TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Mawkdown – (Toy) Markdown Parser in Awk

12 pointsby rethabalmost 5 years ago

2 comments

asicspalmost 5 years ago
Nice. Haven&#x27;t gone through it fully, but the header parsing stood out for improvement. Use match to capture number of &#x27;#&#x27; characters and use length, for example:<p><pre><code> $ echo &#x27;# &#x27; | awk &#x27;match($0, &#x2F;^#+ &#x2F;, m){print length(m[0])-1}&#x27; 1 $ echo &#x27;### &#x27; | awk &#x27;match($0, &#x2F;^#+ &#x2F;, m){print length(m[0])-1}&#x27; 3 </code></pre> You can also use capture groups so that you do not need -1 and remove that substr as well.<p><pre><code> awk &#x27;match($0, &#x2F;^(#+) (.+)&#x2F;, m){l=length(m[1]); print &quot;&lt;h&quot; l &quot;&gt;&quot; m[2] &quot;&lt;&#x2F;h&quot; l &quot;&gt;&quot;}&#x27;</code></pre>
评论 #23882065 未加载
khmalmost 5 years ago
Would it be ok to use elements of this to improve the one we ship with Werc?<p><a href="http:&#x2F;&#x2F;code.9front.org&#x2F;hg&#x2F;werc&#x2F;file&#x2F;2ace198c631b&#x2F;bin&#x2F;contrib&#x2F;md2html.awk" rel="nofollow">http:&#x2F;&#x2F;code.9front.org&#x2F;hg&#x2F;werc&#x2F;file&#x2F;2ace198c631b&#x2F;bin&#x2F;contrib...</a>