
Company News
Free Business Plan Upgrades for Open Source Maintainers
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.
@create-markdown/preview
Advanced tools
Framework-agnostic HTML rendering for @create-markdown with optional syntax highlighting
Framework-agnostic HTML rendering for @create-markdown with syntax highlighting (Shiki) and diagram support (Mermaid).
# Using pnpm
pnpm add @create-markdown/preview
# Using npm
npm install @create-markdown/preview
# Optional: Install plugins
pnpm add shiki
import { markdownToHTML } from '@create-markdown/preview';
import DOMPurify from 'dompurify';
const html = await markdownToHTML(`
# Hello World
This is **bold** and *italic* text.
`);
const preview = document.getElementById('preview');
if (preview) {
preview.innerHTML = DOMPurify.sanitize(html, { USE_PROFILES: { html: true } });
}
Sanitize untrusted content before rendering it. Direct DOM assignment is only appropriate when you fully trust the markdown source.
import { renderAsync, shikiPlugin } from '@create-markdown/preview';
import { parse } from '@create-markdown/core';
const blocks = parse(`
\`\`\`typescript
const greeting = "Hello, World!";
console.log(greeting);
\`\`\`
`);
const html = await renderAsync(blocks, {
plugins: [shikiPlugin({ theme: 'github-dark' })],
});
import { renderAsync } from '@create-markdown/preview';
import { mermaidPlugin } from '@create-markdown/preview-mermaid';
import { parse } from '@create-markdown/core';
const blocks = parse(`
\`\`\`mermaid
flowchart LR
A[Start] --> B[Process]
B --> C[End]
\`\`\`
`);
const html = await renderAsync(blocks, {
plugins: [
mermaidPlugin({
theme: 'default',
config: { securityLevel: 'strict' },
}),
],
});
Install Mermaid support only when you need it:
pnpm add @create-markdown/preview-mermaid mermaid
Use Mermaid's stricter security mode when diagram text can come from users. Only opt into looser Mermaid settings for fully trusted content.
<script type="module">
import { registerPreviewElement } from '@create-markdown/preview';
registerPreviewElement();
</script>
<markdown-preview theme="github">
# Hello World
This is rendered as HTML automatically!
</markdown-preview>
With plugins:
import { registerPreviewElement, shikiPlugin } from '@create-markdown/preview';
import { mermaidPlugin } from '@create-markdown/preview-mermaid';
registerPreviewElement({
plugins: [
shikiPlugin(),
mermaidPlugin(),
],
});
The web component renders trusted content by default, so sanitize user-provided markdown before passing it to the element.
blocksToHTML(blocks, options?)Converts blocks to HTML string synchronously.
markdownToHTML(markdown, options?)Converts markdown string to HTML.
renderAsync(blocks, options?)Async version that initializes plugins before rendering.
shikiPlugin(options?) - Syntax highlighting with ShikimermaidPlugin(options?) - Mermaid diagram rendering via @create-markdown/preview-mermaidCSS themes are available at:
@create-markdown/preview/themes/github.css@create-markdown/preview/themes/github-dark.css@create-markdown/preview/themes/minimal.cssinterface PreviewOptions {
classPrefix?: string; // CSS class prefix (default: 'cm-')
theme?: string; // Theme name
linkTarget?: '_blank' | '_self';
sanitize?: boolean | ((html: string) => string);
plugins?: PreviewPlugin[]; // Plugins for enhanced rendering
}
MIT
FAQs
Framework-agnostic HTML rendering for @create-markdown with optional syntax highlighting
The npm package @create-markdown/preview receives a total of 639,552 weekly downloads. As such, @create-markdown/preview popularity was classified as popular.
We found that @create-markdown/preview demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.

Security News
The supply chain control that delays freshly published gems now covers lockfile generation and gem vendoring in Ruby projects.

Security News
During a UK cyber test, a Mythos 5 agent used sockpuppets, social engineering, and prompt injection to try to get a maintainer to merge malware.