Show HN: Mawkdown – (Toy) Markdown Parser in Awk
github.com
github.com
$ echo '# ' | awk 'match($0, /^#+ /, m){print length(m[0])-1}'
1
$ echo '### ' | awk 'match($0, /^#+ /, m){print length(m[0])-1}'
3
You can also use capture groups so that you do not need -1 and remove that substr as well. awk 'match($0, /^(#+) (.+)/, m){l=length(m[1]); print "<h" l ">" m[2] "</h" l ">"}'As you'll read on, you'll certainly find more areas for improvements, because this is pretty much based on an idea I had in the shower and then typed it out in a hour :)
awk 'match($0, /^#+ /){l=RLENGTH-1; print "<h" l ">" substr($0,RLENGTH+1) "</h" l ">"}'
I checked it on https://awk.js.org/ and it did workhttp://code.9front.org/hg/werc/file/2ace198c631b/bin/contrib...