X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;ds=sidebyside;f=cgilite%2Fmarkdown.awk;h=34879d25c22ba3498633c366374a9feeac6be943;hb=6a9f5a21897f72c61f297b256c5512d5e1b8c667;hp=75f182746bd29d9375c7af1b1e52c39737fb2a58;hpb=08e02da11207d97b7c7d4db58619cdb0a59476e2;p=shellwiki
diff --git a/cgilite/markdown.awk b/cgilite/markdown.awk
index 75f1827..34879d2 100755
--- a/cgilite/markdown.awk
+++ b/cgilite/markdown.awk
@@ -158,18 +158,18 @@ function inline( line, LOCAL, len, text, code, href, guard ) {
href = gensub(/^\[\[([^]|]+)(\|([^]]+))?\]\]/, "\\1", 1, substr(line, 1, len) );
text = gensub(/^\[\[([^]|]+)(\|([^]]+))?\]\]/, "\\3", 1, substr(line, 1, len) );
if ( ! text ) text = href;
- return "" HTML(text) "" inline( substr( line, len + 1) );
+ return "" HTML(text) "" inline( substr( line, len + 1) );
# quick links ("automatic links" in md doc)
} else if ( match( line, /^<[a-zA-Z]+:\/\/([-\.[:alnum:]]+)(:[0-9]*)?(\/[^>]*)?>/ ) ) {
len = RLENGTH;
- href = URL( substr( line, 2, len - 2) );
+ href = HTML( substr( line, 2, len - 2) );
return "" href "" inline( substr( line, len + 1) );
# 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])?)*>/ ) ) {
len = RLENGTH;
- href = URL( substr( line, 2, len - 2) );
+ href = HTML( substr( line, 2, len - 2) );
return "" href "" inline( substr( line, len + 1) );
# Verbatim inline HTML
@@ -178,12 +178,12 @@ function inline( line, LOCAL, len, text, code, href, guard ) {
return substr( line, 1, len) inline(substr(line, len + 1));
# inline links
- } else if ( match(line, "^" lii "\\([\\n\\t ]*" lid "([\\n\\t ]+" lit ")?[\\n\\t ]*\\)") ) {
+ } else if ( match(line, "^" lii "\\([\n\t ]*" lid "([\n\t ]+" lit ")?[\n\t ]*\\)") ) {
len = RLENGTH;
text = href = title = substr( line, 1, len);
- sub("^\\[", "", text); sub("\\]\\([\\n\\t ]*" lid "([\\n\\t ]+" lit ")?[\\n\\t ]*\\)$", "", text);
- sub("^" lii "\\([\\n\\t ]*", "", href); sub("([\\n\\t ]+" lit ")?[\\n\\t ]*\\)$", "", href);
- sub("^" lii "\\([\\n\\t ]*" lid, "", title); sub("[\\n\\t ]*\\)$", "", title); sub("^[\\n\\t ]+", "", title);
+ sub("^\\[", "", text); sub("\\]\\([\n\t ]*" lid "([\n\t ]+" lit ")?[\n\t ]*\\)$", "", text);
+ sub("^" lii "\\([\n\t ]*", "", href); sub("([\n\t ]+" lit ")?[\n\t ]*\\)$", "", href);
+ sub("^" lii "\\([\n\t ]*" lid, "", title); sub("[\n\t ]*\\)$", "", title); sub("^[\n\t ]+", "", title);
if ( match(href, /^<.*>$/) ) { sub(/^, "", href); sub(/>$/, "", href); }
if ( match(title, /^".*"$/) ) { sub(/^"/, "", title); sub(/"$/, "", title); }
@@ -192,7 +192,7 @@ function inline( line, LOCAL, len, text, code, href, guard ) {
gsub(/\\/, "", href); gsub(/\\/, "", title); gsub(/[\n\t]+/, " ", title);
- return "" \
+ return "" \
inline( text ) "" inline( substr( line, len + 1) );
# reference style links
@@ -202,28 +202,28 @@ function inline( line, LOCAL, len, text, code, href, guard ) {
id = gensub(/^\[([^\n]+)\] ?\[([^\n]*)\].*/, "\\2", 1, substr(line, 1, len) );
if ( ! id ) id = text;
if ( rl_href[id] && rl_title[id] ) {
- return "" inline(text) "" inline( substr( line, len + 1) );
+ return "" inline(text) "" inline( substr( line, len + 1) );
} else if ( rl_href[id] ) {
- return "" inline(text) "" inline( substr( line, len + 1) );
+ return "" inline(text) "" inline( substr( line, len + 1) );
} else {
return "" HTML(substr(line, 1, len)) inline( substr(line, len + 1) );
}
# 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 ]*\\)(\\{[a-zA-Z \t-]*\\})?") ) {
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 ]*\\)(\\{[a-zA-Z \t-]*\\})?$", "", text);
- sub("^!" lix "\\([\\n\\t ]*", "", href);
- sub("([\\n\\t ]+" lit ")?[\\n\\t ]*\\)(\\{[a-zA-Z \\t-]*\\})?$", "", href);
+ sub("^!" lix "\\([\n\t ]*", "", href);
+ sub("([\n\t ]+" lit ")?[\n\t ]*\\)(\\{[a-zA-Z \t-]*\\})?$", "", href);
- sub("^!" lix "\\([\\n\\t ]*" lid, "", title);
- sub("[\\n\\t ]*\\)(\\{[a-zA-Z \\t-]*\\})?$", "", title);
- sub("^[\\n\\t ]+", "", title);
+ sub("^!" lix "\\([\n\t ]*" lid, "", title);
+ sub("[\n\t ]*\\)(\\{[a-zA-Z \t-]*\\})?$", "", title);
+ sub("^[\n\t ]+", "", title);
- sub("^!" lix "\\([\\n\\t ]*" lid "([\\n\\t ]+" lit ")?[\\n\\t ]*\\)", "", attrib);
+ sub("^!" lix "\\([\n\t ]*" lid "([\n\t ]+" lit ")?[\n\t ]*\\)", "", attrib);
sub(/^\{[ \t]*/, "", attrib); sub(/[ \t]*\}$/, "", attrib); gsub(/[ \t]+/, " ", attrib);
if ( match(href, /^<.*>$/) ) { sub(/^, "", href); sub(/>$/, "", href); }
@@ -231,9 +231,10 @@ function inline( line, LOCAL, len, text, code, href, guard ) {
else if ( match(title, /^'.*'$/) ) { sub(/^'/, "", title); sub(/'$/, "", title); }
else if ( match(title, /^\(.*\)$/) ) { sub(/^\(/, "", title); sub(/\)$/, "", title); }
- gsub(/\\/, "", href); gsub(/\\/, "", title); gsub(/[\n\t]+/, " ", title);
+ gsub(/^[\t ]+$/, "", text); gsub(/\\/, "", href);
+ gsub(/\\/, "", title); gsub(/[\n\t]+/, " ", title);
- return "" inline( substr( line, len + 1) );
@@ -244,10 +245,10 @@ function inline( line, LOCAL, len, text, code, href, guard ) {
id = gensub(/^!\[([^\n]*)\] ?\[([^\n]*)\].*/, "\\2", 1, substr(line, 1, len) );
if ( ! id ) id = text;
if ( rl_href[id] && rl_title[id] ) {
- return "" \
+ return "" \
inline( substr( line, len + 1) );
} else if ( rl_href[id] ) {
- return "" \
+ return "" \
inline( substr( line, len + 1) );
} else {
return "" HTML(substr(line, 1, len)) inline( substr(line, len + 1) );
@@ -390,7 +391,7 @@ function _block( block, LOCAL, st, len, text, title, attrib, href, guard, code,
# Metadata (custom, block starting with %something)
# Metadata is ignored but can be interpreted externally
- } else if ( match(block, /^%[a-zA-Z]+([[:space:]][^\n]*)?(\n|$)(%[a-zA-Z]+([[:space:]][^\n]*)?(\n|$)|%([[:space:]][^\n]*)?(\n|$)|[ \t]+[^\n[:space:]][^\n]*(\n|$))*/) ) {
+ } else if ( match(block, /^%[a-zA-Z-]+([[:space:]][^\n]*)?(\n|$)(%[a-zA-Z-]+([[:space:]][^\n]*)?(\n|$)|%([[:space:]][^\n]*)?(\n|$)|[ \t]+[^\n[:space:]][^\n]*(\n|$))*/) ) {
len = RLENGTH; st = RSTART;
return _block( substr( block, len + 1) );
@@ -638,21 +639,21 @@ function _block( block, LOCAL, st, len, text, title, attrib, href, guard, code,
return headline( n, text, 0 ) _block( substr( block, len + 1) );
# block images (wrapped in