Skip to content

markdown-it Plugin

The @mrsf/markdown-it-mrsf package is a standalone markdown-it plugin that renders Sidemark review comments directly into HTML output — badges, line highlights, inline text highlights, and tooltips.

Install

bash
npm install @mrsf/markdown-it-mrsf

Live Demo

The panel below renders a sample Markdown document with MRSF review comments injected by the plugin. Hover over badges to see comment tooltips.

Usage

ts
import MarkdownIt from "markdown-it";
import { mrsfPlugin } from "@mrsf/markdown-it-mrsf";

const md = new MarkdownIt();
md.use(mrsfPlugin, {
  comments: sidecarData,       // inline MrsfDocument object
  // or: documentPath: "doc.md" // auto-discover .review.yaml
  // or: sidecarPath: "doc.md.review.yaml"
  // or: loader: () => loadFromDb()
});

const html = md.render(markdownSource);

Don't forget to include the stylesheet:

ts
import "@mrsf/markdown-it-mrsf/style.css";

Options

OptionTypeDefaultDescription
commentsMrsfDocumentPre-loaded sidecar data (highest priority)
loader() => MrsfDocument | nullCustom loader function
documentPathstringPath to Markdown file for auto-discovery
sidecarPathstringExplicit path to sidecar file
showResolvedbooleantrueWhether to show resolved comments
interactivebooleanfalseAdd action buttons for host JS integration
gutterPosition'left' | 'right''right'Badge placement
gutterForInlinebooleantrueShow gutter badges for inline-highlighted comments
inlineHighlightsbooleantrueHighlight selected_text inline
lineHighlightbooleanfalseAdd background tint on commented lines
theme'light' | 'dark' | 'auto''auto'Color scheme hint
cwdstringprocess.cwd()Working directory for file resolution

See the full documentation in the package README.

Display Modes

  • Gutter + inline: the default, with badges plus inline highlights for comments with selected_text.
  • Gutter only: set inlineHighlights: false.
  • Inline only for anchored text comments: set gutterForInline: false so highlighted selections rely on the inline tooltip instead of a duplicate gutter badge.

Gutter Placement

ts
md.use(mrsfPlugin, { comments, gutterPosition: "left" });
md.use(mrsfPlugin, { comments, gutterPosition: "right" });

Interactive Mode

ts
md.use(mrsfPlugin, { comments, interactive: true });
import { refreshAll } from "@mrsf/markdown-it-mrsf/controller";

The controller wires up inline + gutter buttons and shows built-in modals for add/reply/edit/resolve/unresolve/delete. Listen for events and forward them to your API:

ts
document.addEventListener("mrsf:submit", async (e) => {
  // { action, commentId, text?, line?, end_line?, start_column?, end_column?, selection_text? }
  await saveComment(e.detail);
});

Events fired after user confirmation: mrsf:add, mrsf:reply, mrsf:edit, mrsf:resolve, mrsf:unresolve, mrsf:delete, mrsf:navigate, plus mrsf:submit (full payload). Disable the built-in UI by setting window.mrsfDisableBuiltinUi = true before loading the controller.

For async renderers such as Mermaid, the controller auto-refreshes gutter positions when the rendered DOM changes. If you want an explicit refresh after a render pass, call refreshAll() once Mermaid has finished:

ts
await mermaid.run();
refreshAll();

Released under the MIT License.