Rendering Markdown to HTML for a blog or docs site, with a table-of-contents extractor, without a heavy parser.
Overview
Everything a blog or docs page needs — headings with anchor ids, nested & task lists, fenced code, blockquotes, GFM tables, images and links — rendering to clean HTML with source HTML escaped by default. Includes extractHeadings() for a table of contents. It's what the blog template in create-lacspace-app uses.
Install
$ npm install @lacspace/markdown
Quick example
@lacspace/markdownts
markdownToHtml(post)
Returns "<h1 id=…>…"
Key API
markdownToHtml(md, opts)Markdown → HTML string.
extractHeadings(md)Heading outline for a TOC.
slugify(text)GitHub-style anchor slug.
Tips
Use `headingOffset: 1` when the page already has an `<h1>`, so document `#` becomes `<h2>`.
`extractHeadings(md)` gives you `{ level, text, id }[]` for an on-this-page menu; `slugify()` matches the anchor ids.
Pair it with the `blog` and `docs` templates in create-lacspace-app for a complete content site.
Zero-dependency and isomorphic — safe to import on the server, in the browser, on the edge and in React Native. It tree-shakes, so you only ship what you import.
Watch out for
Raw HTML in the source is **escaped**, not passed through — this is a safety feature. If you need embedded HTML, sanitize and inject it yourself.
Looking for the complete API and more examples? The npm page and GitHub README carry the full reference — or grab the PDF.