BT

InfoQ Homepage News Markdown-Wasm, a Very Fast Markdown Parser Written in WebAssembly

Markdown-Wasm, a Very Fast Markdown Parser Written in WebAssembly

Bookmarks

Rasmus Andersson released markdown-wasm, a very fast Markdown parser ported from C to WebAssembly. markdown-wasm is twice as fast as the best JavaScript Markdown parser in one benchmark. markdown-wasm remains additionally small (31KB gzipped).

In a benchmark that runs markdown-wasm and other popular Markdown parsers (e.g. markdown-it, commonmark, marked and showdown) against a series of sample Markdown files that cover the CommonMark specification, markdown-wasm parses the sample files twice as fast as markdown-it, the next fastest contender:

markdown-wasm average operations per seconds
(average operations per seconds. Source: markdown-wasm GitHub)

It seems to do so by being consistently faster than the benchmarked alternatives:

markdown-wasm min-max parse time
(min-max parse time, logarithmic scale. Source: markdown-wasm GitHub)

markdown-wasm leverages MD4C (markdown for C), a Markdown parser written in C that is compliant with the CommonMark specification. markdown-wasm ports MD4C to WebAssembly with the wasmc utility that handles the compiling, linking, and packaging of C and C++ WASM/JS projects. markdown-wasm has no dependencies.

markdown-wasm exposes a single parse API that takes Markdown content (JavaScript string or UTF8 encoded data) and converts it to HTML (returned as a JavaScript string or an Uint8Array). markdown-wasm can be used in Node.js, the browser, or built from source with wasmc.

Computations can be performed faster by doing less work (via more efficient algorithms and data structures), doing work in parallel (leveraging multi-core architectures), or simply doing work faster (e.g., compiling vs. interpreting, AOT vs. JIT compilation). When performance matters, developers often use languages that are designed for efficient compilation and execution of source code across several computation cores (Rust, Go, C, and more). markdown-wasm participates in a growing trend of software that developers write in compile-to-native languages for performance — then eventually port to WebAssembly so the software can run in a variety of target environments and runtimes (e.g., in the browser).

Performance may not however be always all that matters. The markdown-it parser is for instance easy to extend with JavaScript plugins. Such extensibility facilitates community contributions and the growth of an ecosystem of plugins.

Developers can try out markdown-wasm thanks to a dedicated playground. While markdown-wasm should support mathematical notations (e.g. $x_0$), the playground does not. markdown-wasm supports all features specified in the CommonMark Markdown flavor and additional extensions.

markdown-wasm can be used in the browser as follows:

<script src="markdown.js"></script>
<script>
window["markdown"].ready.then(markdown => {
  console.log(markdown.parse("# hello\n*world*"))
})
</script>

markdown-wasm can be used in Node.js as follows:

const  markdown  =  require("./dist/markdown.node.js") 
console.log(markdown.parse("# hello\n*world*"))

markdown-wasm is open-source software under the MIT license.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.
午夜电影_免费高清视频|高清电视|高清电影_青苹果影院