nmark - a markdown parser written in Nim


Fast markdown parser, based on CommonMark, written in Nim.



import nmark

let txt = """
> Lorem ipsum dolor
sit amet.
> - Qui *quodsi iracundia*
> - aliquando id

echo txt.markdown

...and it's done.

# output
<p>Lorem ipsum dolor
sit amet.</p>
<li>Qui <em>quodsi iracundia</em></li>
<li>aliquando id</li>

You can use tables in nmark.

| abc | defghi |
:-: | -----------:
bar | baz

is converted to:

<th align="center">abc</th>
<th align="right">defghi</th>
<td align="center">bar</td>
<td align="right">baz</td>

(Tables need to be separated from other blocks by empty line.)

Performance comparison

One of the reason I'm working on this parser is that other markdown parser librarys written in Nim seemed relatively slow. Here is a comparison between nim-markdown, which I think is the standard Nim markdown parser, and nmark, through a static site generator(which, btw, I made) and hyperfine.

./casa build generates 100 same htmls containing a lot of markdown delimiter. For detail please check my repo.

nim-markdown@0.8.5 >>

CommandMean [ms]Min [ms]Max [ms]Relative
./casa build296.1 ± 12.2287.6322.41.00

nmark@0.1.3 >>

CommandMean [ms]Min [ms]Max [ms]Relative
./casa build53.1 ±


This is still work-in-progess project, and does not FULLY pass the spec-test of CommonMark. For example,

> foo

... is, by nmark, converted to:


Though I believe nmark is enough for normal usage, I'm working on improving the accuracy and performance. And issues, pull requests always welcome.