# Meant to support all features of John Grubers basic Markdown
# + a number of common extensions, mostly inspired by Pandoc Markdown
-# Copyright 2021 - 2023 Paul Hänsch
+# Copyright 2021 - 2024 Paul Hänsch
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
return text;
}
-function URL ( text, sharp ) {
- gsub( /&/, "%26", text );
- gsub( /"/, "%22", text );
- gsub( /'/, "%27", text );
- gsub( /`/, "%60", text );
- gsub( /\?/, "%3F", text );
- if (sharp) gsub( /#/, "%23", text );
- gsub( /\[/, "%5B", text );
- gsub( /\]/, "%5D", text );
- gsub( / /, "%20", text );
- gsub( / /, "%09", text );
- gsub( /\\/, "%5C", text );
- return text;
-}
-
function inline( line, LOCAL, len, text, code, href, guard, ret ) {
ret = "";
while (line !~ /^$/) {
len = RLENGTH; href = text = substr(line, 1, len);
sub(/^\[\[/, "", href); sub(/(\|([^]]+))?\]\].*$/, "", href);
sub(/^\[\[([^]|]+)/, "", text); sub(/\]\].*$/, "", text); sub(/^\|/, "", text);
- # sub(/^\[\[([^]|]+)(\|([^]]+))?\]\]/, "\\1", href );
- # sub(/^\[\[([^]|]+)(\|([^]]+))?\]\]/, "\\3", text );
if ( ! text ) text = href;
ret = ret "<a href=\"" HTML(href) "\">" HTML(text) "</a>"; line = substr( line, len + 1);
continue;
continue;
# quick link email
- # } else if ( match( line, /^<[a-zA-Z0-9.!#$%&'\''*+\/=?^_`{|}~-]+@[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*>/ ) ) {
} else if ( match( line, /^<[a-zA-Z0-9.!#$%&'\''*+\/=?^_`{|}~-]+@([a-zA-Z0-9]\.[a-zA-Z0-9]|[a-zA-Z0-9-])+>/ ) ) {
len = RLENGTH;
href = HTML( substr( line, 2, len - 2) );
len = RLENGTH; text = id = substr(line, 1, len);
sub(/\n.*$/, "", text); sub(/^\[/, "", text); sub(/\] ?\[([^\n]*)\].*$/, "", text);
sub(/\n.*$/, "", id); sub(/^\[([^]]+)\] ?\[/, "", id); sub(/\].*$/, "", id);
- # text = gensub(/^\[([^\n]+)\] ?\[([^\n]*)\].*/, "\\1", 1, text );
- # id = gensub(/^\[([^\n]+)\] ?\[([^\n]*)\].*/, "\\2", 1, id );
if ( ! id ) id = text;
if ( rl_href[id] && rl_title[id] ) {
}
# inline images
- } else if ( match(line, "^!" lix "\\([\n\t ]*" lid "([\n\t ]+" lit ")?[\n\t ]*\\)(\\{[a-zA-Z \t-]*\\})?") ) {
+ } else if ( match(line, "^!" lix "\\([\n\t ]*" lid "([\n\t ]+" lit ")?[\n\t ]*\\)("rattr")?") ) {
len = RLENGTH; text = href = title = attrib = substr( line, 1, len);
sub("^!\\[", "", text);
- sub("\\]\\([\n\t ]*" lid "([\n\t ]+" lit ")?[\n\t ]*\\)(\\{[a-zA-Z \t-]*\\})?$", "", text);
+ sub("\\]\\([\n\t ]*" lid "([\n\t ]+" lit ")?[\n\t ]*\\)("rattr")?$", "", text);
sub("^!" lix "\\([\n\t ]*", "", href);
- sub("([\n\t ]+" lit ")?[\n\t ]*\\)(\\{[a-zA-Z \t-]*\\})?$", "", href);
+ sub("([\n\t ]+" lit ")?[\n\t ]*\\)("rattr")?$", "", href);
sub("^!" lix "\\([\n\t ]*" lid, "", title);
- sub("[\n\t ]*\\)(\\{[a-zA-Z \t-]*\\})?$", "", title);
+ sub("[\n\t ]*\\)("rattr")?$", "", title);
sub("^[\n\t ]+", "", title);
- sub("^!" lix "\\([\n\t ]*" lid "([\n\t ]+" lit ")?[\n\t ]*\\)", "", attrib);
- sub(/^\{[ \t]*/, "", attrib); sub(/[ \t]*\}$/, "", attrib); gsub(/[ \t]+/, " ", attrib);
+ attrib = _attr(attrib);
if ( match(href, /^<.*>$/) ) { sub(/^</, "", href); sub(/>$/, "", href); }
if ( match(title, /^".*"$/) ) { sub(/^"/, "", title); sub(/"$/, "", title); }
len = RLENGTH; text = id = substr(line, 1, len);
sub(/\n.*$/, "", text); sub(/^!\[/, "", text); sub(/\] ?\[([^\n]*)\].*$/, "", text);
sub(/\n.*$/, "", id); sub(/^!\[([^]]+)\] ?\[/, "", id); sub(/\].*$/, "", id);
- # text = gensub(/^!\[([^\n]*)\] ?\[([^\n]*)\].*/, "\\1", 1, substr(line, 1, len) );
- # id = gensub(/^!\[([^\n]*)\] ?\[([^\n]*)\].*/, "\\2", 1, substr(line, 1, len) );
if ( ! id ) id = text;
if ( rl_href[id] && rl_title[id] ) {
ret = ret "<img src=\"" HTML(rl_href[id]) "\" alt=\"" HTML(text) "\" title=\"" HTML(rl_title[id]) "\">";
continue;
# Literal HTML entities
- # } else if ( match( line, /^&([a-zA-Z]{2,32}|#[0-9]{1,7}|#[xX][0-9a-fA-F]{1,6});/) ) {
- # mawk does not support repitition ranges
+ # mawk does not support repitition ranges (i.e. "xyz{1,10}")
} else if ( match( line, /^&[a-zA-Z][a-zA-Z][a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?;/) ) {
len = RLENGTH;
ret = ret substr( line, 1, len ); line = substr(line, len + 1);
} else if ( line ~ /^-->( |$)/) { # ignore multidash-arrow
ret = ret "-->"; line = substr(line, 4);
continue;
+ } else if ( line ~ /^<->( |$)/) {
+ ret = ret "↔"; line = substr(line, 4);
+ continue;
} else if ( line ~ /^<-( |$)/) {
ret = ret "←"; line = substr(line, 3);
continue;
return ret;
}
-function headline( hlvl, htxt, attrib, LOCAL, sec, n, HL) {
- # match(hstack, /([0-9]+( [0-9]+){5})$/); split( substr(hstack, RSTART), HL);
+function headline( hlvl, htxt, attrib, LOCAL, sec, n, hid, HL) {
match(hstack, /([0-9]+( [0-9]+)( [0-9]+)( [0-9]+)( [0-9]+)( [0-9]+))$/); split( substr(hstack, RSTART), HL);
for ( n = hlvl; n <= 6; n++ ) { sec = sec (HL[n]?"</section>":""); }
hid = ""; for ( n = 2; n <= blvl; n++) { hid = hid BL[n] "/"; }
hid = hid HL[1]; for ( n = 2; n <= hlvl; n++) { hid = hid "." HL[n] ; }
- hid = hid ":" URL(htxt, 1);
+ hid = hid ":" HTML(htxt); # anchor for TOC and permalink
- # sub(/([0-9]+( [0-9]+){5})$/, "", hstack);
sub(/([0-9]+( [0-9]+)( [0-9]+)( [0-9]+)( [0-9]+)( [0-9]+))$/, "", hstack);
hstack = hstack HL[1] " " HL[2] " " HL[3] " " HL[4] " " HL[5] " " HL[6];
return sec "<section class=\"" (attrib ? "h" hlvl " " attrib : "h" hlvl) "\" id=\"" hid "\">" \
"<h" hlvl (attrib ? " class=\"" attrib "\"" : "") ">" inline( htxt ) \
- "<a class=\"anchor\" href=\"#" hid "\"></a>" \
+ "<a class=\"anchor\" href=\"#" hid "\" aria-label=\"#" hid "\"></a>" \
"</h" hlvl ">\n";
}
# Column Count
tmp = block; sub( "(\n.*)*$", "", tmp);
cols = split( tmp, tread, /\+/) - 2;
- # debug(" Cols: " gensub( "^(\\+(:?-+:?\\+)+)(\n.*)*$", "\\1", 1, block ));
# table alignment
match(block, "((:?=+:?\\+|(:-+|-+:|:-+:)\\+)+)");
split( substr(block, RSTART, RLENGTH) , talign, /\+/ );
- # split( gensub( "^(.*\n)?\\+((:?=+:?\\+|(:-+|-+:|:-+:)\\+)+)(\n.*)$", "\\2", "g", block ), talign, /\+/ );
- # debug("Align: " gensub( "^(.*\n)?\\+((:?=+:?\\+|(:-+|-+:|:-+:)\\+)+)(\n.*)$", "\\2", "g", block ));
for (cnt = 1; cnt <= cols; cnt++) {
if (match(talign[cnt], /:(-+|=+):/)) talign[cnt]="center";
guard = substr( block, 1, RLENGTH ); attrib = code = block;
sub(/^[^\n]+\n/, "", code);
sub(/^:::+[ \t]*\{?[ \t]*/, "", attrib); sub(/\}?[ \t]*\n.*$/, "", attrib);
- # attrib = gensub(/^:::+[ \t]*\{?[ \t]*([^\}\n]*)\}?[ \t]*\n.*$/, "\\1", 1, attrib);
gsub(/[^a-zA-Z0-9_-]+/, " ", attrib);
gsub(/(^ | $)/, "", attrib);
if ( match(code, "(^|\n)" guard "+(\n|$)" ) && attrib ) {
guard = substr( block, 1, RLENGTH ); attrib = code = block;
sub(/^[^\n]+\n/, "", code);
sub(/^(~~~+|```+)[ \t]*\{?[ \t]*/, "", attrib); sub(/\}?[ \t]*\n.*$/, "", attrib);
- # attrib = gensub(/^(~~~+|```+)[ \t]*\{?[ \t]*([^\}\n]*)\}?[ \t]*\n.*$/, "\\2", 1, attrib);
gsub(/[^a-zA-Z0-9_-]+/, " ", attrib);
gsub(/(^ | $)/, "", attrib);
if ( match(code, "(^|\n)" guard "+(\n|$)" ) && attrib ) {
len = RLENGTH; st = RSTART;
- ret = ret "<pre><code class=\"" attrib "\">" HTML( substr(code, 1, st - 1) ) "</code></pre>\n";
+ ret = ret "<pre class=\"" attrib "\"><code class=\"" attrib "\">" \
+ HTML( substr(code, 1, st - 1) ) "</code></pre>\n";
block = substr( code, st + len );
continue;
}
# First Order Heading H1 + Attrib
- } else if ( match( block, /^([^\n]+)([ \t]*\{([^\}\n]+)\})\n===+(\n|$)/ ) ) {
+ } else if ( match( block, "^([^\n]+)([ \t]*"rattr")\n===+(\n|$)" ) ) {
len = RLENGTH; text = attrib = block;
sub(/([ \t]*\{([^\}\n]+)\})\n===+(\n.*)?$/, "", text);
- sub(/\}\n===+(\n.*)?$/, "", attrib); sub(/^([^\n]+)[ \t]*\{/, "", attrib);
- gsub(/[^a-zA-Z0-9_-]+/, " ", attrib); gsub(/(^ | $)/, "", attrib);
+ attrib = _attr(attrib);
ret = ret headline(1, text, attrib) ; block = substr( block, len + 1 );
continue;
continue;
# Second Order Heading H2 + Attrib
- } else if ( match( block, /^([^\n]+)([ \t]*\{([^\}\n]+)\})\n---+(\n|$)/ ) ) {
+ } else if ( match( block, "^([^\n]+)([ \t]*"rattr")\n---+(\n|$)" ) ) {
len = RLENGTH; text = attrib = block;
sub(/([ \t]*\{([^\}\n]+)\})\n---+(\n.*)?$/, "", text);
- sub(/\}\n---+(\n.*)?$/, "", attrib); sub(/^([^\n]+)[ \t]*\{/, "", attrib);
- gsub(/[^a-zA-Z0-9_-]+/, " ", attrib); gsub(/(^ | $)/, "", attrib);
+ attrib = _attr(attrib);
ret = ret headline(2, text, attrib) ; block = substr( block, len + 1);
continue;
continue;
# # Nth Order Heading H1 H2 H3 H4 H5 H6 + Attrib
- # } else if ( match( block, /^(##?#?#?#?#?)[ \t]*(([^ \t\n]+|[ \t]+[^ \t\n#]|[ \t]+#+[ \t]*[^ \t\n#])+)[ \t]*#*[ \t]*\{[a-zA-Z \t-]*\}(\n|$)/ ) ) {
- } else if ( match( block, /^##?#?#?#?#?[^#\n]([^\n#]|#[^\t\n# ]|#[\t ]+[^\t\n ])+#*[\t ]*\{[\ta-zA-Z -]*\}(\n|$)/ ) ) {
+ } else if ( match( block, "^##?#?#?#?#?[^#\n]([^\n#]|#[^\t\n# ]|#[\t ]+[^\t\n ])+#*[\t ]*"rattr"(\n|$)" ) ) {
len = RLENGTH; text = attrib = substr(block, 1, len);
match(block, /^##?#?#?#?#?[^#]/); n = RLENGTH - 1;
- # sub(/^(##?#?#?#?#?)[ \t]*/, "", text); # not working in mawk
text = substr(text, n + 1); sub(/^[ \t]*/, "", text);
sub(/[ \t]*#*([ \t]*\{([a-zA-Z \t-]*)\})(\n.*)?$/, "", text);
- sub(/^##?#?#?#?#?[^#\n]([^\n#]|#[^\t\n# ]|#[\t ]+[^\t\n ])+#*[\t ]*\{/, "", attrib);
- sub(/\}(\n.*)?$/, "", attrib);
- gsub(/[^a-zA-Z0-9_-]+/, " ", attrib); gsub(/(^ | $)/, "", attrib);
+ attrib = _attr(attrib);
ret = ret headline( n, text, attrib ); block = substr( block, len + 1);
continue;
# Nth Order Heading H1 H2 H3 H4 H5 H6
- # } else if ( match( block, /^(##?#?#?#?#?)[ \t]*(([^ \t\n]+|[ \t]+[^ \t\n#]|[ \t]+#+[ \t]*[^ \t\n#])+)[ \t]*#*(\n|$)/ ) ) {
} else if ( match( block, /^##?#?#?#?#?[^#\n]([^\n#]|#[^\t\n# ]|#[\t ]+[^\t\n ])+#*(\n|$)/ ) ) {
len = RLENGTH; text = substr(block, 1, len);
match(block, /^##?#?#?#?#?[^#]/); n = RLENGTH - 1;
- # sub(/^(##?#?#?#?#?)[ \t]+/, "", text); # not working in mawk
text = substr(text, n + 1); sub(/^[ \t]*/, "", text);
sub(/[ \t]*#*(\n.*)?$/, "", text);
continue;
# block images (wrapped in <figure>)
- } else if ( match(block, "^!" lix "\\([\n\t ]*" lid "([\n\t ]+" lit ")?[\n\t ]*\\)(\\{[a-zA-Z \t-]*\\})?(\n|$)") ) {
+ } else if ( match(block, "^!" lix "\\([\n\t ]*" lid "([\n\t ]+" lit ")?[\n\t ]*\\)("rattr")?(\n|$)") ) {
len = RLENGTH; text = href = title = attrib = substr( block, 1, len);
sub("^!\\[", "", text);
sub("[\n\t ]*\\)(\\{[a-zA-Z \t-]*\\})?(\n.*)?$", "", title);
sub("^[\n\t ]+", "", title);
- sub("^!" lix "\\([\n\t ]*" lid "([\n\t ]+" lit ")?[\n\t ]*\\)", "", attrib);
- sub("(\n.*)?$", "", attrib);
- sub(/^\{[ \t]*/, "", attrib); sub(/[ \t]*\}$/, "", attrib); gsub(/[ \t]+/, " ", attrib);
+ attrib = _attr(attrib);
if ( match(href, /^<.*>$/) ) { sub(/^</, "", href); sub(/>$/, "", href); }
if ( match(title, /^".*"$/) ) { sub(/^"/, "", title); sub(/"$/, "", title); }
len = RLENGTH; text = id = block;
sub(/(\n.*)?$/, "", text); sub( /^!\[/, "", text); sub(/\] ?\[([^\n]*)\]$/, "", text);
sub(/(\n.*)?$/, "", id); sub( /^!\[([^\n]*)\] ?\[/, "", id); sub(/\]$/, "", id);
- # text = gensub(/^!\[([^\n]*)\] ?\[([^\n]*)\](\n.*)?$/, "\\1", 1, block);
- # id = gensub(/^!\[([^\n]*)\] ?\[([^\n]*)\](\n.*)?$/, "\\2", 1, block);
if ( ! id ) id = text;
if ( rl_href[id] && rl_title[id] ) {
ret = ret "<figure data-src=\"" HTML(rl_href[id]) "\">" \
} else if ( match( block, /^<<(([^>]|>[^>])+)>>(\n|$)/ ) ) {
len = RLENGTH; text = block;
sub(/^<</, "", text); sub(/>>(\n.*)?$/, "", text);
- # text = gensub(/^<<(([^>]|>[^>])+)>>(\n.*)?$/, "\\1", 1, block);
ret = ret "<code class=\"macro\">" HTML(text) "</code>" ; block = substr(block, len + 1);
continue;
continue;
# Horizontal rule
- # } else if ( match( block, /(^|\n) ? ? ?((\* *){3,}|(- *){3,}|(_ *){3,})($|\n)/) ) {
} else if ( match( block, /(^|\n) ? ? ?((\* *)(\* *)(\* *)(\* *)*|(- *)(- *)(- *)(- *)*|(_ *)(_ *)(_ *)(_ *)*)($|\n)/) ) {
len = RLENGTH; st = RSTART;
ret = ret _block(substr(block, 1, st - 1)) "<hr>\n"; block = substr(block, st + len);
st = RSTART; len = RLENGTH; list = substr( block, st, len);
sub("^\n", "", list); match(list, "^( | | )?"); indent = RLENGTH;
- # gsub( "(^|\n) {0," indent "}", "\n", list); sub("^\n", "", list);
# emulate greedy range matcher for mawk
it = "("; while ( indent > 0 ) { for (k = indent; k > 0; k--) { it = it " "; } it = it "|"; indent--; }
sub(/\|$/, ")?", it); sub(/^\($/, "", it);
st = (RLENGTH == -1) ? length(block) + 1 : RSTART;
text = substr(block, 1, st); block = substr(block, st + 1);
- # gsub("\n {0," indent "}", "\n", text);
# emulate greedy range matcher for mawk
it = "("; while ( indent > 0 ) { for (k = indent; k > 0; k--) { it = it " "; } it = it "|"; indent--; }
sub(/\|$/, ")?", it); sub(/^\($/, "", it);
sub( "^([ \t]*\n)*", "", text);
match(text, "^ ? ? ?:(\t| +)"); indent = RLENGTH;
sub( "^ ? ? ?:(\t| +)", "", text);
- # gsub( "(^|\n) {0," indent "}", "\n", text );
# emulate greedy range matcher for mawk
it = "("; while ( indent > 0 ) { for (k = indent; k > 0; k--) { it = it " "; } it = it "|"; indent--; }
sub(/\|$/, ")?", it); sub(/^\($/, "", it);
}
}
+function _attr (attrib) {
+ if ( sub(/.*\{[ \t.#]*/, "", attrib) ) if ( sub(/[ \t]*\}(\n.*)?$/, "", attrib) ) {
+ gsub(/[ \t.#]+/, " ", attrib);
+ return attrib;
+ } else return "";
+}
+
BEGIN {
# Global Vars
file = ""; rl_href[""] = ""; rl_title[""] = "";
if (ENVIRON["MD_HTML"] == "true") { AllowHTML = "true"; }
HL[1] = 0; HL[2] = 0; HL[3] = 0; HL[4] = 0; HL[5] = 0; HL[6] = 0;
- # hls = "0 0 0 0 0 0";
# Universal Patterns
nu = "([^_\\\\]|\\\\.|_[[:alnum:]])" # not underline (except when escaped, or inside a word)
iea = "\\*([^*[:space:]]|[^*[:space:]]" na "*[^*[:space:]])\\*" # inner <em> (asterisk)
isa = "\\*\\*([^*[:space:]]|[^*[:space:]]" na "*[^*[:space:]])\\*\\*" # inner <strong> (asterisk)
+ rattr = "\\{[ \t]*([.#]?([a-zA-Z0-9]+-)*[a-zA-Z0-9]+[ \t]+)*([.#]?([a-zA-Z0-9]+-)*[a-zA-Z0-9]+)[ \t]*\\}"
+
lix="\\[(\\\\[^\n]|[^]\n\\\\[])*\\]" # link text
lid="(<(\\\\[^\n]|[^\n<>\\\\])*>|(\\\\.|[^()\"'\\\\])+|([^<\n\t ()\\\\]|\\\\[^\n])(\\\\[\n]|[^\n\t \\(\\)\\\\])*)" # link dest
lit="(\"(\\\\.|[^\"\\\\])*\"|'(\\\\.|[^'\\\\])*'|\\((\\\\.|[^\\(\\)\\\\])*\\))" # link text
# Fill array of reference links
f = file; rl_id;
re_reflink = "(^|\n) ? ? ?\\[([^]\n]+)\\]: ([^ \t\n]+)(\n?[ \t]+(\"([^\"]+)\"|'([^']+)'|\\(([^)]+)\\)))?(\n|$)";
- # /(^|\n) ? ? ?\[([^]\n]+)\]: ([^ \t\n]+)(\n?[ \t]+("([^"]+)"|'([^']+)'|\(([^)]+)\)))?(\n|$)/
while ( match(f, re_reflink ) ) {
tt = th = ti = substr(f, RSTART, RLENGTH); f = substr(f, RSTART + RLENGTH);
sub("(^|\n) ? ? ?\\[", "", ti); sub("\\]: ([^ \t\n]+)(\n?[ \t]+(\"([^\"]+)\"|'([^']+)'|\\(([^)]+)\\)))?(\n.*)?$", "", ti);
sub("(^|\n) ? ? ?\\[([^]\n]+)\\]: ([^ \t\n]+)", "", tt); sub("^\n?[ \t]+", "", tt); sub("(\n.*)?$", "", tt);
} else { tt = ""; }
rl_id = ti; rl_href[rl_id] = th; rl_title[rl_id] = tt;
- # rl_id = gensub( re_reflink, "\\2", 1, substr(f, RSTART, RLENGTH) );
- # rl_href[rl_id] = gensub( re_reflink, "\\3", 1, substr(f, RSTART, RLENGTH) );
- # rl_title[rl_id] = gensub( re_reflink, "\\5", 1, substr(f, RSTART, RLENGTH) );
- # f = substr(f, RSTART + RLENGTH);
rl_title[rl_id] = substr( rl_title[rl_id], 2, length(rl_title[rl_id]) - 2 );
if ( rl_href[rl_id] ~ /<.*>/ ) rl_href[rl_id] = substr( rl_href[rl_id], 2, length(rl_href[rl_id]) - 2 );
}
# Clear reflinks from File
while( gsub(re_reflink, "\n", file ) );
- # for (n in rl_href) { debug(n " | " rl_href[n] " | " rl_title[n] ); }
# Run Block Processing -> The Actual Markdown!
printf "%s", _nblock( file );
#!/bin/sh
-runtimes="gawk busybox mawk goawk"
+runtimes="${runtimes:-gawk busybox mawk goawk}"
BR='
'
assert ' ' '<p> <img src="Test Bild.jpg" alt="Testbild"></p>' "inline image"
assert ' ' '<p> <img src="Test Bild.jpg" alt="Testbild" title="German Television *test* image ca. 1994"></p>' "inline image"
assert ' {tv ard function-check}' '<p> <img src="Test Bild.jpg" alt="Testbild *ARD*" class="tv ard function-check"></p>' "inline image"
-# assert ' {#tv .ard .function-check}' '<p> <img src="Test Bild.jpg" alt="Testbild *ARD*" class="tv ard check"></p>' "inline image id/classes"
+assert ' {#tv .ard .function-check}' '<p> <img src="Test Bild.jpg" alt="Testbild *ARD*" class="tv ard function-check"></p>' "inline image id/classes"
assert '[](<http://de.wikipedia.org>)'\
'<p><a href="http://de.wikipedia.org"><img src="wikilogo.png" alt="Wikipedia"></a></p>'\
*formatted*
but ­ <escaped>
```' \
-'<pre><code class="tag code">fenced code will
+'<pre class="tag code"><code class="tag code">fenced code will
not be
*formatted*
but &shy; <escaped></code></pre>' \
# Headings
assert 'Heading first Order
============' \
-'<section class="h1" id="1:Heading%20first%20Order"><h1>Heading first Order<a class="anchor" href="#1:Heading%20first%20Order"></a></h1>
+'<section class="h1" id="1:Heading first Order"><h1>Heading first Order<a class="anchor" href="#1:Heading first Order" aria-label="#1:Heading first Order"></a></h1>
</section>' \
'Heading h1'
assert 'Heading first Order {.foo #bar}
============' \
-'<section class="h1 foo bar" id="1:Heading%20first%20Order"><h1 class="foo bar">Heading first Order<a class="anchor" href="#1:Heading%20first%20Order"></a></h1>
+'<section class="h1 foo bar" id="1:Heading first Order"><h1 class="foo bar">Heading first Order<a class="anchor" href="#1:Heading first Order" aria-label="#1:Heading first Order"></a></h1>
</section>' \
'Heading h1 + attributes'
assert 'Heading second Order
------------' \
-'<section class="h2" id="0.1:Heading%20second%20Order"><h2>Heading second Order<a class="anchor" href="#0.1:Heading%20second%20Order"></a></h2>
+'<section class="h2" id="0.1:Heading second Order"><h2>Heading second Order<a class="anchor" href="#0.1:Heading second Order" aria-label="#0.1:Heading second Order"></a></h2>
</section>' \
'Heading h2'
assert 'Heading second Order {.foo #bar}
------------' \
-'<section class="h2 foo bar" id="0.1:Heading%20second%20Order"><h2 class="foo bar">Heading second Order<a class="anchor" href="#0.1:Heading%20second%20Order"></a></h2>
+'<section class="h2 foo bar" id="0.1:Heading second Order"><h2 class="foo bar">Heading second Order<a class="anchor" href="#0.1:Heading second Order" aria-label="#0.1:Heading second Order"></a></h2>
</section>' \
'Heading h2 + attributes'
assert '#### Heading four' \
-'<section class="h4" id="0.0.0.1:Heading%20four"><h4>Heading four<a class="anchor" href="#0.0.0.1:Heading%20four"></a></h4>
+'<section class="h4" id="0.0.0.1:Heading four"><h4>Heading four<a class="anchor" href="#0.0.0.1:Heading four" aria-label="#0.0.0.1:Heading four"></a></h4>
</section>' \
'Heading arbitrary'
assert '###Heading three ######' \
-'<section class="h3" id="0.0.1:Heading%20three"><h3>Heading three<a class="anchor" href="#0.0.1:Heading%20three"></a></h3>
+'<section class="h3" id="0.0.1:Heading three"><h3>Heading three<a class="anchor" href="#0.0.1:Heading three" aria-label="#0.0.1:Heading three"></a></h3>
</section>' \
'Heading arbitrary'
assert '### Heading three ## {foo bar}' \
-'<section class="h3 foo bar" id="0.0.1:Heading%20three"><h3 class="foo bar">Heading three<a class="anchor" href="#0.0.1:Heading%20three"></a></h3>
+'<section class="h3 foo bar" id="0.0.1:Heading three"><h3 class="foo bar">Heading three<a class="anchor" href="#0.0.1:Heading three" aria-label="#0.0.1:Heading three"></a></h3>
</section>' \
'Heading arbitrary + attributes'
assert '# Heading \# # {foo bar}' \
-'<section class="h1 foo bar" id="1:Heading%20%5C%23"><h1 class="foo bar">Heading #<a class="anchor" href="#1:Heading%20%5C%23"></a></h1>
+'<section class="h1 foo bar" id="1:Heading \#"><h1 class="foo bar">Heading #<a class="anchor" href="#1:Heading \#" aria-label="#1:Heading \#"></a></h1>
</section>' \
'Heading arbitrary + attributes'
##sub2 bar {x}
' \
-'<section class="h2" id="0.1:foo"><h2>foo<a class="anchor" href="#0.1:foo"></a></h2>
-</section><section class="h1" id="1:bar"><h1>bar<a class="anchor" href="#1:bar"></a></h1>
-<section class="h2" id="1.1:sub%20bar"><h2>sub bar<a class="anchor" href="#1.1:sub%20bar"></a></h2>
-<section class="h3" id="1.1.1:sub%20sub%20sub"><h3>sub sub sub<a class="anchor" href="#1.1.1:sub%20sub%20sub"></a></h3>
-</section></section><section class="h2 x" id="1.2:sub2%20bar"><h2 class="x">sub2 bar<a class="anchor" href="#1.2:sub2%20bar"></a></h2>
+'<section class="h2" id="0.1:foo"><h2>foo<a class="anchor" href="#0.1:foo" aria-label="#0.1:foo"></a></h2>
+</section><section class="h1" id="1:bar"><h1>bar<a class="anchor" href="#1:bar" aria-label="#1:bar"></a></h1>
+<section class="h2" id="1.1:sub bar"><h2>sub bar<a class="anchor" href="#1.1:sub bar" aria-label="#1.1:sub bar"></a></h2>
+<section class="h3" id="1.1.1:sub sub sub"><h3>sub sub sub<a class="anchor" href="#1.1.1:sub sub sub" aria-label="#1.1.1:sub sub sub"></a></h3>
+</section></section><section class="h2 x" id="1.2:sub2 bar"><h2 class="x">sub2 bar<a class="anchor" href="#1.2:sub2 bar" aria-label="#1.2:sub2 bar"></a></h2>
</section></section>' \
'Headline Nesting'
Tests
-----
[Link with Title](https://en.wikipedia.org/wiki/Markdown "Markdown in Wikipedia"), *emphasis*, **strong**, **strong containing *emphasis***, `inline code`, `` code with `backticks` ``. See more tests [here](./tests/).' \
-'<section class="h1" id="1:Markdown.awk"><h1>Markdown.awk<a class="anchor" href="#1:Markdown.awk"></a></h1>
-<section class="h2" id="1.1:Supported%20Features%20/%20TODO:"><h2>Supported Features / TODO:<a class="anchor" href="#1.1:Supported%20Features%20/%20TODO:"></a></h2>
+'<section class="h1" id="1:Markdown.awk"><h1>Markdown.awk<a class="anchor" href="#1:Markdown.awk" aria-label="#1:Markdown.awk"></a></h1>
+<section class="h2" id="1.1:Supported Features / TODO:"><h2>Supported Features / TODO:<a class="anchor" href="#1.1:Supported Features / TODO:" aria-label="#1.1:Supported Features / TODO:"></a></h2>
<ul>
<li class="task done"><input type=checkbox disabled checked> done</li>
<li class="task pending"><input type=checkbox disabled> todo</li>
<li>? unsure (whether to implement)</li>
<li class="task partial"><input type=checkbox disabled> partial</li>
</ul>
-<section class="h3" id="1.1.1:Basic%20Markdown%20-%20Block%20elements:"><h3>Basic Markdown - Block elements:<a class="anchor" href="#1.1.1:Basic%20Markdown%20-%20Block%20elements:"></a></h3>
+<section class="h3" id="1.1.1:Basic Markdown - Block elements:"><h3>Basic Markdown - Block elements:<a class="anchor" href="#1.1.1:Basic Markdown - Block elements:" aria-label="#1.1.1:Basic Markdown - Block elements:"></a></h3>
<ul>
<li class="task done"><input type=checkbox disabled checked><p> Paragraphs</p>
<ul>
<li class="task done"><input type=checkbox disabled checked> Horizontal rules</li>
<li class="task done"><input type=checkbox disabled checked> Verbatim HTML block (disabled by default)</li>
</ul>
-</section><section class="h3" id="1.1.2:Basic%20Markdown%20-%20Inline%20elements:"><h3>Basic Markdown - Inline elements:<a class="anchor" href="#1.1.2:Basic%20Markdown%20-%20Inline%20elements:"></a></h3>
+</section><section class="h3" id="1.1.2:Basic Markdown - Inline elements:"><h3>Basic Markdown - Inline elements:<a class="anchor" href="#1.1.2:Basic Markdown - Inline elements:" aria-label="#1.1.2:Basic Markdown - Inline elements:"></a></h3>
<ul>
<li class="task done"><input type=checkbox disabled checked> Links</li>
<li class="task done"><input type=checkbox disabled checked> Reference style links</li>
</ul>
<p>NOTE: Set the environment variable <code>MD_HTML=true</code> to enable verbatim HTML</p>
-</section><section class="h3" id="1.1.3:Extensions%20-%20Block%20elements:"><h3>Extensions - Block elements:<a class="anchor" href="#1.1.3:Extensions%20-%20Block%20elements:"></a></h3>
+</section><section class="h3" id="1.1.3:Extensions - Block elements:"><h3>Extensions - Block elements:<a class="anchor" href="#1.1.3:Extensions - Block elements:" aria-label="#1.1.3:Extensions - Block elements:"></a></h3>
<ul>
<li class="task done"><input type=checkbox disabled checked> Automatic <section>-wrapping (custom)</li>
<li><p> ? Heading identifiers (php md, pandoc)</p>
<li class="task done"><input type=checkbox disabled checked> Metadata blocks (custom)</li>
<li class="task done"><input type=checkbox disabled checked> Fenced Divs (pandoc)</li>
</ul>
-</section><section class="h3" id="1.1.4:Extensions%20-%20Inline%20elements:"><h3>Extensions - Inline elements:<a class="anchor" href="#1.1.4:Extensions%20-%20Inline%20elements:"></a></h3>
+</section><section class="h3" id="1.1.4:Extensions - Inline elements:"><h3>Extensions - Inline elements:<a class="anchor" href="#1.1.4:Extensions - Inline elements:" aria-label="#1.1.4:Extensions - Inline elements:"></a></h3>
<ul>
<li class="task done"><input type=checkbox disabled checked> Ignore embedded_underscores (php md, pandoc)</li>
<li class="task done"><input type=checkbox disabled checked> <del>strikeout</del> (pandoc)</li>
<li class="task pending"><input type=checkbox disabled> Automatic em-dash / en-dash</li>
<li class="task done"><input type=checkbox disabled checked> Automatic → Arrows ← (custom)</li>
</ul>
-</section></section><section class="h2" id="1.2:Compatibility"><h2>Compatibility<a class="anchor" href="#1.2:Compatibility"></a></h2>
+</section></section><section class="h2" id="1.2:Compatibility"><h2>Compatibility<a class="anchor" href="#1.2:Compatibility" aria-label="#1.2:Compatibility"></a></h2>
<p>Markdown.awk can run in GNU awk (<code>gawk</code>) and in Busybox awk. It is <em>not</em> fully POSIX compliant and does not run in <code>mawk</code> or <code>nawk</code>. In particular it makes heavy use of the <code>gensub()</code> function and its ability to use paranthesized subexpressions in the replacement text. This feature is not available in the POSIX specified <code>sub()</code> and <code>gsub()</code> functions. Hence it cannot be replaced without effort.</p>
-</section><section class="h2" id="1.3:Tests"><h2>Tests<a class="anchor" href="#1.3:Tests"></a></h2>
+</section><section class="h2" id="1.3:Tests"><h2>Tests<a class="anchor" href="#1.3:Tests" aria-label="#1.3:Tests"></a></h2>
<p><a href="https://en.wikipedia.org/wiki/Markdown" title="Markdown in Wikipedia">Link with Title</a>, <em>emphasis</em>, <strong>strong</strong>, <strong>strong containing <em>emphasis</em></strong>, <code>inline code</code>, <code>code with `backticks`</code>. See more tests <a href="./tests/">here</a>.</p>
</section></section>' \
'Full Page (cgilite markdown)'
1. first list item
2. second list item' \
-'<section class="h1" id="1:Headline%20First%20Order"><h1>Headline First Order<a class="anchor" href="#1:Headline%20First%20Order"></a></h1>
-<section class="h2" id="1.1:Headline%20Second%20Order"><h2>Headline Second Order<a class="anchor" href="#1.1:Headline%20Second%20Order"></a></h2>
+'<section class="h1" id="1:Headline First Order"><h1>Headline First Order<a class="anchor" href="#1:Headline First Order" aria-label="#1:Headline First Order"></a></h1>
+<section class="h2" id="1.1:Headline Second Order"><h2>Headline Second Order<a class="anchor" href="#1.1:Headline Second Order" aria-label="#1.1:Headline Second Order"></a></h2>
<pre><code>Code Block
with indentation</code></pre>
-<blockquote><section class="h2" id="1/0.1:Blockquote"><h2>Blockquote<a class="anchor" href="#1/0.1:Blockquote"></a></h2>
+<blockquote><section class="h2" id="1/0.1:Blockquote"><h2>Blockquote<a class="anchor" href="#1/0.1:Blockquote" aria-label="#1/0.1:Blockquote"></a></h2>
<p>like in an email</p>
</section></blockquote>
-<section class="h3" id="1.1.1:Headline%203rd%20order"><h3>Headline 3rd order<a class="anchor" href="#1.1.1:Headline%203rd%20order"></a></h3>
+<section class="h3" id="1.1.1:Headline 3rd order"><h3>Headline 3rd order<a class="anchor" href="#1.1.1:Headline 3rd order" aria-label="#1.1.1:Headline 3rd order"></a></h3>
<ul>
<li>unordered List</li>
</ul>
</ul>
<hr>
-<pre><code class="blue">Fenced Code Block
+<pre class="blue"><code class="blue">Fenced Code Block
# with verbatim Text
`and an attribute`</code></pre>
<div class="line-block">The limerick packs laughs anatomical<br>
Syntax
------
-The wiki syntax is based on John Grubers [Markdown](https://daringfireball.net/projects/markdown/) with extensions borrowed from [Pandoc](https://pandoc.org/MANUAL%202.html#pandocs-markdown) and [PHP Markdown Extra](https://michelf.ca/projects/php-markdown/extra/). The Markdown parser is provided by [Cgilite](/software/cgilite/) and its full documentation can be looked at [here](/software/cgilite/markdown/).
+The wiki syntax is based on John Grubers [Markdown](https://daringfireball.net/projects/markdown/) with extensions borrowed from [Pandoc](https://pandoc.org/MANUAL 2.html#pandocs-markdown) and [PHP Markdown Extra](https://michelf.ca/projects/php-markdown/extra/). The Markdown parser is provided by [Cgilite](/software/cgilite/) and its full documentation can be looked at [here](/software/cgilite/markdown/).
<<include --nolink /[wiki]/editorhelp/>>
- [Macros](dev-macros/)
- [Handlers](dev-handlers/)
- [Parsers](dev-parsers/)' \
-'<section class="h1" id="1:Shellwiki"><h1>Shellwiki<a class="anchor" href="#1:Shellwiki"></a></h1>
+'<section class="h1" id="1:Shellwiki"><h1>Shellwiki<a class="anchor" href="#1:Shellwiki" aria-label="#1:Shellwiki"></a></h1>
<p>Shellwiki is a Wiki and Content Management System with minimal dependencies. It can run on embedded devices, as well as full size web servers. Its goals are:</p>
<ul>
<li><p><strong>easy deployment</strong></p>
be written and modified by system administrators. </p>
</li>
</ul>
-<code class="macro">toc 2 2</code><section class="h2" id="1.1:Features"><h2>Features<a class="anchor" href="#1.1:Features"></a></h2>
+<code class="macro">toc 2 2</code><section class="h2" id="1.1:Features"><h2>Features<a class="anchor" href="#1.1:Features" aria-label="#1.1:Features"></a></h2>
<ul>
<li><p><strong>Markdown Wiki Syntax</strong></p>
</ul>
</li>
</ul>
-</section><section class="h2" id="1.2:Dependencies"><h2>Dependencies<a class="anchor" href="#1.2:Dependencies"></a></h2>
+</section><section class="h2" id="1.2:Dependencies"><h2>Dependencies<a class="anchor" href="#1.2:Dependencies" aria-label="#1.2:Dependencies"></a></h2>
<p>Shellwiki is based on <a href="/software/cgilite/">cgilite</a>, which is included in the installation. It is written in posix compliant shell script, and the markdown renderer is written in <del>posix compliant</del> AWK. The entire wiki system can run with nothing more than a busybox. In fact it can be served from the rescue shell in a Debian initrd, or from an OpenWRT router.</p>
<p><strong>Its precise requirements are:</strong></p>
<li><p><em>Optional:</em> Sendmail for sending password reminders, etc.</p>
</li>
</ul>
-</section><section class="h2" id="1.3:Installation"><h2>Installation<a class="anchor" href="#1.3:Installation"></a></h2>
+</section><section class="h2" id="1.3:Installation"><h2>Installation<a class="anchor" href="#1.3:Installation" aria-label="#1.3:Installation"></a></h2>
<p>Also see → <a href="installation/">installation/</a></p>
<p>You can try out shellwiki right now using busybox:</p>
~$ _DATA=~/wikidata busybox nc -llp 1080 -e ~/shellwiki/index.cgi</code></pre>
<p>For additional examples, regarding permanent installation and configuration in webservers see <a href="installation/">installation/</a>.</p>
-</section><section class="h2" id="1.4:Syntax"><h2>Syntax<a class="anchor" href="#1.4:Syntax"></a></h2>
-<p>The wiki syntax is based on John Grubers <a href="https://daringfireball.net/projects/markdown/">Markdown</a> with extensions borrowed from <a href="https://pandoc.org/MANUAL%202.html#pandocs-markdown">Pandoc</a> and <a href="https://michelf.ca/projects/php-markdown/extra/">PHP Markdown Extra</a>. The Markdown parser is provided by <a href="/software/cgilite/">Cgilite</a> and its full documentation can be looked at <a href="/software/cgilite/markdown/">here</a>.</p>
+</section><section class="h2" id="1.4:Syntax"><h2>Syntax<a class="anchor" href="#1.4:Syntax" aria-label="#1.4:Syntax"></a></h2>
+<p>The wiki syntax is based on John Grubers <a href="https://daringfireball.net/projects/markdown/">Markdown</a> with extensions borrowed from <a href="https://pandoc.org/MANUAL 2.html#pandocs-markdown">Pandoc</a> and <a href="https://michelf.ca/projects/php-markdown/extra/">PHP Markdown Extra</a>. The Markdown parser is provided by <a href="/software/cgilite/">Cgilite</a> and its full documentation can be looked at <a href="/software/cgilite/markdown/">here</a>.</p>
-<code class="macro">include --nolink /[wiki]/editorhelp/</code></section><section class="h2" id="1.5:Macros"><h2>Macros<a class="anchor" href="#1.5:Macros"></a></h2>
+<code class="macro">include --nolink /[wiki]/editorhelp/</code></section><section class="h2" id="1.5:Macros"><h2>Macros<a class="anchor" href="#1.5:Macros" aria-label="#1.5:Macros"></a></h2>
<p>Also see → <a href="macros/">macros/</a></p>
<p>In addition to the Markdown syntax, wiki pages can include Macros, which perform additional functions on a page, like generating an image gallery, including parts of other pages, etc. Macros make Shellwiki truly dynamic and flexible.</p>
<p>Macros are the most easy to write type of extension. See <a href="macros/">Macros</a> for a full list of available macros.</p>
-</section><section class="h2" id="1.6:Themes"><h2>Themes<a class="anchor" href="#1.6:Themes"></a></h2>
+</section><section class="h2" id="1.6:Themes"><h2>Themes<a class="anchor" href="#1.6:Themes" aria-label="#1.6:Themes"></a></h2>
<p>Also see → <a href="theming/">theming/</a></p>
<p>While Shellwiki supports plugins for <a href="dev-theming/">theming</a>, it's apearance can mostly be configured by the user. Pages can be configured to use custom CSS files. In addition page headers and footers are themselves wiki pages which can be modified to add menus, custom logos, links, etc. The same goes for error pages.</p>
<p>For an example, see the <a href="/[wiki]/">technical pages</a> for this wiki.</p>
-</section><section class="h2" id="1.7:Multiple%20Languages"><h2>Multiple Languages<a class="anchor" href="#1.7:Multiple%20Languages"></a></h2>
+</section><section class="h2" id="1.7:Multiple Languages"><h2>Multiple Languages<a class="anchor" href="#1.7:Multiple Languages" aria-label="#1.7:Multiple Languages"></a></h2>
<p>To enable a multilingual setup you must set a default language in your configuration environment:</p>
<pre><code>export LANGUAGE_DEFAULT=en</code></pre>
<p>Header, footer, and error pages will be included from their respective language version, as will all macro includes, etc. Should a page not exist in a given language, the default page will be displayed instead. However, included elements will still be taken from the respective language version, possibly mixing languages between the selected user language and the default.</p>
-<section class="h3" id="1.7.1:Constraints%20of%20the%20current%20implementation"><h3>Constraints of the current implementation<a class="anchor" href="#1.7.1:Constraints%20of%20the%20current%20implementation"></a></h3>
+<section class="h3" id="1.7.1:Constraints of the current implementation"><h3>Constraints of the current implementation<a class="anchor" href="#1.7.1:Constraints of the current implementation" aria-label="#1.7.1:Constraints of the current implementation"></a></h3>
<ul>
<li>There can be only one default language, with no priority of different fallback languages</li>
<li>Page URLs can currently not be translated. Doing so would require a model for manually assigning translated page names and would not be trivial to use.</li>
</ul>
-</section></section><section class="h2" id="1.8:Developer%20Documentation"><h2>Developer Documentation<a class="anchor" href="#1.8:Developer%20Documentation"></a></h2>
+</section></section><section class="h2" id="1.8:Developer Documentation"><h2>Developer Documentation<a class="anchor" href="#1.8:Developer Documentation" aria-label="#1.8:Developer Documentation"></a></h2>
<p>How to write:</p>
<ul>
<li><a href="dev-theming/">Themes</a></li>