From 2ea88f760e5b796c42e6cd9c2237fc4b26a26e20 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Mon, 12 Jun 2023 17:02:33 +0200 Subject: [PATCH] Compatibility: Grid Tables section now compatible with posix/busybox awk --- markdown.awk | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/markdown.awk b/markdown.awk index 33c12bd..7d7e0a5 100755 --- a/markdown.awk +++ b/markdown.awk @@ -399,22 +399,25 @@ function _block( block, LOCAL, st, len, hlvl, htxt, guard, code, indent, attrib "(\\|([^\n]+\\|)+\n)+" \ "(\\+(:?=+:?\\+)+)\n" \ "((\\|([^\n]+\\|)+\n)+" \ - "\\+(-+\\+)+(\n|$))+", \ - tread \ + "\\+(-+\\+)+(\n|$))+" \ ) || \ match( block, "^()()()" \ "(\\+(:?-+:?\\+)+)\n" \ "((\\|([^\n]+\\|)+\n)+" \ - "\\+(-+\\+)+(\n|$))+", \ - tread \ + "\\+(-+\\+)+(\n|$))+" \ ) ) { len = RLENGTH; st = RSTART; #initialize empty arrays - split("", talign); split("", tarray); # split("", tread); + split("", talign); split("", tarray); split("", tread); cols = 0; cnt=0; ttext = ""; + # Column Count + cols = split( gensub( "^(\\+(:?-+:?\\+)+)(\n.*)*$", "\\1", 1, block), tread, /\+/) - 2; + # debug(" Cols: " gensub( "^(\\+(:?-+:?\\+)+)(\n.*)*$", "\\1", 1, block )); + # table alignment - cols = split( gensub( /(^\+|\+$)/, "", "g", tread[4] ), 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"; @@ -432,9 +435,9 @@ function _block( block, LOCAL, st, len, hlvl, htxt, guard, code, indent, attrib # 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|$)/)) \ + 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++) -- 2.39.2