Tip
One import renders every block on this site.
Install
Section titled "Install"pnpmpnpm add comark @comark/html comark-uinpmnpm install comark @comark/html comark-uiRender
Section titled "Render"Pass
comarkUi()to the renderer.
> [!TIP]
> One import renders every block on this site.
::steps
### Install
:::code-group
```sh [pnpm]
pnpm add comark @comark/html comark-ui
```
```sh [npm]
npm install comark @comark/html comark-ui
```
:::
### Render
Pass `comarkUi()` to the renderer.
::This site renders every page through comark-ui.
Install the packages
Section titled "Install the packages"Install Comark, the renderer you use, and comark-ui.
pnpmpnpm add comark @comark/html comark-uinpmnpm install comark @comark/html comark-uiyarnyarn add comark @comark/html comark-uibunbun add comark @comark/html comark-uiFor Vue, React, or Svelte, install
@comark/vue,@comark/react, or@comark/sveltein place of@comark/html.Register the blocks
Section titled "Register the blocks"Use
comarkUi()to get thepluginsandcomponentsfor one renderer, and import it from the entry that matches the renderer.HTMLimport { createHtmlRenderer } from "@comark/html"; import comarkUi from "comark-ui/html"; const render = createHtmlRenderer(comarkUi()); const html = await render("::tabs\n...\n::");Vue<script setup lang="ts"> import { Markdown } from "@comark/vue"; import comarkUi from "comark-ui/vue"; const { plugins, components } = comarkUi(); defineProps<{ source: string }>(); </script> <template> <Markdown :value="source" :plugins="plugins" :components="components" /> </template>Reactimport { Markdown } from "@comark/react"; import comarkUi from "comark-ui/react"; const { plugins, components } = comarkUi(); export function Doc({ source }: { source: string }) { return <Markdown value={source} plugins={plugins} components={components} />; }For Svelte, import
comarkUifromcomark-ui/svelte.Write a block
Section titled "Write a block"Every block on this site now renders. Try one from the playground, or start with a callout:
> [!TIP] > One import renders every block on this site.
Options
Section titled "Options"Every plugin is on except include, which reads files from disk.
Turn a plugin off
Section titled "Turn a plugin off"Pass false to turn a plugin and its components off.
comarkUi({ zoom: false });Pass a plugin options
Section titled "Pass a plugin options"Pass an object to set a plugin's options. Each block's page lists them under API.
comarkUi({
code: { actions: [{ id: "run", label: "Run" }] },
github: { callouts: false, references: { repo: "owner/name" } },
table: { root: "data" },
include: { root: "content" },
});Each key is the package name without comark-, in camelCase, such as fileTree, codeNotes, or readingTime. mermaid is comark-pele. github takes its three plugins by name, callouts, references, and html. links takes external and anchors.
Read files
Section titled "Read files"cast, table, and tests can read files from disk, so comark-ui gives them a reader that finds none. Inline casts, CSV fences, and pasted reports still render. Pass { root } to read files under a folder, or { read } to read them yourself.
icon's resolver also draws the icons in cards, details, file trees, tabs, and code actions, so its collections and fetch apply to all of them.
Parse in a browser
Section titled "Parse in a browser"Pass chips: { download: false } when you parse in a browser, which may block downloading another site's images.
Warning
diagrams sends each diagram's source to https://kroki.io unless you pass your own server.
Critic styles
Section titled "Critic styles"critic has no component for its styles. Put criticCss, which every entry exports, in the page.
Text styles
Section titled "Text styles"comark-ui also styles the headings, paragraphs, lists, tables, code, and quotes around the blocks, with the same tokens. Pass typeset: false if your site already styles Markdown. Typeset has the details.
Untrusted Markdown
Section titled "Untrusted Markdown"comarkUi() also returns tags, every element a parsed document can hold besides the components: Markdown's own, the raw HTML that GitHub's html() keeps, and the plain elements the plugins draw with. With the components' names, it's the allowlist for Comark's security plugin, and it follows the options you pass.
import security from "comark/plugins/security";
const { plugins, components, tags } = comarkUi();
const allowedTags = [...tags, ...Object.keys(components)];
const render = createHtmlRenderer({ plugins: [...plugins, security({ allowedTags })], components });blocks lists the blocks the plugins replace while parsing, such as ::code-group. A linter that reports unknown components needs them beside the components' names.
Mermaid
Section titled "Mermaid"comark-ui draws mermaid fences with comark-pele, a third-party plugin by farnabaz, themed by the shared --comark-* tokens. The mermaid option takes comark-pele's options, or false:
comarkUi({ mermaid: { languages: ["mermaid"] } }); // only `mermaid` fences, not `pele` ones
comarkUi({ mermaid: false }); // leave `mermaid` fences as codeA site that renders documents other people write, on a Worker for example, can limit how much Pele draws per document. A diagram past maxDiagrams, or past maxSource characters of Mermaid over the whole document, shows its source as a code block, and meta.issues says which one and why:
comarkUi({ mermaid: { maxDiagrams: 4, maxSource: 8000 } });Note
Pele adds about 260 KB gzipped to a bundle. comark-ui/vue loads it only when a document has a diagram, and Vue's server renderer waits for it. The other entries load it with the rest, so turn it off there if a size limit matters more than diagrams.
If you use Comark's built-in mermaid plugin instead, pass mermaid: false, since both read mermaid fences. Mermaid covers syntax and theming.
Code highlighting
Section titled "Code highlighting"comark-ui highlights code only with a Shiki you pass, so the preset bundles no grammars or themes. createLazyHighlighter() from comark-ui/shiki builds one: give it the grammars a document may use and the themes, each as a dynamic import, and pass the result as shiki. Install shiki beside comark-ui:
import { createLazyHighlighter } from "comark-ui/shiki";
comarkUi({
shiki: createLazyHighlighter({
languages: {
typescript: () => import("shiki/langs/typescript.mjs"),
bash: () => import("shiki/langs/bash.mjs"),
},
aliases: { ts: "typescript", sh: "bash", zsh: "bash" },
themes: {
light: () => import("shiki/themes/github-light.mjs"),
dark: () => import("shiki/themes/github-dark.mjs"),
},
}),
});Each grammar loads the first time a fence asks for it, once however many documents ask at the same time, so a bundler splits the ones a page never uses into chunks that never load. The themes load with the first grammar. A fence in a language you didn't list stays plain and loads nothing. A grammar that fails to load leaves its block plain, and loads again the next time a fence asks. Shiki names a grammar only once it loads, so list in aliases every other name your fences use for it, such as ts for typescript.
The result also has language(info), which gives the name in languages that a fence's info string or alias stands for, and languages, every name you listed.
To pass your own Shiki instead, highlighter gets each fence's language and returns your Shiki, so it can load the grammar first, or undefined to leave the block plain. A language Shiki doesn't know stays plain too. comark-code reads the colored lines after, so line markers and numbers still work:
import { createHighlighterCore } from "shiki/core";
import { createJavaScriptRegexEngine } from "shiki/engine/javascript";
const shiki = await createHighlighterCore({
themes: [import("shiki/themes/github-light.mjs"), import("shiki/themes/github-dark.mjs")],
langs: [import("shiki/langs/typescript.mjs")],
engine: createJavaScriptRegexEngine(),
});
comarkUi({
shiki: {
highlighter: () => shiki,
themes: { light: "github-light", dark: "github-dark" },
},
});Both use the JavaScript regex engine, which needs no WebAssembly, so they run on Workers and in browsers. A site that renders documents other people write can also pass maxBlocks and maxSource, the characters of code over the whole document. Spread a lazy highlighter to add them, as in shiki: { ...highlighter, maxSource: 200_000 }. A block past either shows without colors, and meta.issues says which one and why. Limits are checked before calling highlighter, so rejected blocks load no grammars, even to check language support. Unsupported languages within the remaining budget stay plain and use no budget; after an oversized block, a later, shorter block can still fit.
One block alone
Section titled "One block alone"Every block is its own package, and comark-ui only registers them. To install fewer, each block's page ends with how to install and register it alone. Renderers shows several in one renderer.
Versions
Section titled "Versions"comark-ui@X holds every block at version X. comark-linter finds an installed comark-ui and checks documents with its plugins.
pnpm trust errors
Section titled "pnpm trust errors"With trustPolicy: no-downgrade, pnpm refuses comark-annotate, comark-carousel, and comark-zoom from 0.4.1 through 0.12.2 with ERR_PNPM_TRUST_DOWNGRADE: "Earlier versions had staged publish, but this version has trusted publisher." comark-ui and comark-linter depend on them, so installing those fails too.
Their first releases were staged on npm and approved with 2FA, which pnpm ranks highest. From 0.4.1 through 0.12.2, every package went out directly through OIDC trusted publishing with provenance. pnpm compares each version with every version published before it, so those releases stay blocked. Releases after 0.12.2 are staged again, so upgrade to one.
To stay on a blocked version, check its publisher and provenance before adding an exception:
npm view [email protected] _npmUser _npmUser.trustedPublisher.id dist.attestations --jsonThe metadata should name GitHub Actions, have _npmUser.trustedPublisher.id set to github, and include dist.attestations.provenance. Check its provenance on npm against this repository's
release.yaml workflow too.
If you accept that publishing change, add only the reviewed packages and exact versions to your existing pnpm-workspace.yaml. For [email protected], its carousel and zoom dependencies need exceptions too:
trustPolicy: no-downgrade
trustPolicyExclude:
- [email protected]
- [email protected]
- [email protected]Check carousel and zoom's metadata the same way, then install locally and run the CLI:
pnpm add -D [email protected]
pnpm exec comark-annotate check report.mdThe policy still checks every other package and version. A later upgrade needs its own review and exact-version exception. When installing the full preset, review each package pnpm names in the error rather than excluding comark-* or disabling the policy.
Next steps
Section titled "Next steps"Editor adds a Tiptap editor to your app, with Vue bindings, file uploads, and Markdown conversion.