X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;ds=inline;f=cgilite%2Fmarkdown.awk;h=100242cb1ebb9b0e2a706a1025dbc552c51c190b;hb=a88a2e833916c59ea6e99e9588543a58f02b9efe;hp=9955bf4ccd42f2b806538e20bd6b8af8b2e15202;hpb=24bbbd528bd30515e9c53d2223d0f68971b5805d;p=shellwiki
diff --git a/cgilite/markdown.awk b/cgilite/markdown.awk
index 9955bf4..100242c 100755
--- a/cgilite/markdown.awk
+++ b/cgilite/markdown.awk
@@ -48,7 +48,8 @@
# - ? Simple table (pandoc)
# - ? Multiline table (pandoc)
# - [x] Grid table (pandoc)
-# - [x] Pipe table (php md pandoc)
+# - [x] Headerless
+# - [x] Pipe table (php md, pandoc)
# - [x] Line blocks (pandoc)
# - [x] Task lists (pandoc, custom)
# - [ ] Definition lists (php md, pandoc)
@@ -64,7 +65,7 @@
# - [x] ^Superscript^ ~Subscript~ (pandoc)
# - [-] Bracketed spans (pandoc)
# - [-] Inline attributes (pandoc)
-# - [x] Image attributes (custom, pandoc inspired, inline only)
+# - [x] Image attributes (custom, pandoc inspired, not for reference style)
# - [x] Wiki style links [[PageName]] / [[PageName|Link Text]]
# - [-] TEX-Math (pandoc)
# - ? Footnotes (php md)
@@ -393,46 +394,62 @@ function _block( block, LOCAL, st, len, hlvl, htxt, guard, code, indent, attrib
return "
\n" _block(block);
# Grid Tables (pandoc)
- } else if ( match(block, "^\\+(-+\\+)+\n" \
- "(\\|([^\n]+\\|)+\n)+" \
- "\\+(:?=+:?\\+)+\n" \
- "((\\|([^\n]+\\|)+\n)+" \
- "\\+(-+\\+)+(\n|$))+" \
- ) ) {
+ # (with, and without header)
+ } else if ( match( block, "^\\+(-+\\+)+\n" \
+ "(\\|([^\n]+\\|)+\n)+" \
+ "(\\+(:?=+:?\\+)+)\n" \
+ "((\\|([^\n]+\\|)+\n)+" \
+ "\\+(-+\\+)+(\n|$))+", \
+ tread \
+ ) || \
+ match( block, "^()()()" \
+ "(\\+(:?-+:?\\+)+)\n" \
+ "((\\|([^\n]+\\|)+\n)+" \
+ "\\+(-+\\+)+(\n|$))+", \
+ tread \
+ ) ) {
len = RLENGTH; st = RSTART;
#initialize empty arrays
- split("", talign); split("", tarray); split("", tread);
+ split("", talign); split("", tarray); # split("", tread);
cols = 0; cnt=0; ttext = "";
- # table header and alignment
- block = substr(block, match(block, /(\n|$)/) + 1 );
- while ( match(block, "^\\|([^\n]+\\|)+\n") ) {
- cols = split( gensub( /(^\||\|$)/, "", "g", \
- gensub( /(^|[^\\])\\\|/, "\\1\\|", "g", \
- substr(block, 1, match(block, /(\n|$)/)) \
- )), tread, /\|/);
- block = substr(block, match(block, /(\n|$)/) + 1 );
- for (cnt = 1; cnt < cols; cnt++)
- tarray[cnt] = tarray[cnt] "\n" tread[cnt];
+ # table alignment
+ cols = split( gensub( /(^\+|\+$)/, "", "g", tread[4] ), talign, /\+/ );
+
+ 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]="";
}
- cols = split( \
- gensub( /(^\+|\+$)/, "", "g", \
- substr(block, 1, match(block, /(\n|$)/)) \
- ), talign, /\+/);
- block = substr(block, match(block, /(\n|$)/) + 1 );
+ if ( match(block, "^\\+(-+\\+)+\n" \
+ "(\\|([^\n]+\\|)+\n)+" \
+ "\\+(:?=+:?\\+)+\n" \
+ "((\\|([^\n]+\\|)+\n)+" \
+ "\\+(-+\\+)+(\n|$))+" \
+ ) ) {
+ # table header
+ block = substr(block, match(block, /(\n|$)/) + 1 );
+ while ( match(block, "^\\|([^\n]+\\|)+\n") ) {
+ cols = split( gensub( /(^\||\|$)/, "", "g", \
+ gensub( /(^|[^\\])\\\|/, "\\1\\|", "g", \
+ substr(block, 1, match(block, /(\n|$)/)) \
+ )), tread, /\|/);
+ block = substr(block, match(block, /(\n|$)/) + 1 );
+ for (cnt = 1; cnt <= cols; cnt++)
+ tarray[cnt] = tarray[cnt] "\n" tread[cnt];
+ }
- 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 = "\n"
+ for (cnt = 1; cnt <= cols; cnt++)
+ ttext = ttext "" _block(tarray[cnt]) " | "
+ ttext = ttext "
\n"
}
- ttext = "\n"
- for (cnt = 1; cnt < cols; cnt++)
- ttext = ttext "" _block(tarray[cnt]) " | "
- ttext = ttext "
\n\n"
+ # table body
+ block = substr(block, match(block, /(\n|$)/) + 1 );
+ ttext = ttext "\n"
while ( match(block, /^((\|([^\n]+\|)+\n)+\+(-+\+)+(\n|$))+/ ) ){
split("", tarray);
@@ -442,13 +459,13 @@ function _block( block, LOCAL, st, len, hlvl, htxt, guard, code, indent, attrib
substr(block, 1, match(block, /(\n|$)/)) \
)), tread, /\|/);
block = substr(block, match(block, /(\n|$)/) + 1 );
- for (cnt = 1; cnt < cols; cnt++)
+ for (cnt = 1; cnt <= cols; cnt++)
tarray[cnt] = tarray[cnt] "\n" tread[cnt];
}
block = substr(block, match(block, /(\n|$)/) + 1 );
ttext = ttext ""
- for (cnt = 1; cnt < cols; cnt++)
+ for (cnt = 1; cnt <= cols; cnt++)
ttext = ttext "" _block(tarray[cnt]) " | "
ttext = ttext "
\n"
}