Drop-in replacement for @astrojs/markdown-remark powered by md4x.
undefined~50-70x faster markdown rendering with a single native dependency.
| Scenario | astromd4x | @astrojs/markdown-remark | Speedup |
|---|---|---|---|
createMarkdownProcessor |
11.8M ops/s | 1.8M ops/s | undefined6.5xundefined |
| render: simple | 443K ops/s | 8.2K ops/s | undefined53.7xundefined |
| render: with frontmatter | 155K ops/s | 4.5K ops/s | undefined34.5xundefined |
| render: complex document | 49K ops/s | 670 ops/s | undefined73xundefined |
Install the package:
npx nypm install astromd4x
Override @astrojs/markdown-remark in your root package.json:
{
"pnpm": {
"overrides": {
"@astrojs/markdown-remark": "npm:astromd4x@latest"
}
}
}
Or use directly:
import { createMarkdownProcessor, parseFrontmatter } from "astromd4x";
const processor = await createMarkdownProcessor();
const { code, metadata } = await processor.render("# Hello World");
console.log(code); // <h1 id="hello-world">Hello World</h1>
console.log(metadata.headings); // [{ depth: 1, slug: 'hello-world', text: 'Hello World' }]
createMarkdownProcessor(opts?)Creates a reusable markdown processor. Returns { render(content, opts?) }.
const processor = await createMarkdownProcessor();
const result = await processor.render(markdown);
// result.code - HTML string
// result.metadata.headings - { depth, slug, text }[]
// result.metadata.frontmatter - Record<string, any>
parseFrontmatter(code, options?)Parses YAML frontmatter from markdown content.
const { frontmatter, rawFrontmatter, content } = parseFrontmatter(markdown);
Options for frontmatter: 'preserve' | 'remove' (default) | 'empty-with-spaces' | 'empty-with-lines'
extractFrontmatter(code)Returns raw frontmatter string or undefined.
isFrontmatterValid(frontmatter)Returns true if the frontmatter object is JSON-serializable.
markdownConfigDefaults / syntaxHighlightDefaultsDefault configuration objects matching @astrojs/markdown-remark defaults.
@astrojs/markdown-remarkThis is an early release focused on core rendering performance. Some @astrojs/markdown-remark features are not yet implemented:
highlighter callback — wiring planned)localImagePaths/remoteImagePaths)See plan.md for the full roadmap.
Published under the MIT license.
We use cookies
We use cookies to analyze traffic and improve your experience. You can accept or reject analytics cookies.