diff options
author | John Ankarström <john@ankarstrom.se> | 2021-01-31 00:32:45 +0000 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-01-31 00:32:45 +0000 |
commit | 2f7147aa05cbdcb8b1b2470877dffc663cb7a83e (patch) | |
tree | c85a09936d3d044e4a10e341e4cff8c5d83877c3 /emparse | |
parent | 2c2367d45ca8bd24398543ddf338568aefc40cf1 (diff) | |
download | em-2f7147aa05cbdcb8b1b2470877dffc663cb7a83e.tar.gz |
Add blockquote syntax
Diffstat (limited to 'emparse')
-rwxr-xr-x | emparse | 33 |
1 files changed, 21 insertions, 12 deletions
@@ -7,6 +7,7 @@ END { breakblock() } /^$/ { breakblock(); getline } expectblock && /^ / { newblock("table") } +expectblock && /^ > / { newblock("blockquote") } expectblock && /^ - / { newblock("ul") } expectblock && /^ [0-9]+\. / { newblock("ol") } expectblock && /^ \[[0-9]+\] / { newblock("nl") } @@ -23,9 +24,9 @@ expectblock { newblock("p") } openblock == "pre" { sub("^ ", ""); $0 = escape($0); printf "%s\n", $0; next } +openblock == "blockquote" && /^ > / { item(1, "blockquote", line) } openblock == "ul" && /^ - / { item(1, "ul", line) } openblock == "ol" && /^ [0-9]+\. / { item(1, "ol", line) } -#openblock == "nl" && /^ \[[0-9]+\] [^ ]+$/ { next } # hyperlink reference openblock == "nl" && /^ \[[0-9]+\] / { item(1, "nl", line) } # text reference openblock == "dl" && /^ .*: / { term(line) } @@ -135,7 +136,10 @@ function breakblock() { printf "(%s:%d) warning: open <%s> closed at block break\n", ARGV[1], NR, openformat > "/dev/stderr" } if (openitem) { - printf "</li>\n" + if (openblock == "blockquote") + printf "</p>\n" + else + printf "</li>\n" while (itemlevel-- > 1) closetag(openblock) itemlevel = 1 @@ -160,17 +164,22 @@ function heading(level, line) { } function item(level, type, line) { + if (type == "blockquote") { + if (openitem) printf "</p>" + openitem = 1 + sub("^ > ", "") + printf "<p>" + return + } if (openitem) printf "</li>" openitem = 1 - if (type != "nl") { - for (; itemlevel < level; itemlevel++) { - printf "<%s>\n", type - leveltype[itemlevel+1] = type - } - for (; itemlevel > level; itemlevel--) { - printf "</%s>\n", leveltype[itemlevel] - leveltype[itemlevel] = "" - } + for (; itemlevel < level; itemlevel++) { + printf "<%s>\n", type + leveltype[itemlevel+1] = type + } + for (; itemlevel > level; itemlevel--) { + printf "</%s>\n", leveltype[itemlevel] + leveltype[itemlevel] = "" } if (type == "ul") { sub("^ +- ", "") @@ -185,7 +194,7 @@ function item(level, type, line) { if (type == "nl") { match($0, "\\[[0-9]+\\]") v = substr($0, RSTART+1, RLENGTH-2) - sub("^ +\\[[0-9]+\\] ", "") + sub("^ \\[[0-9]+\\] ", "") printf "<li value=\"%s\" id=\"ref%s\">", v, v } } |