aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-01-29 23:58:05 +0000
committerJohn Ankarström <john@ankarstrom.se>2021-01-29 23:58:05 +0000
commit1eaa4590ceee74ca82162cfbcd7f417d35dacd35 (patch)
tree46fb4c2d2c30654d15192e378135a9b5e2178f75
parenta9b6311209593b5a5955048e124fc45a9d4a108e (diff)
downloadem-1eaa4590ceee74ca82162cfbcd7f417d35dacd35.tar.gz
Add support for mixed nested lists
That is, <ul> within <ol> or vice versa.
-rwxr-xr-xaux/emparse29
-rw-r--r--mkfile3
-rw-r--r--test.em11
-rw-r--r--test.html14
4 files changed, 34 insertions, 23 deletions
diff --git a/aux/emparse b/aux/emparse
index 73fdd5c..e59487d 100755
--- a/aux/emparse
+++ b/aux/emparse
@@ -15,7 +15,7 @@ function escape(s) {
}
function beginblock(name) {
- if (name == "nl") printf "<ol>\n"
+ if (name == "nl") printf "<ol class=\"reflist\" style=\"font-size: small;\">\n"
else printf "<%s>\n", name
}
@@ -57,8 +57,8 @@ function heading(level, line) {
function item(level, type, line) {
if (openitem) printf "</li>"
openitem = 1
- if (level > itemlevel) printf "<ul>\n"
- if (level < itemlevel) printf "</ul>\n"
+ if (level > itemlevel) printf "<%s>\n", type
+ if (level < itemlevel) printf "</%s>\n", type
itemlevel = level
if (type == "ul") {
sub("^ +- ", "")
@@ -92,8 +92,7 @@ function term(line, t) { # t is a local variable
function ref(v) {
if (ENVIRON["ref" v] != "")
return "(<a href=\"" ENVIRON["ref" v] "\">" linktext "</a>)"
- else
- return "[<a href=\"#ref" v "\">" v "</a>]"
+ return "[<a href=\"#ref" v "\">" v "</a>]"
}
function format(line) {
@@ -179,15 +178,15 @@ openblock == "nl" && /^ \[[0-9a-z]\]+ [^ ]+$/ { next } # hyperlink reference
openblock == "nl" && /^ \[[0-9a-z]\]+ / { item(1, "nl", line) } # text reference
openblock == "dl" && /^ .*: / { term(line) }
-openblock == "ul" && /^ -/ { item(2, "ul", line) }
-openblock == "ol" && /^ [0-9a-z]+\./ { item(2, "ol", line) }
-openblock == "ul" && /^ -/ { item(3, "ul", line) }
-openblock == "ol" && /^ [0-9a-z]+\./ { item(3, "ol", line) }
-openblock == "ul" && /^ -/ { item(4, "ul", line) }
-openblock == "ol" && /^ [0-9a-z]+\./ { item(4, "ol", line) }
-openblock == "ul" && /^ -/ { item(5, "ul", line) }
-openblock == "ol" && /^ [0-9a-z]+\./ { item(5, "ol", line) }
-openblock == "ul" && /^ -/ { item(6, "ul", line) }
-openblock == "ol" && /^ [0-9a-z]+\./ { item(6, "ol", line) }
+(openblock == "ul" || openblock == "ol") && /^ -/ { item(2, "ul", line) }
+(openblock == "ul" || openblock == "ol") && /^ [0-9a-z]+\./ { item(2, "ol", line) }
+(openblock == "ul" || openblock == "ol") && /^ -/ { item(3, "ul", line) }
+(openblock == "ul" || openblock == "ol") && /^ [0-9a-z]+\./ { item(3, "ol", line) }
+(openblock == "ul" || openblock == "ol") && /^ -/ { item(4, "ul", line) }
+(openblock == "ul" || openblock == "ol") && /^ [0-9a-z]+\./ { item(4, "ol", line) }
+(openblock == "ul" || openblock == "ol") && /^ -/ { item(5, "ul", line) }
+(openblock == "ul" || openblock == "ol") && /^ [0-9a-z]+\./ { item(5, "ol", line) }
+(openblock == "ul" || openblock == "ol") && /^ -/ { item(6, "ul", line) }
+(openblock == "ul" || openblock == "ol") && /^ [0-9a-z]+\./ { item(6, "ol", line) }
{ format($0) }
diff --git a/mkfile b/mkfile
index 2c475dd..53f73ae 100644
--- a/mkfile
+++ b/mkfile
@@ -1,2 +1,5 @@
test:
em test.em > test.html
+
+README.html: README
+ em README > README.html
diff --git a/test.em b/test.em
index 2abf836..79569a6 100644
--- a/test.em
+++ b/test.em
@@ -1,6 +1,6 @@
= Em example =
-This is an example of *Em* [1].
+This is an example of *em* [a].
- Here is an
unordered list item.
@@ -11,10 +11,13 @@ ordered list item.
2. Here is another.
- Here is a list
- - With another list inside it [a]
+ - With another list inside it [1]
- [1] http://example.com
- [a] Reference list item
+ 1. Here is a mixed nested list
+ - An unordered item
+
+ [1] Reference list item
+ [a] http://example.com
term: definition
long term: long
diff --git a/test.html b/test.html
index 212c830..af80b0b 100644
--- a/test.html
+++ b/test.html
@@ -1,6 +1,6 @@
<h1>Em example</h1>
<p>
-This is an example of <i>Em</i> (<a href="http://example.com">link</a>).
+This is an example of <i>em</i> (<a href="http://example.com">link</a>).
</p>
<ul>
<li>Here is an
@@ -17,13 +17,19 @@ ordered list item.
<ul>
<li>Here is a list
</li><ul>
-<li>With another list inside it [<a href="#refa">a</a>]
+<li>With another list inside it [<a href="#ref1">1</a>]
</li>
</ul>
</ul>
<ol>
-<li value="1" id="ref1">http://example.com
-</li><li value="a" id="refa">Reference list item
+<li value="1">Here is a mixed nested list
+</li><ul>
+<li>An unordered item
+</li>
+</ol>
+</ol>
+<ol class="reflist" style="font-size: small;">
+<li value="1" id="ref1">Reference list item
</li>
</ol>
<dl>