X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;ds=inline;f=cgilite%2Fmarkdown.awk;h=33c12bdc9a5be4bcccd3e5bf1b504182291b0c36;hb=1293c214db032ca473b2b2ff54acd8e3f7e83d0a;hp=9955bf4ccd42f2b806538e20bd6b8af8b2e15202;hpb=24bbbd528bd30515e9c53d2223d0f68971b5805d;p=shellwiki
diff --git a/cgilite/markdown.awk b/cgilite/markdown.awk
index 9955bf4..33c12bd 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)
@@ -136,10 +137,10 @@ function inline( line, LOCAL, len, code, href, guard ) {
}
# Wiki style links
- } else if ( match( line, /^\[\[([^\]\|]+)(\|([^\]]+))?\]\]/) ) {
+ } else if ( match( line, /^\[\[([^]|]+)(\|[^]]+)?\]\]/) ) {
len = RLENGTH;
- href = gensub(/^\[\[([^\]\|]+)(\|([^\]]+))?\]\]/, "\\1", 1, substr(line, 1, len) );
- text = gensub(/^\[\[([^\]\|]+)(\|([^\]]+))?\]\]/, "\\3", 1, substr(line, 1, len) );
+ href = gensub(/^\[\[([^]|]+)(\|([^]]+))?\]\]/, "\\1", 1, substr(line, 1, len) );
+ text = gensub(/^\[\[([^]|]+)(\|([^]]+))?\]\]/, "\\3", 1, substr(line, 1, len) );
if ( ! text ) text = href;
return "" HTML(text) "" inline( substr( line, len + 1) );
@@ -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"
}