]> git.plutz.net Git - cgilite/blobdiff - markdown.awk
metadata blocks
[cgilite] / markdown.awk
index b3166f9e6c8580b919b960df50229750a7a1e3c8..b0647922efdcbf5859dac4d3cda72145035403ed 100755 (executable)
@@ -56,6 +56,7 @@
 # - [ ] Definition lists (php md, pandoc)
 # - [-] Numbered example lists (pandoc)
 # - [-] Metadata blocks (pandoc)
+# - [x] Metadata blocks (custom)
 # - [x] Fenced Divs (pandoc)
 #
 # Extensions - Inline elements:
@@ -279,6 +280,12 @@ function _block( block, LOCAL, st, len, hlvl, htxt, guard, code, indent, attrib
   } else if ( AllowHTML && match( block, /^ ? ? ?(<\/[A-Za-z][A-Za-z0-9-]*[[:space:]]*>|<[A-Za-z][A-Za-z0-9-]*([[:space:]]+[A-Za-z_:][A-Za-z0-9_\.:-]*([[:space:]]*=[[:space:]]*([[:space:]"'=<>`]+|"[^"]*"|'[^']*'))?)*[[:space:]]*\/?>)([[:space:]]*\n)([^\n]|\n[ \t]*[^\n])*(\n[[:space:]]*\n|$)/) ) {
     len = RLENGTH; st = RSTART;
     return substr(block, st, len) _block(substr(block, st + len));
+
+  # 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|$))*/) ) {
+    len = RLENGTH; st = RSTART;
+    return  _block( substr( block, len + 1) );
  
   # Blockquote (leading >)
   } else if ( match( block, /^> /) ) {
@@ -390,6 +397,12 @@ function _block( block, LOCAL, st, len, hlvl, htxt, guard, code, indent, attrib
     return "<h" hlvl " id=\"" hid " - " HTML(htxt) "\">" inline( htxt ) "</h" hlvl ">\n\n" \
            _block( substr( block, len + 1) );
 
+  # 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;
@@ -397,10 +410,7 @@ function _block( block, LOCAL, st, len, hlvl, htxt, guard, code, indent, attrib
 
   # Plain paragraph
   } else {
-    match( block, /(^|\n)[[:space:]]*(\n|$)/ ) || match( block, /$/ );
-    len = RLENGTH; st = RSTART;
-    return "<p>" inline( substr(block, 1, st - 1) ) "</p>\n" \
-           _block( substr(block, st + len) );
+    return "<p>" inline(block) "</p>\n";
   }
 }