From 99ac4e7f5a389898673348449e4a522a86d07f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sat, 30 Jan 2021 09:24:26 +0000 Subject: Keep track of open inline format, auto-close at block break --- aux/emparse | 91 ++++++++++++++++++++++++++++++++++++------------------------- test.em | 6 ++++ test.html | 9 ++++++ 3 files changed, 69 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] = "" substr(w[i], 2) - else if (match(w[i], "^\\*")) - w[i] = "" substr(w[i], 2) - else if (match(w[i], "^_")) - w[i] = "" substr(w[i], 2) - else if (match(w[i], "^\\(`")) - w[i] = "(" substr(w[i], 3) - else if (match(w[i], "^\\(\\*")) - w[i] = "(" substr(w[i], 3) - else if (match(w[i], "^\\(_")) - w[i] = "(" substr(w[i], 3) - - if (match(w[i], "`$")) - w[i] = substr(w[i], 1, RSTART-1) "" - else if (match(w[i], "\\*$")) - w[i] = substr(w[i], 1, RSTART-1) "" - else if (match(w[i], "_$")) - w[i] = substr(w[i], 1, RSTART-1) "" - else if (match(w[i], "`[.,:;?!)]$")) - w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) - else if (match(w[i], "\\*[.,:;?!)]$")) - w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) - else if (match(w[i], "_[.,:;?!)]$")) - w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) - else if (match(w[i], "`\\)[.,:;?!]$")) - w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) - else if (match(w[i], "\\*\\)[.,:;?!]$")) - w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) - else if (match(w[i], "_\\)[.,:;?!]$")) - w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) + if (!openformat) { + if (match(w[i], "^`")) { + w[i] = "" substr(w[i], 2) + openformat = "tt" + } else if (match(w[i], "^\\*")) { + w[i] = "" substr(w[i], 2) + openformat = "i" + } else if (match(w[i], "^_")) { + w[i] = "" substr(w[i], 2) + openformat = "b" + } else if (match(w[i], "^\\(`")) { + w[i] = "(" substr(w[i], 3) + openformat = "tt" + } else if (match(w[i], "^\\(\\*")) { + w[i] = "(" substr(w[i], 3) + openformat = "i" + } else if (match(w[i], "^\\(_")) { + w[i] = "(" substr(w[i], 3) + openformat = "b" + } + } + + if (openformat) { + orig = w[i] + if (match(w[i], "`$")) + w[i] = substr(w[i], 1, RSTART-1) "" + else if (match(w[i], "\\*$")) + w[i] = substr(w[i], 1, RSTART-1) "" + else if (match(w[i], "_$")) + w[i] = substr(w[i], 1, RSTART-1) "" + else if (match(w[i], "`[.,:;?!)]$")) + w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) + else if (match(w[i], "\\*[.,:;?!)]$")) + w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) + else if (match(w[i], "_[.,:;?!)]$")) + w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) + else if (match(w[i], "`\\)[.,:;?!]$")) + w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) + else if (match(w[i], "\\*\\)[.,:;?!]$")) + w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) + else if (match(w[i], "_\\)[.,:;?!]$")) + w[i] = substr(w[i], 1, RSTART-1) "" 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 "
    \n" else printf "<%s>\n", name } -function endblock(name) { +function closetag(name) { if (name == "nl") printf "
\n" else printf "\n", name } function newblock(name) { - beginblock(name) + opentag(name) openblock = name - openitem = 0 expectblock = 0 } function breakblock() { + if (openformat) { + printf "", openformat + printf "(%s:%d) warning: open <%s> closed at block break\n", ARGV[1], NR, openformat > "/dev/stderr" + } if (openitem) { printf "\n" while (itemlevel-- > 1) - endblock(openblock) + closetag(openblock) itemlevel = 1 } if (opendef) printf "\n" - if (openblock) endblock(openblock) + if (openblock) closetag(openblock) openitem = 0 opendef = 0 openblock = 0 + openformat = "" expectblock = 1 } diff --git a/test.em b/test.em index 79569a6..830e4bd 100644 --- a/test.em +++ b/test.em @@ -2,6 +2,12 @@ This is an example of *em* [a]. +Here is some `teletype text`, some _bold text_. + +Here is an asterisk at the end of a word*. + +Here is an *unfinished inline formatting tag. + - Here is an unordered list item. - Here is another. diff --git a/test.html b/test.html index af80b0b..b5bafb5 100644 --- a/test.html +++ b/test.html @@ -2,6 +2,15 @@

This is an example of em (link).

+

+Here is some teletype text, some bold text. +

+

+Here is an asterisk at the end of a word*. +

+

+Here is an unfinished inline formatting tag. +