@wesleyel/md-core
v0.1.1
Published
Markdown rendering core (CommonMark + GFM + math) compiled to WebAssembly
Downloads
20
Maintainers
Readme
@wesleyel/md-core
Markdown rendering core from md-preview: CommonMark + GFM, math extraction, line mapping, TOC, front matter, sanitisation, and CJK-aware word counts. Compiled to WebAssembly.
Install
npm install @wesleyel/md-coreUsage
The package is an ESM wasm-bindgen module. Initialise it once, then call render.
import init, { render, version } from '@wesleyel/md-core'
import wasmUrl from '@wesleyel/md-core/md_core_bg.wasm?url'
await init({ module_or_path: wasmUrl })
const FLAG = {
SMART_PUNCTUATION: 1 << 0,
MATH: 1 << 1,
SANITIZE: 1 << 2,
HARD_BREAKS: 1 << 3,
TEX_DELIMS: 1 << 4,
}
const out = render('# Hello\n\n$E = mc^2$', FLAG.MATH | FLAG.SANITIZE)
console.log(out.html) // sanitised HTML, `data-l` on top-level blocks
console.log(JSON.parse(out.toc))
console.log(out.frontmatter, out.words, out.chars, out.lines)
out.free()
console.log(version())Without a bundler, pass a URL that serves md_core_bg.wasm:
import init, { render } from '@wesleyel/md-core'
await init({ module_or_path: new URL('./md_core_bg.wasm', import.meta.url) })Math is extracted into KaTeX-ready nodes ($…$, $$…$$, and optionally
\\(…\\) / \\[…\\]). Rendering those nodes is the caller's job.
License
MIT
