]> git.plutz.net Git - shellwiki/commitdiff
Merge commit 'fb04e54ec3eecd4420c0f65780bc1099c911373a'
authorPaul Hänsch <paul@plutz.net>
Mon, 28 Aug 2023 14:32:42 +0000 (16:32 +0200)
committerPaul Hänsch <paul@plutz.net>
Mon, 28 Aug 2023 14:32:42 +0000 (16:32 +0200)
1  2 
cgilite/markdown.awk

diff --combined cgilite/markdown.awk
index ffa225b477f6e8ff3dd1b157bc0f6e715df0a494,be7d723b6b96d0efa7ccdc9ecc5be38c881f1026..be7d723b6b96d0efa7ccdc9ecc5be38c881f1026
@@@ -54,7 -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)
@@@ -590,6 -590,17 +590,17 @@@ function _block( block, LOCAL, st, len
    gsub("(^|\n) {0," indent "}", "\n", list);
    return "\n<ol>\n" _list( substr(list, 2) ) "</ol>\n" _block( block );
  
+   # 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<dl>\n" _dlist( list ) "</dl>\n" _block( block );
    # First Order Heading H1 + Attrib
    } else if ( match( block, /^([^\n]+)([ \t]*\{([^\}\n]+)\})\n===+(\n|$)/ ) ) {
      len = RLENGTH;
    }
  }
  
+ 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 "<dt>" inline( text ) "</dt>\n" _dlist( substr(block, len + 1) );
+   } else if (match( block, "^([ \t]*\n)* ? ? ?:[ \t][^\n]+(\n|$)" \
+                          "([^:\n \t][^\n]+(\n|$)" \
+                          "|( ? ? ?\t|  +)[^\n]+(\n|$)" \
+                          "|([ \t]*\n)+( ? ? ?\t|  +)[^\n]+(\n|$))*" \
+   )) {
+     len = RLENGTH; text = substr(block, 1, len);
+     if (match( text, "^ ? ? ?:[ \t][^\n]+(\n|$)" \
+                     "([^:\n \t][^\n]+(\n|$)" \
+                     "|( ? ? ?\t|  +)[^\t\n ][^\n]*(\n|$))*$" \
+     )) p = 1; else p = 0;
+     sub( "^([ \t]*\n)*", "", text);
+     match(text, "^ ? ? ?:(\t| +)"); indent = RLENGTH;
+     sub( "^ ? ? ?:(\t| +)", "", text);
+     gsub( "(^|\n) {0," indent "}", "\n", text );
+     text = _block(text);
+     if (p) gsub("(^\n*<p>|</p>\n*$)", "", text);
+     return "<dd>" text "</dd>\n" _dlist( substr(block, len + 1) );
+   }
+ }
  function _list( block, last, LOCAL, p) {
    if ( ! length(block) ) return "";
    gsub(/^([-+*]|[0-9]+\.|#\.)(  ? ? ?|\t)/, "", block)