@lowlighter/markdown
v4.0.1
Published
[](https://jsr.io/@libs/markdown) [](https://jsr.io/@libs/markdown) [
markdown("# Hello, world!")
// Toggle additional features through options
markdown("$\\pi$ is ==irrational==", { math: true, markers: true })
// Raw HTML is escaped by default, opt-in with the `html` option
markdown("<b>trusted</b>", { html: true })
// Retrieve frontmatter metadata
const { value, metadata } = markdown("---\ntitle: foo\n---\nbar", { frontmatter: true, metadata: true })
console.log(value, metadata.frontmatter) // "bar" { title: "foo" }Reusing a renderer and hooking custom rules
import { Renderer } from "./renderer.ts"
const renderer = new Renderer({
highlighting: true,
wikilinks: { resolve: (link) => `/wiki/${link}` },
// Hook the underlying markdown-it instance for custom rules and renderers
hooks(engine) {
engine.renderer.rules.code_inline = (tokens, index) => `<kbd>${engine.utils.escapeHtml(tokens[index].content)}</kbd>`
},
})
renderer.render("# Hello, world!")✨ Features
- Single
markdown(text, options)function where every feature is a simple toggle. - Renders GitHub Flavored Markdown by default (tables, strikethrough, autolinks, footnotes and tasklists).
- Raw HTML is escaped by default, making the output safe against HTML injection (opt-in with the
htmloption). - Optional features:
- Math and mermaid are rendered as plain markup intended for client-side processing (KaTeX, MathJax, mermaid), so no heavyweight server-side dependency is required.
- Escape hatch to the underlying markdown-it instance through the
hooksoption for custom syntax and rendering rules.
📜 Licenses and credits
Copyright (c) Simon Lecoq <@lowlighter>. (MIT License)
https://github.com/lowlighter/libs/blob/main/LICENSEThis library relies on the awesome markdown-it library.
