GitHub 42
Skip to content

Renderers

Which renderer each package supports, and how to use several in one document.

comark-ui is the recommended install. It registers every package in the order they need, with one icon resolver for :icon, cards, details, file trees, tabs, and code actions. It returns the plugins and components for one renderer:

import { createHtmlRenderer } from "@comark/html";
import comarkUi from "comark-ui/html"; // or /vue, /react, /svelte

const render = createHtmlRenderer(comarkUi({ zoom: false, github: { references: { repo: "owner/name" } } }));
ts

Every plugin is on except include, which reads from disk. cast, table, and tests read no files until you give them options. false turns a plugin and its components off, and an object passes it options. The Vue, React, and Svelte entries leave out annotate, comments, diff, and quiz. comark-ui shares the plugins' version.

Package@comark/html@comark/vue@comark/react@comark/svelte
annotatecomark-annotate/html
badgecomark-badge/htmlcomark-badge/vuecomark-badge/reactcomark-badge/svelte
cardscomark-cards/htmlcomark-cards/vuecomark-cards/reactcomark-cards/svelte
carouselcomark-carousel/htmlcomark-carousel/vuecomark-carousel/reactcomark-carousel/svelte
castcomark-cast/htmlcomark-cast/vuecomark-cast/reactcomark-cast/svelte
chartscomark-charts/htmlcomark-charts/vuecomark-charts/reactcomark-charts/svelte
chipscomark-chips/htmlcomark-chips/vuecomark-chips/reactcomark-chips/svelte
codecomark-code/htmlcomark-code/vuecomark-code/reactcomark-code/svelte
code-notescomark-code-notes/htmlcomark-code-notes/vuecomark-code-notes/reactcomark-code-notes/svelte
colorscomark-colors/htmlcomark-colors/vuecomark-colors/reactcomark-colors/svelte
commentscomark-comments/html
detailscomark-details/htmlcomark-details/vuecomark-details/reactcomark-details/svelte
diagramscomark-diagrams/htmlcomark-diagrams/vuecomark-diagrams/reactcomark-diagrams/svelte
diffcomark-diff/html
embedcomark-embed/htmlcomark-embed/vuecomark-embed/reactcomark-embed/svelte
fieldscomark-fields/htmlcomark-fields/vuecomark-fields/reactcomark-fields/svelte
file-treecomark-file-tree/htmlcomark-file-tree/vuecomark-file-tree/reactcomark-file-tree/svelte
githubcomark-github/htmlcomark-github/vuecomark-github/reactcomark-github/svelte
iconcomark-icon/htmlcomark-icon/vuecomark-icon/reactcomark-icon/svelte
linkscomark-links/htmlcomark-links/vuecomark-links/reactcomark-links/svelte
magic-movecomark-magic-move/htmlcomark-magic-move/vuecomark-magic-move/reactcomark-magic-move/svelte
markcomark-mark/htmlcomark-mark/vuecomark-mark/reactcomark-mark/svelte
mathcomark-mathml/htmlcomark-mathml/vuecomark-mathml/reactcomark-mathml/svelte
mediacomark-media/htmlcomark-media/vuecomark-media/reactcomark-media/svelte
metricscomark-metrics/htmlcomark-metrics/vuecomark-metrics/reactcomark-metrics/svelte
outlinecomark-outline/htmlcomark-outline/vuecomark-outline/reactcomark-outline/svelte
propertiescomark-properties/htmlcomark-properties/vuecomark-properties/reactcomark-properties/svelte
qrcomark-qr/htmlcomark-qr/vuecomark-qr/reactcomark-qr/svelte
quizcomark-quiz/html
sourcescomark-sources/htmlcomark-sources/vuecomark-sources/reactcomark-sources/svelte
stepscomark-steps/htmlcomark-steps/vuecomark-steps/reactcomark-steps/svelte
tablecomark-table/htmlcomark-table/vuecomark-table/reactcomark-table/svelte
tabscomark-tabs/htmlcomark-tabs/vuecomark-tabs/reactcomark-tabs/svelte
testscomark-tests/htmlcomark-tests/vuecomark-tests/reactcomark-tests/svelte
git graphcomark-git-graph/htmlcomark-git-graph/vuecomark-git-graph/reactcomark-git-graph/svelte
bundlecomark-bundle/htmlcomark-bundle/vuecomark-bundle/reactcomark-bundle/svelte
timecomark-time/htmlcomark-time/vuecomark-time/reactcomark-time/svelte
zoomcomark-zoom/htmlcomark-zoom/vuecomark-zoom/reactcomark-zoom/svelte

Each entry exports the parse plugin as default and the renderer's components. github and links have several plugins, so they export them by name.

Annotate, comments, diff, and quiz render only to HTML. Annotate's marks on a chart show only in @comark/html, and the other renderers draw the chart without them.

cjk, critic, deflist, figure, footnotes, keys, reading-time, xref, and include have no components. They output plain HTML elements or write to the document's meta, so they work with any renderer. chat renders AI SDK messages with @comark/vue, @comark/react, or @comark/svelte instead of plugging into them. lint checks documents and doesn't render them.

To pick plugins yourself, pass them to one renderer and spread their components into one map:

import { createHtmlRenderer } from "@comark/html";
import include from "comark-include";
import annotate, { components as annotateComponents } from "comark-annotate/html";
import carousel, { components as carouselComponents } from "comark-carousel/html";
import embed, { components as embedComponents } from "comark-embed/html";
import { callouts, components as githubComponents } from "comark-github/html";
import zoom, { components as zoomComponents } from "comark-zoom/html";

const render = createHtmlRenderer({
  plugins: [include(), annotate(), carousel(), embed(), callouts(), zoom()],
  components: {
    ...annotateComponents,
    ...carouselComponents,
    ...embedComponents,
    ...githubComponents,
    ...zoomComponents,
  },
});
ts

Put include first, since it pastes files into the Markdown before the others read it. callouts() replaces Comark's built-in alert plugin.

Annotate brings zoom and carousel, so screenshots and comparisons zoom without zoom(). Add zoom() to zoom content images and ::zoom blocks too.

Every page reads without a script. Scripts add zooming to zoom, arrows and keys to carousel, switching to tabs, copying and wrapping to code, hover and copy to annotate, and copying a diagram as an image or source to Mermaid. Callouts and embeds need only styles.

The HTML renderers inline each plugin's styles and script in the page. Vue, React, and Svelte render the text styles with the document too, since they're scoped to the element the document renders into.

The Vue, React, and Svelte components add the styles and start the script on mount, and stop it when the last one unmounts. To render on a server, import comark-ui/style.css, every package's styles in one file, with your own styles, so the page doesn't shift on mount. With a single package, import its own style.css, such as comark-zoom/style.css.

Without a renderer, call start() from comark-zoom/client once on a page with data-zoom elements. It adds the styles and returns a stop function.

A Vue app that renders its documents with comark-ui/html, at build time or on a server, can show the HTML with ComarkHtml from comark-ui/html/vue. v-html leaves the inline scripts inert, so nothing would zoom, slide, or copy. ComarkHtml runs them after it mounts and again when html changes:

<script setup lang="ts">
import { ComarkHtml } from "comark-ui/html/vue";

defineProps<{ html: string }>();
</script>

<template>
  <ComarkHtml :html="html" class="article" />
</template>
vue

Each script starts once per page, so the copies a server render already ran don't start twice. It renders a div; pass tag="span" for HTML inside a paragraph. comark-ui/vue exports it too, but importing from there also bundles every block's Vue components.

Serve rendered HTML as UTF-8, with Content-Type: text/html; charset=utf-8 or an early <meta charset="utf-8"> in the document head. Inline scripts use Unicode line separators to keep their text identical when nested inside HTML elements. Without an encoding declaration, browsers can decode those separators incorrectly, preventing the scripts from running and invalidating their CSP hashes.

The inlined <style> and <script> elements need 'unsafe-inline' in style-src and script-src, or a hash of each. A script's text changes only between versions. Annotate places marks with style attributes, so its pages need style-src 'unsafe-inline'.

To allow the scripts without rendering a document first, use the preset's scripts: the text of every inline script its plugins can write, for the plugins that are on. Hash each one:

import { createHash } from "node:crypto";
import comarkUi from "comark-ui/html";

const preset = comarkUi();
const hashes = preset.scripts.map(
  (script) => `'sha256-${createHash("sha256").update(script).digest("base64")}'`,
);
// Content-Security-Policy: script-src 'self' ${hashes.join(" ")}
ts

Or add a nonce to each <script> whose text is in the list, and leave any other script, such as one written in a document's own HTML, blocked:

const allowed = new Set(preset.scripts);
const html = rendered.replace(/<script>([\s\S]*?)<\/script>/g, (tag, text) =>
  allowed.has(text) ? `<script nonce="${nonce}">${text}</script>` : tag,
);
ts

The Vue, React, and Svelte presets run their scripts from your bundle, so their scripts is empty. A package used alone exports its list as scripts from its /html entry, such as comark-zoom/html. mermaidScript from comark-ui/html and railScript from comark-outline/html are each one entry of those lists.

Copy image draws a Mermaid diagram from a data: image to make the PNG, so the policy also needs img-src data:.

Raw HTML in notes, slides, and callouts renders like anywhere else in the document. For untrusted input, add Comark's security plugin with the tags to drop, such as security({ blockedTags: ["script", "style", "iframe"] }).