]> git.plutz.net Git - cgilite/blobdiff - markdown.awk
md: handle DOS line breaks
[cgilite] / markdown.awk
index 785ece87fbad731d7d4de1343752a2a63ccc9632..973818067497779dc286f234b1c1ed489f2e4dfe 100755 (executable)
@@ -51,7 +51,7 @@
 #   -  ?  Grid table (pandoc)
 #   -  ?  Pipe table (php md pandoc)
 # - [x] Line blocks (pandoc)
-# - [ ] Task lists (pandoc)
+# - [x] Task lists (pandoc)
 # - [ ] Definition lists (php md, pandoc)
 # - [-] Numbered example lists (pandoc)
 # - [-] Metadata blocks (pandoc)
@@ -396,6 +396,12 @@ function _list( block, last, LOCAL, p) {
     sub( /<\/p>\n/, "", p );
   }
   sub( /\n$/, "", p );
+
+  # Task List (pandoc)
+       if ( p ~ /^\[ \].*/ )       { p = "<input type=checkbox disabled />" substr(p, 4); }
+  else if ( p ~ /^\[[xX]\].*/ )    { p = "<input type=checkbox disabled checked />" substr(p, 4); }
+  else if ( p ~ /^<p>\[ \].*/ )    { p = "<p><input type=checkbox disabled />" substr(p, 7); }
+  else if ( p ~ /^<p>\[[xX]\].*/ ) { p = "<p><input type=checkbox disabled checked />" substr(p, 7); }
   return "<li>" p "</li>\n" _list( block, last );
 }
 
@@ -406,6 +412,8 @@ BEGIN {
 
   # Buffering of full file ist necessary, e.g. to find reference links
   while (getline) { file = file $0 "\n"; }
+  # Clean up MS-DOS line breaks
+  gsub(/\r\n/, "\n", file);
 
   # Fill array of reference links
   f = file; rl_id;