A remark plugin to render mermaid diagrams using playwright
HTML
85
117 commits
updated Oct 8, 2024
A remark plugin to render mermaid diagrams using playwright.
[!IMPORTANT]
Use cases for this package are rare. You should probably use
rehype-mermaidinstead.
npm install remark-mermaidjs
Outside of browsers remark-mermaidjs uses Playwright. If you use this
outside of a browser, you need to install Playwright and a Playwright browser.
npm install playwright
npx playwright install --with-deps chromium
See the Playwright Browsers documentation for more information.
This plugin takes all code blocks marked as mermaid and renders them as an inline SVG.
import { readFile } from 'node:fs/promises'
import { remark } from 'remark'
import remarkMermaid from 'remark-mermaidjs'
const { value } = await remark()
.use(remarkMermaid, {
/* Options */
})
.process(await readFile('readme.md'))
console.log(value)
This package has a default export remarkMermaid.
unified().use(remarkMermaid, options?)browserThe Playwright browser to use. (object, default: chromium)
cssA URL that points to a custom CSS file to load. Use this to load custom fonts. This option is
ignored in the browser. You need to include the CSS in your build manually. (string | URL)
errorFallbackCreate a fallback node if processing of a mermaid diagram fails. If nothing is returned, the code block is removed. The function receives the following arguments:
node: The mdast code node that couldn’t be rendered.error: The error message that was thrown.file: The file on which the error occurred.launchOptionsThe options used to launch the browser. (object)
mermaidConfigThe mermaid config to use.
Note: This config is only supported in Node.js. In the browser this option is unused. If you use
this in a browser, call mermaid.initialize() manually.
prefixA custom prefix to use for Mermaid IDs. (string, default: mermaid)
This project is compatible with Node.js 18 or greater.
mermaid is the library that’s used to render the diagrams.mermaid-isomorphic allows this package to
render Mermaid diagrams in both Node.js and the browser.rehype-mermaid is a more powerful plugin that
does the same, but as a rehype plugin.Test fixtures are generated and verified using Linux. Rendering on other platforms may yield slightly different results. Don’t worry about adding new fixtures, but don’t update existing ones that cause CI to fail. Furthermore see my global contributing guidelines.
116 commits
1 commits
HTML
96.7%
TypeScript
3.0%
A remark plugin to render mermaid diagrams using playwright
HTML
85
117 commits
updated Oct 8, 2024
A remark plugin to render mermaid diagrams using playwright.
[!IMPORTANT]
Use cases for this package are rare. You should probably use
rehype-mermaidinstead.
npm install remark-mermaidjs
Outside of browsers remark-mermaidjs uses Playwright. If you use this
outside of a browser, you need to install Playwright and a Playwright browser.
npm install playwright
npx playwright install --with-deps chromium
See the Playwright Browsers documentation for more information.
This plugin takes all code blocks marked as mermaid and renders them as an inline SVG.
import { readFile } from 'node:fs/promises'
import { remark } from 'remark'
import remarkMermaid from 'remark-mermaidjs'
const { value } = await remark()
.use(remarkMermaid, {
/* Options */
})
.process(await readFile('readme.md'))
console.log(value)
This package has a default export remarkMermaid.
unified().use(remarkMermaid, options?)browserThe Playwright browser to use. (object, default: chromium)
cssA URL that points to a custom CSS file to load. Use this to load custom fonts. This option is
ignored in the browser. You need to include the CSS in your build manually. (string | URL)
errorFallbackCreate a fallback node if processing of a mermaid diagram fails. If nothing is returned, the code block is removed. The function receives the following arguments:
node: The mdast code node that couldn’t be rendered.error: The error message that was thrown.file: The file on which the error occurred.launchOptionsThe options used to launch the browser. (object)
mermaidConfigThe mermaid config to use.
Note: This config is only supported in Node.js. In the browser this option is unused. If you use
this in a browser, call mermaid.initialize() manually.
prefixA custom prefix to use for Mermaid IDs. (string, default: mermaid)
This project is compatible with Node.js 18 or greater.
mermaid is the library that’s used to render the diagrams.mermaid-isomorphic allows this package to
render Mermaid diagrams in both Node.js and the browser.rehype-mermaid is a more powerful plugin that
does the same, but as a rehype plugin.Test fixtures are generated and verified using Linux. Rendering on other platforms may yield slightly different results. Don’t worry about adding new fixtures, but don’t update existing ones that cause CI to fail. Furthermore see my global contributing guidelines.
116 commits
1 commits
HTML
96.7%
TypeScript
3.0%