@scalar/markdown
v0.1.4
Published
Markdown to HTML for Scalar projects, with GitHub alerts, sanitizing and syntax highlighting
Readme
@scalar/markdown
Markdown to HTML for Scalar projects: GitHub Flavored Markdown, GitHub alerts, sanitizing, and syntax highlighting through @scalar/highlight.
It replaces the Markdown half of @scalar/code-highlight. The code half's replacement is @scalar/highlight/compat.
Installation
npm install @scalar/markdownUsage
import { htmlFromMarkdown } from '@scalar/markdown'
const html = htmlFromMarkdown('# Hello\n\n```js\nconst answer = 42\n```')Code blocks come out with the same hljs / hljs-* classes highlight.js uses, so style them with the stylesheet @scalar/highlight ships:
import '@scalar/highlight/compat/code.css'A fence without a language is left as plain text. There is no language detection, because guessing wrong is worse than not colouring at all.
Other exports
| export | purpose |
| --- | --- |
| htmlFromMarkdown | Markdown string to sanitized HTML |
| getHeadings | Every heading in a Markdown string, with its depth |
| splitContent | Split a Markdown string into one document per heading |
| isHeading, textFromNode | Helpers for transform callbacks |
| rehypeAlert | rehype plugin for GitHub alerts (> [!NOTE]) |
| rehypeHighlight | rehype plugin for syntax highlighting |
| parseMarkdown | GitHub Flavored Markdown string to an mdast tree |
| mdastFromHtml | HTML fragment to a sanitized mdast tree |
| createMarkdownSerializer | Build a reusable mdast to GitHub Flavored Markdown serializer, with remark-stringify options |
parseMarkdown, mdastFromHtml and createMarkdownSerializer exist so packages that work on Markdown trees can share the unified stack this package bundles, rather than shipping a second copy of it.
Community
We are API nerds. You too? Let's chat on Discord: https://discord.gg/scalar
License
The source code in this repository is licensed under MIT.
