diff options
author | John Ankarström <john@ankarstrom.se> | 2021-01-30 09:24:26 +0000 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-01-30 09:24:26 +0000 |
commit | 99ac4e7f5a389898673348449e4a522a86d07f1c (patch) | |
tree | c42dd9f200cc9e531c2988f76e120b7df2f2e4fd /aux/emparse | |
parent | 70d8e48567cfe07d992a625241ff02606f699a5e (diff) | |
download | em-99ac4e7f5a389898673348449e4a522a86d07f1c.tar.gz |
Keep track of open inline format, auto-close at block break
Diffstat (limited to 'aux/emparse')
-rwxr-xr-x | aux/emparse | 91 |
1 files changed, 54 insertions, 37 deletions
diff --git a/aux/emparse b/aux/emparse index edafcae..929c1c7 100755 --- a/aux/emparse +++ b/aux/emparse @@ -60,37 +60,50 @@ function format(line) { else if (match(w[i], "^\\[[0-9a-z]+\\]\\)[.,:;?!]$")) w[i] = ref(substr(w[i], 2, RLENGTH-4)) substr(w[i], RLENGTH-1) - if (match(w[i], "^`")) - w[i] = "<tt>" substr(w[i], 2) - else if (match(w[i], "^\\*")) - w[i] = "<i>" substr(w[i], 2) - else if (match(w[i], "^_")) - w[i] = "<b>" substr(w[i], 2) - else if (match(w[i], "^\\(`")) - w[i] = "(<tt>" substr(w[i], 3) - else if (match(w[i], "^\\(\\*")) - w[i] = "(<i>" substr(w[i], 3) - else if (match(w[i], "^\\(_")) - w[i] = "(<b>" substr(w[i], 3) - - if (match(w[i], "`$")) - w[i] = substr(w[i], 1, RSTART-1) "</tt>" - else if (match(w[i], "\\*$")) - w[i] = substr(w[i], 1, RSTART-1) "</i>" - else if (match(w[i], "_$")) - w[i] = substr(w[i], 1, RSTART-1) "</b>" - else if (match(w[i], "`[.,:;?!)]$")) - w[i] = substr(w[i], 1, RSTART-1) "</tt>" substr(w[i], RSTART+1) - else if (match(w[i], "\\*[.,:;?!)]$")) - w[i] = substr(w[i], 1, RSTART-1) "</i>" substr(w[i], RSTART+1) - else if (match(w[i], "_[.,:;?!)]$")) - w[i] = substr(w[i], 1, RSTART-1) "</b>" substr(w[i], RSTART+1) - else if (match(w[i], "`\\)[.,:;?!]$")) - w[i] = substr(w[i], 1, RSTART-1) "</tt>" substr(w[i], RSTART+1) - else if (match(w[i], "\\*\\)[.,:;?!]$")) - w[i] = substr(w[i], 1, RSTART-1) "</i>" substr(w[i], RSTART+1) - else if (match(w[i], "_\\)[.,:;?!]$")) - w[i] = substr(w[i], 1, RSTART-1) "</b>" substr(w[i], RSTART+1) + if (!openformat) { + if (match(w[i], "^`")) { + w[i] = "<tt>" substr(w[i], 2) + openformat = "tt" + } else if (match(w[i], "^\\*")) { + w[i] = "<i>" substr(w[i], 2) + openformat = "i" + } else if (match(w[i], "^_")) { + w[i] = "<b>" substr(w[i], 2) + openformat = "b" + } else if (match(w[i], "^\\(`")) { + w[i] = "(<tt>" substr(w[i], 3) + openformat = "tt" + } else if (match(w[i], "^\\(\\*")) { + w[i] = "(<i>" substr(w[i], 3) + openformat = "i" + } else if (match(w[i], "^\\(_")) { + w[i] = "(<b>" substr(w[i], 3) + openformat = "b" + } + } + + if (openformat) { + orig = w[i] + if (match(w[i], "`$")) + w[i] = substr(w[i], 1, RSTART-1) "</tt>" + else if (match(w[i], "\\*$")) + w[i] = substr(w[i], 1, RSTART-1) "</i>" + else if (match(w[i], "_$")) + w[i] = substr(w[i], 1, RSTART-1) "</b>" + else if (match(w[i], "`[.,:;?!)]$")) + w[i] = substr(w[i], 1, RSTART-1) "</tt>" substr(w[i], RSTART+1) + else if (match(w[i], "\\*[.,:;?!)]$")) + w[i] = substr(w[i], 1, RSTART-1) "</i>" substr(w[i], RSTART+1) + else if (match(w[i], "_[.,:;?!)]$")) + w[i] = substr(w[i], 1, RSTART-1) "</b>" substr(w[i], RSTART+1) + else if (match(w[i], "`\\)[.,:;?!]$")) + w[i] = substr(w[i], 1, RSTART-1) "</tt>" substr(w[i], RSTART+1) + else if (match(w[i], "\\*\\)[.,:;?!]$")) + w[i] = substr(w[i], 1, RSTART-1) "</i>" substr(w[i], RSTART+1) + else if (match(w[i], "_\\)[.,:;?!]$")) + w[i] = substr(w[i], 1, RSTART-1) "</b>" substr(w[i], RSTART+1) + if (w[i] != orig) openformat = "" + } printf "%s", w[i] if (i < n) printf " " @@ -98,35 +111,39 @@ function format(line) { printf "\n" } -function beginblock(name) { +function opentag(name) { if (name == "nl") printf "<ol class=\"reflist\" style=\"font-size: small;\">\n" else printf "<%s>\n", name } -function endblock(name) { +function closetag(name) { if (name == "nl") printf "</ol>\n" else printf "</%s>\n", name } function newblock(name) { - beginblock(name) + opentag(name) openblock = name - openitem = 0 expectblock = 0 } function breakblock() { + if (openformat) { + printf "</%s>", openformat + printf "(%s:%d) warning: open <%s> closed at block break\n", ARGV[1], NR, openformat > "/dev/stderr" + } if (openitem) { printf "</li>\n" while (itemlevel-- > 1) - endblock(openblock) + closetag(openblock) itemlevel = 1 } if (opendef) printf "</dd>\n" - if (openblock) endblock(openblock) + if (openblock) closetag(openblock) openitem = 0 opendef = 0 openblock = 0 + openformat = "" expectblock = 1 } |