WebAssembly build of Rust lib pulldown-cmark
for Node.js
npm install @web-alchemy/markdown-wasm
import { parse } from '@web-alchemy/markdown-wasm';
const markdownSource = `# title
Some text
![some image alt](image.png)
`;
const html = parse(markdownSource);
console.log(html)
/*
<h1>title</h1>
<p>Some text</p>
<p><img src="image.png" alt="some image alt" /></p>
*/
You can use additional (non CommonMark) features via Options
. They work as bit masks.
import { parse, Flags } from '@web-alchemy/markdown-wasm';
const source = `# my todo list { #list-head-id .head-class }
- [x] check 1
- [x] check 2
- [ ] check 3
`;
const FLAGS = new Flags();
const flags = FLAGS.ENABLE_HEADING_ATTRIBUTES | FLAGS.ENABLE_TASKLISTS;
const html = parse(source, flags);
/*
<h1 id="list-head-id" class="head-class">my todo list</h1>
<ul>
<li><input disabled="" type="checkbox" checked=""/> check 1</li>
<li><input disabled="" type="checkbox" checked=""/> check 2</li>
<li><input disabled="" type="checkbox"/> check 3</li>
</ul>
*/
You can enable all feautures with FLAGS.ENABLE_ALL
flag.
Results of benchmark (ops/s):
- Install Node.js
- Install dev dependencies -
npm ci
. - Modify source code in
src
folder and write tests intest
folder. - Create build -
node --run build
.pkg
folder should contains npm package files. - Run tests -
node --run test
.