aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-01-30 00:05:11 +0000
committerJohn Ankarström <john@ankarstrom.se>2021-01-30 00:05:11 +0000
commit113e584e4a7d1ccb3f3c9a822a36e883251cfe0a (patch)
tree6d69a5fbf3e4507a1319206ff392a2e42d226650
parent8ee58ef236089524d08f9f71c713bd3450854ffd (diff)
downloadem-113e584e4a7d1ccb3f3c9a822a36e883251cfe0a.tar.gz
Re-arrange source code
-rwxr-xr-xaux/emparse204
1 files changed, 102 insertions, 102 deletions
diff --git a/aux/emparse b/aux/emparse
index e59487d..edafcae 100755
--- a/aux/emparse
+++ b/aux/emparse
@@ -2,16 +2,100 @@
# aux/emparse -- parse em source
-function escape(s) {
- if (s == "") {
- gsub("&", "\\&amp;")
- gsub("<", "\\&lt;")
- gsub(">", "\\&gt;")
- } else {
- gsub("&", "\\&amp;", s)
- gsub("<", "\\&lt;", s)
- gsub(">", "\\&gt;", s)
+BEGIN {
+ expectblock = 1
+ itemlevel = 1
+ linktext = ENVIRON["linktext"]
+ if (!linktext) linktext = "link"
+}
+END { breakblock() }
+
+/^$/ { breakblock(); getline }
+expectblock && /^ / { newblock("table") }
+expectblock && /^ - / { newblock("ul") }
+expectblock && /^ [0-9a-z]+\. / { newblock("ol") }
+expectblock && /^ \[[0-9a-z]\]+ / { newblock("nl") }
+expectblock && /^ .*: / { newblock("dl") }
+expectblock && /^ / { newblock("pre") }
+expectblock && /^---$/ { expectblock = 0; printf "<hr/>\n"; next }
+expectblock && /^= .* =$/ { heading(1, $0); next }
+expectblock && /^== .* ==$/ { heading(2, $0); next }
+expectblock && /^=== .* ===$/ { heading(3, $0); next }
+expectblock && /^==== .* ====$/ { heading(4, $0); next }
+expectblock && /^===== .* =====$/ { heading(5, $0); next }
+expectblock && /^====== .* ======$/ { heading(6, $0); next }
+expectblock { newblock("p") }
+
+openblock == "pre" { sub("^ ", ""); escape(); 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) }
+
+{ format($0) } # inline formatting
+
+function format(line) {
+ escape(line)
+ n = split(line, w, "[ ]")
+ for (i = 0; i <= n; i++) {
+ if (w[i] == "") continue;
+
+ if (match(w[i], "^\\[[0-9a-z]+\\]$"))
+ w[i] = ref(substr(w[i], 2, RLENGTH-2))
+ else if (match(w[i], "^\\[[0-9a-z]+\\][.,:;?!)]$"))
+ w[i] = ref(substr(w[i], 2, RLENGTH-3)) substr(w[i], RLENGTH)
+ 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)
+
+ printf "%s", w[i]
+ if (i < n) printf " "
}
+ printf "\n"
}
function beginblock(name) {
@@ -95,98 +179,14 @@ function ref(v) {
return "[<a href=\"#ref" v "\">" v "</a>]"
}
-function format(line) {
- escape(line)
- n = split(line, w, "[ ]")
- for (i = 0; i <= n; i++) {
- if (w[i] == "") continue;
-
- if (match(w[i], "^\\[[0-9a-z]+\\]$"))
- w[i] = ref(substr(w[i], 2, RLENGTH-2))
- else if (match(w[i], "^\\[[0-9a-z]+\\][.,:;?!)]$"))
- w[i] = ref(substr(w[i], 2, RLENGTH-3)) substr(w[i], RLENGTH)
- 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)
-
- printf "%s", w[i]
- if (i < n) printf " "
+function escape(s) {
+ if (s == "") {
+ gsub("&", "\\&amp;")
+ gsub("<", "\\&lt;")
+ gsub(">", "\\&gt;")
+ } else {
+ gsub("&", "\\&amp;", s)
+ gsub("<", "\\&lt;", s)
+ gsub(">", "\\&gt;", s)
}
- printf "\n"
-}
-
-BEGIN {
- expectblock = 1
- itemlevel = 1
- linktext = ENVIRON["linktext"]
- if (!linktext) linktext = "link"
}
-END { breakblock() }
-
-/^$/ { breakblock(); getline }
-expectblock && /^ / { newblock("table") }
-expectblock && /^ - / { newblock("ul") }
-expectblock && /^ [0-9a-z]+\. / { newblock("ol") }
-expectblock && /^ \[[0-9a-z]\]+ / { newblock("nl") }
-expectblock && /^ .*: / { newblock("dl") }
-expectblock && /^ / { newblock("pre") }
-expectblock && /^---$/ { expectblock = 0; printf "<hr/>\n"; next }
-expectblock && /^= .* =$/ { heading(1, $0); next }
-expectblock && /^== .* ==$/ { heading(2, $0); next }
-expectblock && /^=== .* ===$/ { heading(3, $0); next }
-expectblock && /^==== .* ====$/ { heading(4, $0); next }
-expectblock && /^===== .* =====$/ { heading(5, $0); next }
-expectblock && /^====== .* ======$/ { heading(6, $0); next }
-expectblock { newblock("p") }
-
-openblock == "pre" { sub("^ ", ""); escape(); 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) }
-
-{ format($0) }