X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;ds=sidebyside;f=markdown.awk;h=949ea9390f8450e8982b10945854f29076bde118;hb=2bd7c7ece5376f659a1888615b12adf3d6a96744;hp=506d22d08474b5f4a14dc5953c1dda121f4b9678;hpb=f5a7a98f217d9a047cba2c9c92c21baa46d9e0db;p=shellwiki
diff --git a/markdown.awk b/markdown.awk
index 506d22d..949ea93 100755
--- a/markdown.awk
+++ b/markdown.awk
@@ -54,7 +54,7 @@
# - [x] Pipe table (php md, pandoc)
# - [x] Line blocks (pandoc)
# - [x] Task lists (pandoc, custom)
-# - [ ] Definition lists (php md, pandoc)
+# - [x] Definition lists (php md, pandoc)
# - [-] Numbered example lists (pandoc)
# - [-] Metadata blocks (pandoc)
# - [x] Metadata blocks (custom)
@@ -323,7 +323,7 @@ function headline( hlvl, htxt, attrib, LOCAL, sec, n, HL) {
return sec " " inline(block) " /, "", p );
- sub( /<\/p>\n/, "", p );
+ gsub("\n {0," indent "}", "\n", text);
+
+ task = match( text, /^\[ \]/ ) ? " (\n" _nblock( gensub( /(^|\n)> /, "\n", "g", substr(block, 1, st - 1) ) ) "
\n\n" \
+ return "" gensub( /^\n|\n$/, "", "g", _nblock( gensub( /(^|\n)> /, "\n", "g", substr(block, 1, st - 1) ) ) ) "
\n\n" \
_block( substr(block, st + len) );
# Pipe Tables (pandoc / php md / gfm )
@@ -514,11 +514,11 @@ function _block( block, LOCAL, st, len, hlvl, htxt, sec, guard, code, indent, at
# Line Blocks (pandoc)
} else if ( match(block, /^\| [^\n]*(\n|$)(\| [^\n]*(\n|$)|[ \t]+[^\n[:space:]][^\n]*(\n|$))*/) ) {
len = RLENGTH; st = RSTART;
- code = substr(block, 1, len);
- gsub(/\n[[:space:]]+/, " ", code);
- gsub(/\n\| /, "\n", code);
- gsub(/^\| |\n$/, "", code);
- return "
\n", "g", inline( code )) "
\n", "g", inline( text )) "\n" _list( substr(list, 2) ) "
\n" _block( block );
-
- # Ordered list
- } else if ( match( block, "^ ? ? ?([0-9]+|#)\\.[ \t]+[^\n]+(\n|$)" \
- "(([ \t]*\n)* ? ? ?([0-9]+|#)\\.[ \t]+[^\n]+(\n|$)" \
- "|([ \t]*\n)*( ? ? ?\t| +)[^\n]+(\n|$)" \
- "|[^\n]+(\n|$))*" ) ) {
- list = substr( block, 1, RLENGTH);
- block = substr( block, RLENGTH + 1);
- indent = length( gensub(/([0-9]+|#)\.[ \t]+[^\n]+.*$/, "", 1, list) );
-
- gsub("(^|\n) {0," indent "}", "\n", list);
- return "\n\n" _list( substr(list, 2) ) "
\n" _block( block );
-
# First Order Heading H1 + Attrib
} else if ( match( block, /^([^\n]+)([ \t]*\{([^\}\n]+)\})\n===+(\n|$)/ ) ) {
len = RLENGTH;
@@ -704,69 +680,118 @@ function _block( block, LOCAL, st, len, hlvl, htxt, sec, guard, code, indent, at
text = gensub(/^<<(([^>]|>[^>])+)>>(\n.*)?$/, "\\1", 1, block);
return macro(text) _block(substr(block, len + 1) );
+ # Horizontal rule
+ } else if ( match( block, /(^|\n) ? ? ?((\* *){3,}|(- *){3,}|(_ *){3,})($|\n)/) ) {
+ len = RLENGTH; st = RSTART;
+ return _block(substr(block, 1, st - 1)) "
\n" _block(substr(block, st + len));
+
+ # Definition list
+ } else if (match( block, "^(([ \t]*\n)*[^:\n \t][^\n]+\n" \
+ "([ \t]*\n)* ? ? ?:[ \t][^\n]+(\n|$)" \
+ "(([ \t]*\n)* ? ? ?:[ \t][^\n]+(\n|$)" \
+ "|[^:\n \t][^\n]+(\n|$)" \
+ "|( ? ? ?\t| +)[^\n]+(\n|$)" \
+ "|([ \t]*\n)+( ? ? ?\t| +)[^\n]+(\n|$))*)+" \
+ )) {
+ list = substr( block, 1, RLENGTH); block = substr( block, RLENGTH + 1);
+ return "\n\n" _dlist( list ) "
\n" _block( block );
+
+ # Unordered list
+ } else if ( match( block, "(^|\n) ? ? ?[-+*][ \t][^\n]+(\n|$)" \
+ "(([ \t]*\n)* ? ? ?[-+*][ \t][^\n]+(\n|$)" \
+ "|([ \t]*\n)*( ? ? ?\t| +)[^\n]+(\n|$)" \
+ "|[^\n \t][^\n]+(\n|$))*" ) ) {
+ st = RSTART; len = RLENGTH; list = substr( block, RSTART, RLENGTH);
+ sub("^\n", "", list); match(list, "^ ? ? ?[-+*]"); indent = RLENGTH;
+ gsub( "(^|\n) {0," indent - 1 "}", "\n", list); sub("^\n", "", list);
+
+ text = substr(block, 1, st - 1); block = substr(block, st + len);
+ if (match( list, "\n([0-9]+\\.|#\\.)[ \t]" )) {
+ block = substr(list, RSTART + 1) block;
+ list = substr(list, 1, RSTART);
+ }
+
+ return _block( text ) "\n" _list( list, "[-+*]" ) "
\n" _block( block );
+
+ # Ordered list
+ } else if ( match( block, "(^|\n) ? ? ?([0-9]+\\.|#\\.)[ \t][^\n]+(\n|$)" \
+ "(([ \t]*\n)* ? ? ?([0-9]+\\.|#\\.)[ \t][^\n]+(\n|$)" \
+ "|([ \t]*\n)*( ? ? ?\t| +)[^\n]+(\n|$)" \
+ "|[^\n \t][^\n]+(\n|$))*" ) ) {
+ st = RSTART; len = RLENGTH; list = substr( block, RSTART, RLENGTH);
+ sub("^\n", "", list); match(list, "^ ? ? ?[0-9#]"); indent = RLENGTH;
+ gsub( "(^|\n) {0," indent - 1 "}", "\n", list); sub("^\n", "", list);
+
+ text = substr(block, 1, st - 1); block = substr(block, st + len);
+ if (match( list, "\n[-+*][ \t]" )) {
+ block = substr(list, RSTART + 1) block;
+ list = substr(list, 1, RSTART);
+ }
+
+ return _block( text ) "\n" _list( list, "([0-9]+\\.|#\\.)" ) "
\n" _block( block );
+
# Split paragraphs
} else if ( match( block, /(^|\n)[[:space:]]*(\n|$)/) ) {
len = RLENGTH; st = RSTART;
return _block( substr(block, 1, st - 1) ) "\n" \
_block( substr(block, st + len) );
- # Horizontal rule
- } else if ( match( block, /(^|\n) ? ? ?((\* *){3,}|(- *){3,}|(_ *){3,})($|\n)/) ) {
- len = RLENGTH; st = RSTART;
- return _block(substr(block, 1, st - 1)) "
\n" _block(substr(block, st + len));
-
# Plain paragraph
} else {
return "
|
\n$)", "", text); + + return task text "\n" _list(block, mark); +} + +function _dlist (block, LOCAL, len, st, text, indent, p) { + if (match( block, "^([ \t]*\n)*[^:\n \t][^\n]+\n" )) { + len = RLENGTH; text = substr(block, 1, len); + gsub( "(^\n*|\n*$)", "", text ); + return "(
]|[^p]|<[^/]|[^<])*\n$" )) + gsub( "(^|
\n$)", "", text); + + return "\[ \].*/ ) { return "
" \ - substr(p, 7) "
\[-\].*/ ) { return "
" \ - substr(p, 7) "
\[\?\].*/ ) { return "
" \ - substr(p, 7) "
\[\/\].*/ ) { return "
" \ - substr(p, 7) "
\[[xX]\].*/ ) { return "
" \ - substr(p, 7) "