# Renderers

## Every plugin at once

[`comark-ui`](https://comark-ui.onmax.me/getting-started) 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:

```ts
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" } } }));
```

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.

## Support

| Package | `@comark/html` | `@comark/vue` | `@comark/react` | `@comark/svelte` |
| --- | --- | --- | --- | --- |
| [annotate](https://comark-ui.onmax.me/annotate) | `comark-annotate/html` | | | |
| [badge](https://comark-ui.onmax.me/badge) | `comark-badge/html` | `comark-badge/vue` | `comark-badge/react` | `comark-badge/svelte` |
| [cards](https://comark-ui.onmax.me/cards) | `comark-cards/html` | `comark-cards/vue` | `comark-cards/react` | `comark-cards/svelte` |
| [carousel](https://comark-ui.onmax.me/carousel) | `comark-carousel/html` | `comark-carousel/vue` | `comark-carousel/react` | `comark-carousel/svelte` |
| [cast](https://comark-ui.onmax.me/cast) | `comark-cast/html` | `comark-cast/vue` | `comark-cast/react` | `comark-cast/svelte` |
| [charts](https://comark-ui.onmax.me/charts) | `comark-charts/html` | `comark-charts/vue` | `comark-charts/react` | `comark-charts/svelte` |
| [chips](https://comark-ui.onmax.me/chips) | `comark-chips/html` | `comark-chips/vue` | `comark-chips/react` | `comark-chips/svelte` |
| [code](https://comark-ui.onmax.me/code) | `comark-code/html` | `comark-code/vue` | `comark-code/react` | `comark-code/svelte` |
| [code-notes](https://comark-ui.onmax.me/code-notes) | `comark-code-notes/html` | `comark-code-notes/vue` | `comark-code-notes/react` | `comark-code-notes/svelte` |
| [colors](https://comark-ui.onmax.me/colors) | `comark-colors/html` | `comark-colors/vue` | `comark-colors/react` | `comark-colors/svelte` |
| [comments](https://comark-ui.onmax.me/comments) | `comark-comments/html` | | | |
| [details](https://comark-ui.onmax.me/details) | `comark-details/html` | `comark-details/vue` | `comark-details/react` | `comark-details/svelte` |
| [diagrams](https://comark-ui.onmax.me/diagrams) | `comark-diagrams/html` | `comark-diagrams/vue` | `comark-diagrams/react` | `comark-diagrams/svelte` |
| [diff](https://comark-ui.onmax.me/diff) | `comark-diff/html` | | | |
| [embed](https://comark-ui.onmax.me/embed) | `comark-embed/html` | `comark-embed/vue` | `comark-embed/react` | `comark-embed/svelte` |
| [fields](https://comark-ui.onmax.me/fields) | `comark-fields/html` | `comark-fields/vue` | `comark-fields/react` | `comark-fields/svelte` |
| [file-tree](https://comark-ui.onmax.me/file-tree) | `comark-file-tree/html` | `comark-file-tree/vue` | `comark-file-tree/react` | `comark-file-tree/svelte` |
| [github](https://comark-ui.onmax.me/github) | `comark-github/html` | `comark-github/vue` | `comark-github/react` | `comark-github/svelte` |
| [icon](https://comark-ui.onmax.me/icon) | `comark-icon/html` | `comark-icon/vue` | `comark-icon/react` | `comark-icon/svelte` |
| [links](https://comark-ui.onmax.me/links) | `comark-links/html` | `comark-links/vue` | `comark-links/react` | `comark-links/svelte` |
| [magic-move](https://comark-ui.onmax.me/magic-move) | `comark-magic-move/html` | `comark-magic-move/vue` | `comark-magic-move/react` | `comark-magic-move/svelte` |
| [mark](https://comark-ui.onmax.me/mark) | `comark-mark/html` | `comark-mark/vue` | `comark-mark/react` | `comark-mark/svelte` |
| [math](https://comark-ui.onmax.me/math) | `comark-mathml/html` | `comark-mathml/vue` | `comark-mathml/react` | `comark-mathml/svelte` |
| [media](https://comark-ui.onmax.me/media) | `comark-media/html` | `comark-media/vue` | `comark-media/react` | `comark-media/svelte` |
| [metrics](https://comark-ui.onmax.me/metrics) | `comark-metrics/html` | `comark-metrics/vue` | `comark-metrics/react` | `comark-metrics/svelte` |
| [outline](https://comark-ui.onmax.me/outline) | `comark-outline/html` | `comark-outline/vue` | `comark-outline/react` | `comark-outline/svelte` |
| [properties](https://comark-ui.onmax.me/properties) | `comark-properties/html` | `comark-properties/vue` | `comark-properties/react` | `comark-properties/svelte` |
| [qr](https://comark-ui.onmax.me/qr) | `comark-qr/html` | `comark-qr/vue` | `comark-qr/react` | `comark-qr/svelte` |
| [quiz](https://comark-ui.onmax.me/quiz) | `comark-quiz/html` | | | |
| [sources](https://comark-ui.onmax.me/sources) | `comark-sources/html` | `comark-sources/vue` | `comark-sources/react` | `comark-sources/svelte` |
| [steps](https://comark-ui.onmax.me/steps) | `comark-steps/html` | `comark-steps/vue` | `comark-steps/react` | `comark-steps/svelte` |
| [table](https://comark-ui.onmax.me/table) | `comark-table/html` | `comark-table/vue` | `comark-table/react` | `comark-table/svelte` |
| [tabs](https://comark-ui.onmax.me/tabs) | `comark-tabs/html` | `comark-tabs/vue` | `comark-tabs/react` | `comark-tabs/svelte` |
| [tests](https://comark-ui.onmax.me/tests) | `comark-tests/html` | `comark-tests/vue` | `comark-tests/react` | `comark-tests/svelte` |
| [git graph](https://comark-ui.onmax.me/git-graph) | `comark-git-graph/html` | `comark-git-graph/vue` | `comark-git-graph/react` | `comark-git-graph/svelte` |
| [bundle](https://comark-ui.onmax.me/bundle) | `comark-bundle/html` | `comark-bundle/vue` | `comark-bundle/react` | `comark-bundle/svelte` |
| [time](https://comark-ui.onmax.me/time) | `comark-time/html` | `comark-time/vue` | `comark-time/react` | `comark-time/svelte` |
| [zoom](https://comark-ui.onmax.me/zoom) | `comark-zoom/html` | `comark-zoom/vue` | `comark-zoom/react` | `comark-zoom/svelte` |

Each entry exports the parse plugin as `default` and the renderer's `components`. [github](https://comark-ui.onmax.me/github) and [links](https://comark-ui.onmax.me/links) have several plugins, so they export them by name.

Annotate, comments, [diff](https://comark-ui.onmax.me/diff), and [quiz](https://comark-ui.onmax.me/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](https://comark-ui.onmax.me/cjk), [critic](https://comark-ui.onmax.me/critic), [deflist](https://comark-ui.onmax.me/deflist), [figure](https://comark-ui.onmax.me/figure), [footnotes](https://comark-ui.onmax.me/footnotes), [keys](https://comark-ui.onmax.me/keys), [reading-time](https://comark-ui.onmax.me/reading-time), [xref](https://comark-ui.onmax.me/xref), and [include](https://comark-ui.onmax.me/include) have no components. They output plain HTML elements or write to the document's meta, so they work with any renderer. [chat](https://comark-ui.onmax.me/chat) renders AI SDK messages with `@comark/vue`, `@comark/react`, or `@comark/svelte` instead of plugging into them. [lint](https://comark-ui.onmax.me/lint) checks documents and doesn't render them.

## Several plugins

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

```ts
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,
  },
});
```

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.

## Scripts and styles

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](https://comark-ui.onmax.me/guide/typeset) 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.

### HTML in a Vue app

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:

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

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

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

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.

## Content Security Policy

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:

```ts
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(" ")}
```

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:

```ts
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,
);
```

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"] })`.

<!-- vitehub-docs:section-links -->
## In this section

- [Accessibility](https://comark-ui.onmax.me/raw/guide/accessibility.md)
- [Agents](https://comark-ui.onmax.me/raw/guide/agents.md)
- [Editor](https://comark-ui.onmax.me/raw/guide/editor.md)
- [Renderers](https://comark-ui.onmax.me/raw/guide/renderers.md) (this page)
- [Theming](https://comark-ui.onmax.me/raw/guide/theming.md)
- [Typeset](https://comark-ui.onmax.me/raw/guide/typeset.md)
- [Validation](https://comark-ui.onmax.me/raw/guide/validation.md)

Next: [Theming](https://comark-ui.onmax.me/raw/guide/theming.md)

All pages: [llms.txt](https://comark-ui.onmax.me/llms.txt)
