Skip to content

rehype Plugin

The @mrsf/rehype-mrsf package is a rehype plugin that renders Sidemark review comments directly into your HTML output. It works with the entire unified ecosystem — Astro, Next.js MDX, Docusaurus, and any other tool that uses remark/rehype.

Install

bash
npm install @mrsf/rehype-mrsf

Live Demo

The panel below renders a sample document with the rehype plugin. Hover the gutter badges or inline highlights to see tooltips, toggle options, and try the interactive actions.

Quick Start

ts
import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import rehypeStringify from "rehype-stringify";
import { rehypeMrsf } from "@mrsf/rehype-mrsf";

const html = await unified()
  .use(remarkParse)
  .use(remarkRehype)
  .use(rehypeMrsf, { documentPath: "docs/guide.md" })
  .use(rehypeStringify, { allowDangerousHtml: true })
  .process(markdownSource);

Include the stylesheet:

ts
import "@mrsf/rehype-mrsf/style.css";

TIP

Pass { allowDangerousHtml: true } to rehype-stringify so the raw HTML tooltips render correctly.

Options

OptionTypeDefaultDescription
commentsMrsfDocumentPre-loaded sidecar data (highest priority)
loader() => MrsfDocument | nullCustom loader function
sidecarPathstringExplicit path to .review.yaml / .review.json
documentPathstringAuto-discover sidecar next to this markdown file
showResolvedbooleantrueShow resolved comments
interactivebooleanfalseShow action buttons (resolve, reply, edit)
gutterPosition'left' | 'right''right'Badge placement
gutterForInlinebooleantrueShow badge for inline-highlighted comments
inlineHighlightsbooleantrueHighlight selected_text with <mark>
lineHighlightbooleanfalseAdd background tint on commented lines
theme'light' | 'dark' | 'auto''auto'Color scheme hint
cwdstringprocess.cwd()Working directory for file discovery

Data Provisioning

The plugin supports four ways to load sidecar data, in priority order:

  1. comments
  2. loader
  3. sidecarPath
  4. documentPath

Framework Integration

Astro

ts
import { rehypeMrsf } from "@mrsf/rehype-mrsf";

export default defineConfig({
  markdown: {
    rehypePlugins: [
      [rehypeMrsf, { documentPath: "src/content/guide.md" }],
    ],
  },
});

Next.js MDX

ts
import createMDX from "@next/mdx";
import { rehypeMrsf } from "@mrsf/rehype-mrsf";

const withMDX = createMDX({
  options: {
    rehypePlugins: [
      [rehypeMrsf, { documentPath: "docs/guide.md" }],
    ],
  },
});

Released under the MIT License.