aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-01-30 09:24:26 +0000
committerJohn Ankarström <john@ankarstrom.se>2021-01-30 09:24:26 +0000
commit99ac4e7f5a389898673348449e4a522a86d07f1c (patch)
treec42dd9f200cc9e531c2988f76e120b7df2f2e4fd
parent70d8e48567cfe07d992a625241ff02606f699a5e (diff)
downloadem-99ac4e7f5a389898673348449e4a522a86d07f1c.tar.gz
Keep track of open inline format, auto-close at block break
-rwxr-xr-xaux/emparse91
-rw-r--r--test.em6
-rw-r--r--test.html9
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] = "<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
}
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 @@
<p>
This is an example of <i>em</i> (<a href="http://example.com">link</a>).
</p>
+<p>
+Here is some <tt>teletype text</tt>, some <b>bold text</b>.
+</p>
+<p>
+Here is an asterisk at the end of a word*.
+</p>
+<p>
+Here is an <i>unfinished inline formatting tag.
+</i></p>
<ul>
<li>Here is an
unordered list item.