diff --git a/markdown.awk b/markdown.awk index 398a415..293002f 100755 --- a/markdown.awk +++ b/markdown.awk @@ -68,6 +68,11 @@ function lstrip(str) { return str; } +function strip(str) { + gsub(/^ *\n*| *\n*$/, "", str); + return str; +} + function escape_special() { } @@ -429,10 +434,63 @@ function is_metadata(str, i, lines, line) { return 1; } +function col_count(str, i, count) { + count = 0; + for (i=1; i<=length(str); i++) { + if (substr(str, i, 1) == "|") + count++; + } + return count-1; + +} +function is_table(str, i, lines, line) { + split(str, lines, "\n"); + num_cols = col_count(lines[1]); + if (!match(lines[2], /^([[:space:]]*\|[[:space:]]*-{3,}[[:space:]])*\|[[:space:]]*/)) { + return 0; + } + + for (i=2; i<=length(lines); i++) { + line = lines[i]; + + if (col_count(line) != num_cols) + return 0; + } + + return 1; +} + +function parse_table(str, num_cols, lines, line, cols, i, j) { + split(str, lines, "\n"); + num_cols = col_count(lines[1]); + + split(lines[1], cols, "|"); + res="
"strip(cols[i])" | \n"; + } + res = res "
---|
"strip(cols[i])" | \n"; + } + res=res"
this: 1 is: 2 not metadata: 3
EOF +check <<-"EOF" +|foo|bar| +|---|---| +|1 |2 | +--- +foo | +bar | +
---|---|
1 | +2 | +