aboutsummaryrefslogtreecommitdiff
path: root/emparse
diff options
context:
space:
mode:
Diffstat (limited to 'emparse')
-rwxr-xr-xemparse74
1 files changed, 40 insertions, 34 deletions
diff --git a/emparse b/emparse
index 3184488..5ddb585 100755
--- a/emparse
+++ b/emparse
@@ -2,19 +2,14 @@
# aux/emparse -- parse em source
-BEGIN {
- expectblock = 1
- itemlevel = 1
- linktext = ENVIRON["linktext"]
- if (!linktext) linktext = "link"
-}
+BEGIN { expectblock = 1; itemlevel = 1 }
END { breakblock() }
/^$/ { breakblock(); getline }
expectblock && /^ / { newblock("table") }
expectblock && /^ - / { newblock("ul") }
-expectblock && /^ [0-9a-z]+\. / { newblock("ol") }
-expectblock && /^ \[[0-9a-z]+\] / { newblock("nl") }
+expectblock && /^ [0-9]+\. / { newblock("ol") }
+expectblock && /^ \[[0-9]+\] / { newblock("nl") }
expectblock && /^ .*: / { newblock("dl") }
expectblock && /^ / { newblock("pre") }
expectblock && /^---$/ { expectblock = 0; printf "<hr/>\n"; next }
@@ -28,36 +23,43 @@ expectblock { newblock("p") }
openblock == "pre" { sub("^ ", ""); $0 = escape($0); printf "%s\n", $0; next }
-openblock == "ul" && /^ - / { item(1, "ul", line) }
-openblock == "ol" && /^ [0-9a-z]+\. / { item(1, "ol", line) }
-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" || 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) }
+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) }
+
+(openblock == "ul" || openblock == "ol") && /^ -/ { item(2, "ul", line) }
+(openblock == "ul" || openblock == "ol") && /^ [0-9]+\./ { item(2, "ol", line) }
+(openblock == "ul" || openblock == "ol") && /^ -/ { item(3, "ul", line) }
+(openblock == "ul" || openblock == "ol") && /^ [0-9]+\./ { item(3, "ol", line) }
+(openblock == "ul" || openblock == "ol") && /^ -/ { item(4, "ul", line) }
+(openblock == "ul" || openblock == "ol") && /^ [0-9]+\./ { item(4, "ol", line) }
+(openblock == "ul" || openblock == "ol") && /^ -/ { item(5, "ul", line) }
+(openblock == "ul" || openblock == "ol") && /^ [0-9]+\./ { item(5, "ol", line) }
+(openblock == "ul" || openblock == "ol") && /^ -/ { item(6, "ul", line) }
+(openblock == "ul" || openblock == "ol") && /^ [0-9]+\./ { item(6, "ol", line) }
{ format($0) } # inline formatting
function format(line) {
line = escape(line)
- n = split(line, w, "[ ]")
+ n = split(line, w, "[ ]") # TODO: this removes spaces...
for (i = 0; i <= n; i++) {
if (w[i] == "") continue;
- if (match(w[i], "^\\[[0-9a-z]+\\]$"))
+ if (match(w[i], "^&lt;(\\./.*|\\.\\./.*|.*/.*)&gt;$"))
+ w[i] = link(substr(w[i], 5, RLENGTH-8))
+ else if (match(w[i], "^&lt;(\\./.*|\\.\\./.*|.*/.*)&gt;[.,:;?!)]$"))
+ w[i] = link(substr(w[i], 5, RLENGTH-9)) substr(w[i], RLENGTH)
+ else if (match(w[i], "^&lt;(\\./.*|\\.\\./.*|.*/.*)&gt;\\)[.,:;?!]$"))
+ w[i] = link(substr(w[i], 5, RLENGTH-10)) substr(w[i], RLENGTH-1)
+
+ if (match(w[i], "^\\[[0-9]+\\]$"))
w[i] = ref(substr(w[i], 2, RLENGTH-2))
- else if (match(w[i], "^\\[[0-9a-z]+\\][.,:;?!)]$"))
+ else if (match(w[i], "^\\[[0-9]+\\][.,:;?!)]$"))
w[i] = ref(substr(w[i], 2, RLENGTH-3)) substr(w[i], RLENGTH)
- else if (match(w[i], "^\\[[0-9a-z]+\\]\\)[.,:;?!]$"))
+ else if (match(w[i], "^\\[[0-9]+\\]\\)[.,:;?!]$"))
w[i] = ref(substr(w[i], 2, RLENGTH-4)) substr(w[i], RLENGTH-1)
if (!openformat) {
@@ -112,7 +114,7 @@ function format(line) {
}
function opentag(name) {
- if (name == "nl") printf "<ol class=\"reflist\" style=\"font-size: small;\">\n"
+ if (name == "nl") printf "<ol class=\"reflist\">\n"
else printf "<%s>\n", name
}
@@ -175,15 +177,15 @@ function item(level, type, line) {
printf "<li>"
}
if (type == "ol") {
- match($0, "[0-9a-z]+\.")
+ match($0, "[0-9]+\.")
v = substr($0, RSTART, RLENGTH-1)
- sub("^ +[0-9a-z]+\. ", "")
+ sub("^ +[0-9]+\. ", "")
printf "<li value=\"%s\">", v
}
if (type == "nl") {
- match($0, "\\[[0-9a-z]+\\]")
+ match($0, "\\[[0-9]+\\]")
v = substr($0, RSTART+1, RLENGTH-2)
- sub("^ +\\[[0-9a-z]+\\] ", "")
+ sub("^ +\\[[0-9]+\\] ", "")
printf "<li value=\"%s\" id=\"ref%s\">", v, v
}
}
@@ -201,10 +203,14 @@ function term(line, t) { # t is a local variable
function ref(v) {
if (ENVIRON["ref" v] != "")
- return "(<a href=\"" ENVIRON["ref" v] "\">" linktext "</a>)"
+ return "[<a href=\"" ENVIRON["ref" v] "\">" v "</a>]"
return "[<a href=\"#ref" v "\">" v "</a>]"
}
+function link(h) {
+ return "<a href=\"" h "\">" h "</a>"
+}
+
function escape(s) {
gsub("&", "\\&amp;", s)
gsub("<", "\\&lt;", s)