return block sec;
}
-function _block( block, LOCAL, st, len, text, title, attrib, href, guard, code, indent, list, tmp ) {
- gsub( "(^\n+|\n+$)", "", block );
-
- if ( block == "" ) {
- return "";
-
- # HTML #2 #3 #4 $5
- } else if ( AllowHTML && match( block, /(^|\n) ? ? ?(<!--([^-]|-[^-]|--[^>])*(-->|$)|<\?([^\?]|\?[^>])*(\?>|$)|<![A-Z][^>]*(>|$)|<!\[CDATA\[([^\]]|\][^\]]|\]\][^>])*(\]\]>|$))/) ) {
- len = RLENGTH; st = RSTART;
- return _block(substr(block, 1, st - 1)) substr(block, st, len) _block(substr(block, st + len));
-
- # HTML #6
- } else if ( AllowHTML && match( tolower(block), /(^|\n) ? ? ?<\/?(address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[123456]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)([[:space:]\n>]|\/>)([^\n]|\n[ \t]*[^\n])*(\n[[:space:]]*\n|$)/) ) {
- len = RLENGTH; st = RSTART;
- return _block(substr(block, 1, st - 1)) substr(block, st, len) _block(substr(block, st + len));
-
- # HTML #1
- } else if ( AllowHTML && match( tolower(block), /(^|\n) ? ? ?<(script|pre|style)([[:space:]\n>]).*(<\/script>|<\/pre>|<\/style>|$)/) ) {
- len = RLENGTH; st = RSTART;
- match( tolower(substr(block, st, len)), /(<\/script>|<\/pre>|<\/style>)/);
- len = RSTART + RLENGTH;
- return _block(substr(block, 1, st - 1)) substr(block, st, len) _block(substr(block, st + len));
-
- # HTML #7
- } 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) );
+function _block( block, LOCAL, st, len, text, title, attrib, href, guard, code, indent, list, tmp, ret) {
+ ret = "";
+ while ( block != "" ) {
+ gsub( "(^\n+|\n+$)", "", block );
+
+ # HTML #2 #3 #4 $5
+ if ( AllowHTML && match( block, /(^|\n) ? ? ?(<!--([^-]|-[^-]|--[^>])*(-->|$)|<\?([^\?]|\?[^>])*(\?>|$)|<![A-Z][^>]*(>|$)|<!\[CDATA\[([^\]]|\][^\]]|\]\][^>])*(\]\]>|$))/) ) {
+ len = RLENGTH; st = RSTART;
+ ret = ret _block(substr(block, 1, st - 1)) substr(block, st, len); block = substr(block, st + len);
+ continue;
+
+ # HTML #6
+ } else if ( AllowHTML && match( tolower(block), /(^|\n) ? ? ?<\/?(address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[123456]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)([[:space:]\n>]|\/>)([^\n]|\n[ \t]*[^\n])*(\n[[:space:]]*\n|$)/) ) {
+ len = RLENGTH; st = RSTART;
+ ret = ret _block(substr(block, 1, st - 1)) substr(block, st, len); block = substr(block, st + len);
+ continue;
+
+ # HTML #1
+ } else if ( AllowHTML && match( tolower(block), /(^|\n) ? ? ?<(script|pre|style)([[:space:]\n>]).*(<\/script>|<\/pre>|<\/style>|$)/) ) {
+ len = RLENGTH; st = RSTART;
+ match( tolower(substr(block, st, len)), /(<\/script>|<\/pre>|<\/style>)/);
+ len = RSTART + RLENGTH;
+ ret = ret _block(substr(block, 1, st - 1)) substr(block, st, len); block = substr(block, st + len);
+ continue;
+
+ # HTML #7
+ } 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;
+ ret = ret substr(block, st, len); block = substr(block, st + len);
+ continue;
+
+ # 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;
+ block = substr( block, len + 1);
+ continue;
- # Blockquote (leading >)
- } else if ( match( block, /^> /) ) {
- match( block, /(^|\n)[[:space:]]*(\n|$)/ ) || match(block, /$/);
- len = RLENGTH; st = RSTART;
- text = substr(block, 1, st - 1); gsub( /(^|\n)> /, "\n", text );
- text = _nblock( text ); gsub( /^\n|\n$/, "", text )
- return "<blockquote>" text "</blockquote>\n\n" _block( substr(block, st + len) );
-
- # Pipe Tables (pandoc / php md / gfm )
- } else if ( match(block, "^((\\|)?([^\n]+\\|)+[^\n]+(\\|)?)\n" \
- "((\\|)?(:?-+:?[\\|+])+:?-+:?(\\|)?)\n" \
- "((\\|)?([^\n]+\\|)+[^\n]+(\\|)?(\n|$))+" ) ) {
- len = RLENGTH; st = RSTART;
- #initialize empty arrays
- split("", talign); split("", tarray);
- cols = 0; cnt=0; ttext = "";
-
- # table header and alignment
- tmp = substr(block, 1, match(block, /(\n|$)/));
- gsub( /(^|[^\\])\\\|/, "\\1\\|", tmp );
- gsub( /(^\||\|$)/, "", tmp)
- split( tmp, tarray, /\|/);
- block = substr(block, match(block, /(\n|$)/) + 1 );
- tmp = substr(block, 1, match(block, /(\n|$)/));
- gsub( /(^\||\|$)/, "", tmp );
- cols = split( tmp , talign, /[+\|]/);
- block = substr(block, match(block, /(\n|$)/) + 1 );
-
- for( cnt = 1; cnt < cols; cnt++ ) {
- if (match(talign[cnt], /:-+:/)) talign[cnt]="center";
- else if (match(talign[cnt], /-+:/)) talign[cnt]="right";
- else if (match(talign[cnt], /:-+/)) talign[cnt]="left";
- else talign[cnt]="";
- }
+ # Blockquote (leading >)
+ } else if ( match( block, /^> /) ) {
+ match( block, /(^|\n)[[:space:]]*(\n|$)/ ) || match(block, /$/);
+ len = RLENGTH; st = RSTART;
+ text = substr(block, 1, st - 1); gsub( /(^|\n)> /, "\n", text );
+ text = _nblock( text ); gsub( /^\n|\n$/, "", text )
+ ret = ret "<blockquote>" text "</blockquote>\n\n"; block = substr(block, st + len);
+ continue;
- ttext = "<thead>\n<tr>"
- for (cnt = 1; cnt < cols; cnt++)
- ttext = ttext "<th align=\"" talign[cnt] "\">" inline(tarray[cnt]) "</th>"
- ttext = ttext "</tr>\n</thead><tbody>\n"
+ # Pipe Tables (pandoc / php md / gfm )
+ } else if ( match(block, "^((\\|)?([^\n]+\\|)+[^\n]+(\\|)?)\n" \
+ "((\\|)?(:?-+:?[\\|+])+:?-+:?(\\|)?)\n" \
+ "((\\|)?([^\n]+\\|)+[^\n]+(\\|)?(\n|$))+" ) ) {
+ len = RLENGTH; st = RSTART;
+ #initialize empty arrays
+ split("", talign); split("", tarray);
+ cols = 0; cnt=0; ttext = "";
- while ( match(block, "^((\\|)?([^\n]+\\|)+[^\n]+(\\|)?(\n|$))+" ) ){
+ # table header and alignment
tmp = substr(block, 1, match(block, /(\n|$)/));
gsub( /(^|[^\\])\\\|/, "\\1\\|", tmp );
- gsub( /(^\||\|$)/, "", tmp );
+ gsub( /(^\||\|$)/, "", tmp)
split( tmp, tarray, /\|/);
block = substr(block, match(block, /(\n|$)/) + 1 );
+ tmp = substr(block, 1, match(block, /(\n|$)/));
+ gsub( /(^\||\|$)/, "", tmp );
+ cols = split( tmp , talign, /[+\|]/);
+ block = substr(block, match(block, /(\n|$)/) + 1 );
+
+ for( cnt = 1; cnt < cols; cnt++ ) {
+ if (match(talign[cnt], /:-+:/)) talign[cnt]="center";
+ else if (match(talign[cnt], /-+:/)) talign[cnt]="right";
+ else if (match(talign[cnt], /:-+/)) talign[cnt]="left";
+ else talign[cnt]="";
+ }
- ttext = ttext "<tr>"
+ ttext = "<thead>\n<tr>"
for (cnt = 1; cnt < cols; cnt++)
- ttext = ttext "<td align=\"" talign[cnt] "\">" inline(tarray[cnt]) "</td>"
- ttext = ttext "</tr>\n"
- }
- return "<table>" ttext "</tbody></table>\n" _block(block);
-
- # Grid Tables (pandoc)
- # (with, and without header)
- } else if ( match( block, "^\\+(-+\\+)+\n" \
- "(\\|([^\n]+\\|)+\n)+" \
- "(\\+(:?=+:?\\+)+)\n" \
- "((\\|([^\n]+\\|)+\n)+" \
- "\\+(-+\\+)+(\n|$))+" \
- ) || \
- match( block, "^()()()" \
- "(\\+(:?-+:?\\+)+)\n" \
- "((\\|([^\n]+\\|)+\n)+" \
- "\\+(-+\\+)+(\n|$))+" \
- ) ) {
- len = RLENGTH; st = RSTART;
- #initialize empty arrays
- split("", talign); split("", tarray); split("", tread);
- cols = 0; cnt=0; ttext = "";
-
- # Column Count
- tmp = block; sub( "(\n.*)*$", "", tmp);
- cols = split( tmp, tread, /\+/) - 2;
- # debug(" Cols: " gensub( "^(\\+(:?-+:?\\+)+)(\n.*)*$", "\\1", 1, block ));
-
- # table alignment
- match(block, "((:?=+:?\\+|(:-+|-+:|:-+:)\\+)+)");
- split( substr(block, RSTART, RLENGTH) , talign, /\+/ );
- # split( gensub( "^(.*\n)?\\+((:?=+:?\\+|(:-+|-+:|:-+:)\\+)+)(\n.*)$", "\\2", "g", block ), talign, /\+/ );
- # debug("Align: " gensub( "^(.*\n)?\\+((:?=+:?\\+|(:-+|-+:|:-+:)\\+)+)(\n.*)$", "\\2", "g", block ));
-
- for (cnt = 1; cnt <= cols; cnt++) {
- if (match(talign[cnt], /:(-+|=+):/)) talign[cnt]="center";
- else if (match(talign[cnt], /(-+|=+):/)) talign[cnt]="right";
- else if (match(talign[cnt], /:(-+|=+)/ )) talign[cnt]="left";
- else talign[cnt]="";
- }
+ ttext = ttext "<th align=\"" talign[cnt] "\">" inline(tarray[cnt]) "</th>"
+ ttext = ttext "</tr>\n</thead><tbody>\n"
- if ( match(block, "^\\+(-+\\+)+\n" \
- "(\\|([^\n]+\\|)+\n)+" \
- "\\+(:?=+:?\\+)+\n" \
- "((\\|([^\n]+\\|)+\n)+" \
- "\\+(-+\\+)+(\n|$))+" \
- ) ) {
- # table header
- block = substr(block, match(block, /(\n|$)/) + 1 );
- while ( match(block, "^\\|([^\n]+\\|)+\n") ) {
+ while ( match(block, "^((\\|)?([^\n]+\\|)+[^\n]+(\\|)?(\n|$))+" ) ){
tmp = substr(block, 1, match(block, /(\n|$)/));
- gsub( /\\\\/, "\\\", tmp); gsub(/\\\|/, "\\|", tmp);
+ gsub( /(^|[^\\])\\\|/, "\\1\\|", tmp );
gsub( /(^\||\|$)/, "", tmp );
- split(tmp, tread, /\|/);
+ split( tmp, tarray, /\|/);
block = substr(block, match(block, /(\n|$)/) + 1 );
- for (cnt = 1; cnt <= cols; cnt++)
- tarray[cnt] = tarray[cnt] "\n" tread[cnt];
- }
- ttext = "<thead>\n<tr>"
- for (cnt = 1; cnt <= cols; cnt++)
- ttext = ttext "<th align=\"" talign[cnt] "\">" _nblock(tarray[cnt]) "</th>"
- ttext = ttext "</tr>\n</thead>"
- }
+ ttext = ttext "<tr>"
+ for (cnt = 1; cnt < cols; cnt++)
+ ttext = ttext "<td align=\"" talign[cnt] "\">" inline(tarray[cnt]) "</td>"
+ ttext = ttext "</tr>\n"
+ }
+ ret = ret "<table>" ttext "</tbody></table>\n";
+ continue;
- # table body
- block = substr(block, match(block, /(\n|$)/) + 1 );
- ttext = ttext "<tbody>\n"
+ # Grid Tables (pandoc)
+ # (with, and without header)
+ } else if ( match( block, "^\\+(-+\\+)+\n" \
+ "(\\|([^\n]+\\|)+\n)+" \
+ "(\\+(:?=+:?\\+)+)\n" \
+ "((\\|([^\n]+\\|)+\n)+" \
+ "\\+(-+\\+)+(\n|$))+" \
+ ) || \
+ match( block, "^()()()" \
+ "(\\+(:?-+:?\\+)+)\n" \
+ "((\\|([^\n]+\\|)+\n)+" \
+ "\\+(-+\\+)+(\n|$))+" \
+ ) ) {
+ len = RLENGTH; st = RSTART;
+ #initialize empty arrays
+ split("", talign); split("", tarray); split("", tread);
+ cols = 0; cnt=0; ttext = "";
+
+ # Column Count
+ tmp = block; sub( "(\n.*)*$", "", tmp);
+ cols = split( tmp, tread, /\+/) - 2;
+ # debug(" Cols: " gensub( "^(\\+(:?-+:?\\+)+)(\n.*)*$", "\\1", 1, block ));
+
+ # table alignment
+ match(block, "((:?=+:?\\+|(:-+|-+:|:-+:)\\+)+)");
+ split( substr(block, RSTART, RLENGTH) , talign, /\+/ );
+ # split( gensub( "^(.*\n)?\\+((:?=+:?\\+|(:-+|-+:|:-+:)\\+)+)(\n.*)$", "\\2", "g", block ), talign, /\+/ );
+ # debug("Align: " gensub( "^(.*\n)?\\+((:?=+:?\\+|(:-+|-+:|:-+:)\\+)+)(\n.*)$", "\\2", "g", block ));
+
+ for (cnt = 1; cnt <= cols; cnt++) {
+ if (match(talign[cnt], /:(-+|=+):/)) talign[cnt]="center";
+ else if (match(talign[cnt], /(-+|=+):/)) talign[cnt]="right";
+ else if (match(talign[cnt], /:(-+|=+)/ )) talign[cnt]="left";
+ else talign[cnt]="";
+ }
- while ( match(block, /^((\|([^\n]+\|)+\n)+\+(-+\+)+(\n|$))+/ ) ){
- split("", tarray);
- while ( match(block, /^\|([^\n]+\|)+\n/) ) {
- tmp = substr(block, 1, match(block, /(\n|$)/));
- gsub( /\\\\/, "\\\", tmp); gsub(/\\\|/, "\\|", tmp);
- gsub( /(^\||\|$)/, "", tmp);
- split( tmp, tread, /\|/);
+ if ( match(block, "^\\+(-+\\+)+\n" \
+ "(\\|([^\n]+\\|)+\n)+" \
+ "\\+(:?=+:?\\+)+\n" \
+ "((\\|([^\n]+\\|)+\n)+" \
+ "\\+(-+\\+)+(\n|$))+" \
+ ) ) {
+ # table header
block = substr(block, match(block, /(\n|$)/) + 1 );
+ while ( match(block, "^\\|([^\n]+\\|)+\n") ) {
+ tmp = substr(block, 1, match(block, /(\n|$)/));
+ gsub( /\\\\/, "\\\", tmp); gsub(/\\\|/, "\\|", tmp);
+ gsub( /(^\||\|$)/, "", tmp );
+ split(tmp, tread, /\|/);
+ block = substr(block, match(block, /(\n|$)/) + 1 );
+ for (cnt = 1; cnt <= cols; cnt++)
+ tarray[cnt] = tarray[cnt] "\n" tread[cnt];
+ }
+
+ ttext = "<thead>\n<tr>"
for (cnt = 1; cnt <= cols; cnt++)
- tarray[cnt] = tarray[cnt] "\n" tread[cnt];
+ ttext = ttext "<th align=\"" talign[cnt] "\">" _nblock(tarray[cnt]) "</th>"
+ ttext = ttext "</tr>\n</thead>"
}
+
+ # table body
block = substr(block, match(block, /(\n|$)/) + 1 );
+ ttext = ttext "<tbody>\n"
+
+ while ( match(block, /^((\|([^\n]+\|)+\n)+\+(-+\+)+(\n|$))+/ ) ){
+ split("", tarray);
+ while ( match(block, /^\|([^\n]+\|)+\n/) ) {
+ tmp = substr(block, 1, match(block, /(\n|$)/));
+ gsub( /\\\\/, "\\\", tmp); gsub(/\\\|/, "\\|", tmp);
+ gsub( /(^\||\|$)/, "", tmp);
+ split( tmp, tread, /\|/);
+ block = substr(block, match(block, /(\n|$)/) + 1 );
+ for (cnt = 1; cnt <= cols; cnt++)
+ tarray[cnt] = tarray[cnt] "\n" tread[cnt];
+ }
+ block = substr(block, match(block, /(\n|$)/) + 1 );
- ttext = ttext "<tr>"
- for (cnt = 1; cnt <= cols; cnt++)
- ttext = ttext "<td align=\"" talign[cnt] "\">" _nblock(tarray[cnt]) "</td>"
- ttext = ttext "</tr>\n"
- }
- return "<table>" ttext "</tbody></table>\n" _nblock(block);
-
- # Line Blocks (pandoc)
- } else if ( match(block, /^\| [^\n]*(\n|$)(\| [^\n]*(\n|$)|[ \t]+[^\n[:space:]][^\n]*(\n|$))*/) ) {
- len = RLENGTH; st = RSTART;
-
- text = substr(block, 1, len); gsub(/\n[[:space:]]+/, " ", text);
- gsub(/\n\| /, "\n", text); gsub(/^\| |\n$/, "", text);
- text = inline(text); gsub(/\n/, "<br>\n", text);
-
- return "<div class=\"line-block\">" text "</div>\n" _block( substr( block, len + 1) );
-
- # Indented Code Block
- } else if ( match(block, /^(( |\t)[^\n]*[^\n\t ][^\n]*(\n|$))(( |\t)[^\n]*(\n|$)|[\t ]*(\n|$))*/) ) {
- len = RLENGTH; st = RSTART;
-
- code = substr(block, 1, len);
- gsub(/(^|\n)( |\t)/, "\n", code);
- gsub(/^\n|\n+$/, "", code);
- return "<pre><code>" HTML( code ) "</code></pre>\n" \
- _block( substr( block, len + 1 ) );
-
- # Fenced Divs (pandoc, custom)
- } else if ( match( block, /^(:::+)/ ) ) {
- guard = substr( block, 1, RLENGTH ); attrib = code = block;
- sub(/^[^\n]+\n/, "", code);
- sub(/^:::+[ \t]*\{?[ \t]*/, "", attrib); sub(/\}?[ \t]*\n.*$/, "", attrib);
- # attrib = gensub(/^:::+[ \t]*\{?[ \t]*([^\}\n]*)\}?[ \t]*\n.*$/, "\\1", 1, attrib);
- gsub(/[^a-zA-Z0-9_-]+/, " ", attrib);
- gsub(/(^ | $)/, "", attrib);
- if ( match(code, "(^|\n)" guard "+(\n|$)" ) && attrib ) {
- len = RLENGTH; st = RSTART;
- return "<div class=\"" attrib "\">" _nblock( substr(code, 1, st - 1) ) "</div>\n" \
- _block( substr( code, st + len ) );
- } else if ( match(code, "(^|\n)" guard "+(\n|$)" ) ) {
- len = RLENGTH; st = RSTART;
- return "<div>" _nblock( substr(code, 1, st - 1) ) "</div>\n" \
- _block( substr( code, st + len ) );
- } 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) );
- }
+ ttext = ttext "<tr>"
+ for (cnt = 1; cnt <= cols; cnt++)
+ ttext = ttext "<td align=\"" talign[cnt] "\">" _nblock(tarray[cnt]) "</td>"
+ ttext = ttext "</tr>\n"
+ }
+ return ret "<table>" ttext "</tbody></table>\n" _nblock(block);
- # Fenced Code Block (pandoc)
- } else if ( match( block, /^(~~~+|```+)/ ) ) {
- guard = substr( block, 1, RLENGTH ); attrib = code = block;
- sub(/^[^\n]+\n/, "", code);
- sub(/^(~~~+|```+)[ \t]*\{?[ \t]*/, "", attrib); sub(/\}?[ \t]*\n.*$/, "", attrib);
- # attrib = gensub(/^(~~~+|```+)[ \t]*\{?[ \t]*([^\}\n]*)\}?[ \t]*\n.*$/, "\\2", 1, attrib);
- gsub(/[^a-zA-Z0-9_-]+/, " ", attrib);
- gsub(/(^ | $)/, "", attrib);
- if ( match(code, "(^|\n)" guard "+(\n|$)" ) && attrib ) {
+ # Line Blocks (pandoc)
+ } else if ( match(block, /^\| [^\n]*(\n|$)(\| [^\n]*(\n|$)|[ \t]+[^\n[:space:]][^\n]*(\n|$))*/) ) {
len = RLENGTH; st = RSTART;
- return "<pre><code class=\"" attrib "\">" HTML( substr(code, 1, st - 1) ) "</code></pre>\n" \
- _block( substr( code, st + len ) );
- } else if ( match(code, "(^|\n)" guard "+(\n|$)" ) ) {
- len = RLENGTH; st = RSTART;
- return "<pre><code>" HTML( substr(code, 1, st - 1) ) "</code></pre>\n" \
- _block( substr( code, st + len ) );
- } else {
- match( block, /(^|\n)[[:space:]]*(\n|$)/ ) || match( block, /$/ );
+
+ text = substr(block, 1, len); gsub(/\n[[:space:]]+/, " ", text);
+ gsub(/\n\| /, "\n", text); gsub(/^\| |\n$/, "", text);
+ text = inline(text); gsub(/\n/, "<br>\n", text);
+
+ ret = ret "<div class=\"line-block\">" text "</div>\n"; block = substr( block, len + 1);
+ continue;
+
+ # Indented Code Block
+ } else if ( match(block, /^(( |\t)[^\n]*[^\n\t ][^\n]*(\n|$))(( |\t)[^\n]*(\n|$)|[\t ]*(\n|$))*/) ) {
len = RLENGTH; st = RSTART;
- return "<p>" inline( substr(block, 1, st - 1) ) "</p>\n" \
- _block( substr(block, st + len) );
- }
- # First Order Heading H1 + Attrib
- } else if ( match( block, /^([^\n]+)([ \t]*\{([^\}\n]+)\})\n===+(\n|$)/ ) ) {
- len = RLENGTH; text = attrib = block;
- sub(/([ \t]*\{([^\}\n]+)\})\n===+(\n.*)?$/, "", text);
- sub(/\}\n===+(\n.*)?$/, "", attrib); sub(/^([^\n]+)[ \t]*\{/, "", attrib);
- gsub(/[^a-zA-Z0-9_-]+/, " ", attrib); gsub(/(^ | $)/, "", attrib);
+ code = substr(block, 1, len);
+ gsub(/(^|\n)( |\t)/, "\n", code);
+ gsub(/^\n|\n+$/, "", code);
+ ret = ret "<pre><code>" HTML( code ) "</code></pre>\n"; block = substr( block, len + 1 );
+ continue;
- return headline(1, text, attrib) _block( substr( block, len + 1 ) );
+ # Fenced Divs (pandoc, custom)
+ } else if ( match( block, /^(:::+)/ ) ) {
+ guard = substr( block, 1, RLENGTH ); attrib = code = block;
+ sub(/^[^\n]+\n/, "", code);
+ sub(/^:::+[ \t]*\{?[ \t]*/, "", attrib); sub(/\}?[ \t]*\n.*$/, "", attrib);
+ # attrib = gensub(/^:::+[ \t]*\{?[ \t]*([^\}\n]*)\}?[ \t]*\n.*$/, "\\1", 1, attrib);
+ gsub(/[^a-zA-Z0-9_-]+/, " ", attrib);
+ gsub(/(^ | $)/, "", attrib);
+ if ( match(code, "(^|\n)" guard "+(\n|$)" ) && attrib ) {
+ len = RLENGTH; st = RSTART;
+ ret = ret "<div class=\"" attrib "\">" _nblock( substr(code, 1, st - 1) ) "</div>\n";
+ block = substr( code, st + len );
+ continue;
- # First Order Heading H1
- } else if ( match( block, /^([^\n]+)\n===+(\n|$)/ ) ) {
- len = RLENGTH; text = substr(block, 1, len);
- sub(/\n===+(\n.*)?$/, "", text);
+ } else if ( match(code, "(^|\n)" guard "+(\n|$)" ) ) {
+ len = RLENGTH; st = RSTART;
+ ret = ret "<div>" _nblock( substr(code, 1, st - 1) ) "</div>\n"; block = substr( code, st + len );
+ continue;
+
+ } else {
+ match( block, /(^|\n)[[:space:]]*(\n|$)/ ) || match( block, /$/ );
+ len = RLENGTH; st = RSTART;
+ ret = ret "<p>" inline( substr(block, 1, st - 1) ) "</p>\n"; block = substr(block, st + len);
+ continue;
+ }
- return headline(1, text, 0) _block( substr( block, len + 1 ) );
+ # Fenced Code Block (pandoc)
+ } else if ( match( block, /^(~~~+|```+)/ ) ) {
+ guard = substr( block, 1, RLENGTH ); attrib = code = block;
+ sub(/^[^\n]+\n/, "", code);
+ sub(/^(~~~+|```+)[ \t]*\{?[ \t]*/, "", attrib); sub(/\}?[ \t]*\n.*$/, "", attrib);
+ # attrib = gensub(/^(~~~+|```+)[ \t]*\{?[ \t]*([^\}\n]*)\}?[ \t]*\n.*$/, "\\2", 1, attrib);
+ gsub(/[^a-zA-Z0-9_-]+/, " ", attrib);
+ gsub(/(^ | $)/, "", attrib);
+ if ( match(code, "(^|\n)" guard "+(\n|$)" ) && attrib ) {
+ len = RLENGTH; st = RSTART;
+ ret = ret "<pre><code class=\"" attrib "\">" HTML( substr(code, 1, st - 1) ) "</code></pre>\n";
+ block = substr( code, st + len );
+ continue;
- # Second Order Heading H2 + Attrib
- } else if ( match( block, /^([^\n]+)([ \t]*\{([^\}\n]+)\})\n---+(\n|$)/ ) ) {
- len = RLENGTH; text = attrib = block;
- sub(/([ \t]*\{([^\}\n]+)\})\n---+(\n.*)?$/, "", text);
- sub(/\}\n---+(\n.*)?$/, "", attrib); sub(/^([^\n]+)[ \t]*\{/, "", attrib);
- gsub(/[^a-zA-Z0-9_-]+/, " ", attrib); gsub(/(^ | $)/, "", attrib);
+ } else if ( match(code, "(^|\n)" guard "+(\n|$)" ) ) {
+ len = RLENGTH; st = RSTART;
+ ret = ret "<pre><code>" HTML( substr(code, 1, st - 1) ) "</code></pre>\n";
+ block = substr( code, st + len );
+ continue;
- return headline(2, text, attrib) _block( substr( block, len + 1) );
+ } else {
+ match( block, /(^|\n)[[:space:]]*(\n|$)/ ) || match( block, /$/ );
+ len = RLENGTH; st = RSTART;
+ ret = ret "<p>" inline( substr(block, 1, st - 1) ) "</p>\n"; block = substr(block, st + len);
+ continue;
+ }
- # Second Order Heading H2
- } else if ( match( block, /^([^\n]+)\n---+(\n|$)/ ) ) {
- len = RLENGTH; text = substr(block, 1, len);
- sub(/\n---+(\n.*)?$/, "", text);
+ # First Order Heading H1 + Attrib
+ } else if ( match( block, /^([^\n]+)([ \t]*\{([^\}\n]+)\})\n===+(\n|$)/ ) ) {
+ len = RLENGTH; text = attrib = block;
+ sub(/([ \t]*\{([^\}\n]+)\})\n===+(\n.*)?$/, "", text);
+ sub(/\}\n===+(\n.*)?$/, "", attrib); sub(/^([^\n]+)[ \t]*\{/, "", attrib);
+ gsub(/[^a-zA-Z0-9_-]+/, " ", attrib); gsub(/(^ | $)/, "", attrib);
- return headline(2, text, 0) _block( substr( block, len + 1) );
+ ret = ret headline(1, text, attrib) ; block = substr( block, len + 1 );
+ continue;
- # Nth Order Heading H1 H2 H3 H4 H5 H6 + Attrib
- } else if ( match( block, /^(##?#?#?#?#?)[ \t]*(([^ \t\n]+|[ \t]+[^ \t\n#]|[ \t]+#+[ \t]*[^ \t\n#])+)[ \t]*#*([ \t]*\{([a-zA-Z \t-]*)\})(\n|$)/ ) ) {
- len = RLENGTH; text = attrib = substr(block, 1, len);
- match(block, /^##?#?#?#?#?[^#]/); n = RLENGTH - 1;
+ # First Order Heading H1
+ } else if ( match( block, /^([^\n]+)\n===+(\n|$)/ ) ) {
+ len = RLENGTH; text = substr(block, 1, len);
+ sub(/\n===+(\n.*)?$/, "", text);
- # sub(/^(##?#?#?#?#?)[ \t]*/, "", text); # not working in mawk
- text = substr(text, n + 1); sub(/^[ \t]*/, "", text);
- sub(/[ \t]*#*([ \t]*\{([a-zA-Z \t-]*)\})(\n.*)?$/, "", text);
- sub(/^(##?#?#?#?#?)[ \t]*(([^ \t\n]+|[ \t]+[^ \t\n#]|[ \t]+#+[ \t]*[^ \t\n#])+)[ \t]*#*[ \t]*\{/, "", attrib);
- sub(/\}(\n.*)?$/, "", attrib);
- gsub(/[^a-zA-Z0-9_-]+/, " ", attrib); gsub(/(^ | $)/, "", attrib);
+ ret = ret headline(1, text, 0) ; block = substr( block, len + 1 );
+ continue;
- return headline( n, text, attrib ) _block( substr( block, len + 1) );
+ # Second Order Heading H2 + Attrib
+ } else if ( match( block, /^([^\n]+)([ \t]*\{([^\}\n]+)\})\n---+(\n|$)/ ) ) {
+ len = RLENGTH; text = attrib = block;
+ sub(/([ \t]*\{([^\}\n]+)\})\n---+(\n.*)?$/, "", text);
+ sub(/\}\n---+(\n.*)?$/, "", attrib); sub(/^([^\n]+)[ \t]*\{/, "", attrib);
+ gsub(/[^a-zA-Z0-9_-]+/, " ", attrib); gsub(/(^ | $)/, "", attrib);
- # Nth Order Heading H1 H2 H3 H4 H5 H6
- } else if ( match( block, /^(##?#?#?#?#?)[ \t]*(([^ \t\n]+|[ \t]+[^ \t\n#]|[ \t]+#+[ \t]*[^ \t\n#])+)[ \t]*#*(\n|$)/ ) ) {
- len = RLENGTH; text = substr(block, 1, len);
- match(block, /^##?#?#?#?#?[^#]/); n = RLENGTH - 1;
- # sub(/^(##?#?#?#?#?)[ \t]+/, "", text); # not working in mawk
- text = substr(text, n + 1); sub(/^[ \t]*/, "", text);
- sub(/[ \t]*#*(\n.*)?$/, "", text);
-
- return headline( n, text, 0 ) _block( substr( block, len + 1) );
-
- # block images (wrapped in <figure>)
- } else if ( match(block, "^!" lix "\\([\n\t ]*" lid "([\n\t ]+" lit ")?[\n\t ]*\\)(\\{[a-zA-Z \t-]*\\})?(\n|$)") ) {
- len = RLENGTH; text = href = title = attrib = substr( block, 1, len);
-
- sub("^!\\[", "", text);
- sub("\\]\\([\n\t ]*" lid "([\n\t ]+" lit ")?[\n\t ]*\\)(\\{[a-zA-Z \t-]*\\})?(\n.*)?$", "", text);
-
- sub("^!" lix "\\([\n\t ]*", "", href);
- sub("([\n\t ]+" lit ")?[\n\t ]*\\)(\\{[a-zA-Z \t-]*\\})?(\n.*)?$", "", href);
-
- sub("^!" lix "\\([\n\t ]*" lid, "", title);
- sub("[\n\t ]*\\)(\\{[a-zA-Z \t-]*\\})?(\n.*)?$", "", title);
- sub("^[\n\t ]+", "", title);
-
- sub("^!" lix "\\([\n\t ]*" lid "([\n\t ]+" lit ")?[\n\t ]*\\)", "", attrib);
- sub("(\n.*)?$", "", attrib);
- sub(/^\{[ \t]*/, "", attrib); sub(/[ \t]*\}$/, "", attrib); gsub(/[ \t]+/, " ", attrib);
-
- if ( match(href, /^<.*>$/) ) { sub(/^</, "", href); sub(/>$/, "", href); }
- if ( match(title, /^".*"$/) ) { sub(/^"/, "", title); sub(/"$/, "", title); }
- else if ( match(title, /^'.*'$/) ) { sub(/^'/, "", title); sub(/'$/, "", title); }
- else if ( match(title, /^\(.*\)$/) ) { sub(/^\(/, "", title); sub(/\)$/, "", title); }
-
- gsub(/^[\t ]+$/, "", text); gsub(/\\/, "", href);
-
- return "<figure data-src=\"" HTML(href) "\"" (attrib?" class=\"" HTML(attrib) "\"":"") ">" \
- "<img src=\"" HTML(href) "\" alt=\"" HTML(text?text:title?title:href) "\"" \
- (attrib?" class=\"" HTML(attrib) "\"":"") ">" \
- (title?"<figcaption>" inline(title) "</figcaption>":"") \
- "</figure>\n\n" \
- _block( substr( block, len + 1) );
-
- } else if ( match(block, /^!\[([^]]*)\] ?\[([^]]*)\](\n|$)/ ) ) {
- len = RLENGTH; text = id = block;
- sub(/(\n.*)?$/, "", text); sub( /^!\[/, "", text); sub(/\] ?\[([^\n]*)\]$/, "", text);
- sub(/(\n.*)?$/, "", id); sub( /^!\[([^\n]*)\] ?\[/, "", id); sub(/\]$/, "", id);
- # text = gensub(/^!\[([^\n]*)\] ?\[([^\n]*)\](\n.*)?$/, "\\1", 1, block);
- # id = gensub(/^!\[([^\n]*)\] ?\[([^\n]*)\](\n.*)?$/, "\\2", 1, block);
- if ( ! id ) id = text;
- if ( rl_href[id] && rl_title[id] ) {
- return "<figure data-src=\"" HTML(rl_href[id]) "\">" \
- "<img src=\"" HTML(rl_href[id]) "\" alt=\"" HTML(text) "\">" \
- "<figcaption>" inline(rl_title[id]) "</figcaption>" \
- "</figure>\n\n" \
- _block( substr( block, len + 1) );
- } else if ( rl_href[id] ) {
- return "<figure data-src=\"" HTML(rl_href[id]) "\">" \
- "<img src=\"" HTML(rl_href[id]) "\" alt=\"" HTML(text) "\">" \
- "</figure>\n\n" \
- _block( substr( block, len + 1) );
+ ret = ret headline(2, text, attrib) ; block = substr( block, len + 1);
+ continue;
+
+ # Second Order Heading H2
+ } else if ( match( block, /^([^\n]+)\n---+(\n|$)/ ) ) {
+ len = RLENGTH; text = substr(block, 1, len);
+ sub(/\n---+(\n.*)?$/, "", text);
+
+ ret = ret headline(2, text, 0) ; block = substr( block, len + 1);
+ continue;
+
+ # Nth Order Heading H1 H2 H3 H4 H5 H6 + Attrib
+ } else if ( match( block, /^(##?#?#?#?#?)[ \t]*(([^ \t\n]+|[ \t]+[^ \t\n#]|[ \t]+#+[ \t]*[^ \t\n#])+)[ \t]*#*([ \t]*\{([a-zA-Z \t-]*)\})(\n|$)/ ) ) {
+ len = RLENGTH; text = attrib = substr(block, 1, len);
+ match(block, /^##?#?#?#?#?[^#]/); n = RLENGTH - 1;
+
+ # sub(/^(##?#?#?#?#?)[ \t]*/, "", text); # not working in mawk
+ text = substr(text, n + 1); sub(/^[ \t]*/, "", text);
+ sub(/[ \t]*#*([ \t]*\{([a-zA-Z \t-]*)\})(\n.*)?$/, "", text);
+ sub(/^(##?#?#?#?#?)[ \t]*(([^ \t\n]+|[ \t]+[^ \t\n#]|[ \t]+#+[ \t]*[^ \t\n#])+)[ \t]*#*[ \t]*\{/, "", attrib);
+ sub(/\}(\n.*)?$/, "", attrib);
+ gsub(/[^a-zA-Z0-9_-]+/, " ", attrib); gsub(/(^ | $)/, "", attrib);
+
+ ret = ret headline( n, text, attrib ) ; block = substr( block, len + 1);
+ continue;
+
+ # Nth Order Heading H1 H2 H3 H4 H5 H6
+ } else if ( match( block, /^(##?#?#?#?#?)[ \t]*(([^ \t\n]+|[ \t]+[^ \t\n#]|[ \t]+#+[ \t]*[^ \t\n#])+)[ \t]*#*(\n|$)/ ) ) {
+ len = RLENGTH; text = substr(block, 1, len);
+ match(block, /^##?#?#?#?#?[^#]/); n = RLENGTH - 1;
+ # sub(/^(##?#?#?#?#?)[ \t]+/, "", text); # not working in mawk
+ text = substr(text, n + 1); sub(/^[ \t]*/, "", text);
+ sub(/[ \t]*#*(\n.*)?$/, "", text);
+
+ ret = ret headline( n, text, 0 ) ; block = substr( block, len + 1);
+ continue;
+
+ # block images (wrapped in <figure>)
+ } else if ( match(block, "^!" lix "\\([\n\t ]*" lid "([\n\t ]+" lit ")?[\n\t ]*\\)(\\{[a-zA-Z \t-]*\\})?(\n|$)") ) {
+ len = RLENGTH; text = href = title = attrib = substr( block, 1, len);
+
+ sub("^!\\[", "", text);
+ sub("\\]\\([\n\t ]*" lid "([\n\t ]+" lit ")?[\n\t ]*\\)(\\{[a-zA-Z \t-]*\\})?(\n.*)?$", "", text);
+
+ sub("^!" lix "\\([\n\t ]*", "", href);
+ sub("([\n\t ]+" lit ")?[\n\t ]*\\)(\\{[a-zA-Z \t-]*\\})?(\n.*)?$", "", href);
+
+ sub("^!" lix "\\([\n\t ]*" lid, "", title);
+ sub("[\n\t ]*\\)(\\{[a-zA-Z \t-]*\\})?(\n.*)?$", "", title);
+ sub("^[\n\t ]+", "", title);
+
+ sub("^!" lix "\\([\n\t ]*" lid "([\n\t ]+" lit ")?[\n\t ]*\\)", "", attrib);
+ sub("(\n.*)?$", "", attrib);
+ sub(/^\{[ \t]*/, "", attrib); sub(/[ \t]*\}$/, "", attrib); gsub(/[ \t]+/, " ", attrib);
+
+ if ( match(href, /^<.*>$/) ) { sub(/^</, "", href); sub(/>$/, "", href); }
+ if ( match(title, /^".*"$/) ) { sub(/^"/, "", title); sub(/"$/, "", title); }
+ else if ( match(title, /^'.*'$/) ) { sub(/^'/, "", title); sub(/'$/, "", title); }
+ else if ( match(title, /^\(.*\)$/) ) { sub(/^\(/, "", title); sub(/\)$/, "", title); }
+
+ gsub(/^[\t ]+$/, "", text); gsub(/\\/, "", href);
+
+ ret = ret "<figure data-src=\"" HTML(href) "\"" (attrib?" class=\"" HTML(attrib) "\"":"") ">" \
+ "<img src=\"" HTML(href) "\" alt=\"" HTML(text?text:title?title:href) "\"" \
+ (attrib?" class=\"" HTML(attrib) "\"":"") ">" \
+ (title?"<figcaption>" inline(title) "</figcaption>":"") \
+ "</figure>\n\n";
+ block = substr( block, len + 1);
+ continue;
+
+ } else if ( match(block, /^!\[([^]]*)\] ?\[([^]]*)\](\n|$)/ ) ) {
+ len = RLENGTH; text = id = block;
+ sub(/(\n.*)?$/, "", text); sub( /^!\[/, "", text); sub(/\] ?\[([^\n]*)\]$/, "", text);
+ sub(/(\n.*)?$/, "", id); sub( /^!\[([^\n]*)\] ?\[/, "", id); sub(/\]$/, "", id);
+ # text = gensub(/^!\[([^\n]*)\] ?\[([^\n]*)\](\n.*)?$/, "\\1", 1, block);
+ # id = gensub(/^!\[([^\n]*)\] ?\[([^\n]*)\](\n.*)?$/, "\\2", 1, block);
+ if ( ! id ) id = text;
+ if ( rl_href[id] && rl_title[id] ) {
+ ret = ret "<figure data-src=\"" HTML(rl_href[id]) "\">" \
+ "<img src=\"" HTML(rl_href[id]) "\" alt=\"" HTML(text) "\">" \
+ "<figcaption>" inline(rl_title[id]) "</figcaption>" \
+ "</figure>\n\n";
+ block = substr( block, len + 1);
+ continue;
+
+ } else if ( rl_href[id] ) {
+ ret = ret "<figure data-src=\"" HTML(rl_href[id]) "\">" \
+ "<img src=\"" HTML(rl_href[id]) "\" alt=\"" HTML(text) "\">" \
+ "</figure>\n\n";
+ block = substr( block, len + 1);
+ continue;
+ } else {
+ ret = ret "<p>" HTML(substr(block, 1, len)) "</p>\n" ; block = substr(block, len + 1);
+ continue;
+ }
+
+ # Macros (standalone <<macro>> calls handled as block, so they are not wrapped in paragraph)
+ } else if ( match( block, /^<<(([^>]|>[^>])+)>>(\n|$)/ ) ) {
+ len = RLENGTH; text = block;
+ sub(/^<</, "", text); sub(/>>(\n.*)?$/, "", text);
+ # text = gensub(/^<<(([^>]|>[^>])+)>>(\n.*)?$/, "\\1", 1, block);
+ ret = ret "<code class=\"macro\">" HTML(text) "</code>" ; block = substr(block, len + 1);
+ continue;
+
+ # 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);
+ ret = ret "<dl>\n" _dlist( list ) "</dl>\n";
+ continue;
+
+ # Unordered list types
+ } else if ( text = _startlist( block, "ul", "-", "([+*•]|[0-9]+\\.|#\\.|[0-9]+\\)|#\\))") ) {
+ return ret text;
+ } else if ( text = _startlist( block, "ul", "\\+", "([-*•]|[0-9]+\\.|#\\.|[0-9]+\\)|#\\))") ) {
+ return ret text;
+ } else if ( text = _startlist( block, "ul", "\\*", "([-+•]|[0-9]+\\.|#\\.|[0-9]+\\)|#\\))") ) {
+ return ret text;
+ } else if ( text = _startlist( block, "ul", "•", "([-+*]|[0-9]+\\.|#\\.|[0-9]+\\)|#\\))") ) {
+ return ret text;
+
+ # Ordered list types
+ } else if ( text = _startlist( block, "ol", "[0-9]+\\.", "([-+*•]|#\\.|[0-9]+\\)|#\\))") ) {
+ return ret text;
+ } else if ( text = _startlist( block, "ol", "[0-9]+\\)", "([-+*•]|[0-9]+\\.|#\\.|#\\))") ) {
+ return ret text;
+ } else if ( text = _startlist( block, "ol", "#\\.", "([-+*•]|[0-9]+\\.|[0-9]+\\)|#\\))") ) {
+ return ret text;
+ } else if ( text = _startlist( block, "ol", "#\\)", "([-+*•]|[0-9]+\\.|#\\.|[0-9]+\\))") ) {
+ return ret text;
+
+ # Split paragraphs
+ } else if ( match( block, /(^|\n)[[:space:]]*(\n|$)/) ) {
+ len = RLENGTH; st = RSTART;
+ ret = ret _block( substr(block, 1, st - 1) ) "\n"; block = substr(block, st + len);
+ continue;
+
+ # Horizontal rule
+ # } else if ( match( block, /(^|\n) ? ? ?((\* *){3,}|(- *){3,}|(_ *){3,})($|\n)/) ) {
+ } else if ( match( block, /(^|\n) ? ? ?((\* *)(\* *)(\* *)(\* *)*|(- *)(- *)(- *)(- *)*|(_ *)(_ *)(_ *)(_ *)*)($|\n)/) ) {
+ len = RLENGTH; st = RSTART;
+ ret = ret _block(substr(block, 1, st - 1)) "<hr>\n"; block = substr(block, st + len);
+ continue;
+
+ # Plain paragraph
} else {
- return "<p>" HTML(substr(block, 1, len)) "</p>\n" _block( substr(block, len + 1) );
+ return ret "<p>" inline(block) "</p>\n";
}
-
- # Macros (standalone <<macro>> calls handled as block, so they are not wrapped in paragraph)
- } else if ( match( block, /^<<(([^>]|>[^>])+)>>(\n|$)/ ) ) {
- len = RLENGTH; text = block;
- sub(/^<</, "", text); sub(/>>(\n.*)?$/, "", text);
- # text = gensub(/^<<(([^>]|>[^>])+)>>(\n.*)?$/, "\\1", 1, block);
- return "<code class=\"macro\">" HTML(text) "</code>" _block(substr(block, len + 1) );
-
- # 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 "<dl>\n" _dlist( list ) "</dl>\n" _block( block );
-
- # Unordered list types
- } else if ( text = _startlist( block, "ul", "-", "([+*•]|[0-9]+\\.|#\\.|[0-9]+\\)|#\\))") ) {
- return text;
- } else if ( text = _startlist( block, "ul", "\\+", "([-*•]|[0-9]+\\.|#\\.|[0-9]+\\)|#\\))") ) {
- return text;
- } else if ( text = _startlist( block, "ul", "\\*", "([-+•]|[0-9]+\\.|#\\.|[0-9]+\\)|#\\))") ) {
- return text;
- } else if ( text = _startlist( block, "ul", "•", "([-+*]|[0-9]+\\.|#\\.|[0-9]+\\)|#\\))") ) {
- return text;
-
- # Ordered list types
- } else if ( text = _startlist( block, "ol", "[0-9]+\\.", "([-+*•]|#\\.|[0-9]+\\)|#\\))") ) {
- return text;
- } else if ( text = _startlist( block, "ol", "[0-9]+\\)", "([-+*•]|[0-9]+\\.|#\\.|#\\))") ) {
- return text;
- } else if ( text = _startlist( block, "ol", "#\\.", "([-+*•]|[0-9]+\\.|[0-9]+\\)|#\\))") ) {
- return text;
- } else if ( text = _startlist( block, "ol", "#\\)", "([-+*•]|[0-9]+\\.|#\\.|[0-9]+\\))") ) {
- return text;
-
- # 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)/) ) {
- } else if ( match( block, /(^|\n) ? ? ?((\* *)(\* *)(\* *)(\* *)*|(- *)(- *)(- *)(- *)*|(_ *)(_ *)(_ *)(_ *)*)($|\n)/) ) {
- len = RLENGTH; st = RSTART;
- return _block(substr(block, 1, st - 1)) "<hr>\n" _block(substr(block, st + len));
-
- # Plain paragraph
- } else {
- return "<p>" inline(block) "</p>\n";
}
+ return ret;
}
function _startlist(block, type, mark, exclude, LOCAL, st, len, list, indent, it, text) {