Skip to content
PimigrationWeb1 file · +763 −33

Migrate Svelte markdown renderer from marked to @comark/svelte

Session from pi-web on Hugging Face by woxQAQ · MIT · condensed by Coders Talk

15msession
1interventions
GOAL

Replace the existing marked-based MarkdownRenderer with @comark/svelte, while preserving inline file references, Shiki code highlighting, and Mermaid diagram rendering.

  1. Prompt · +0
    Replace our existing markdown logic with @comark/svelte
  2. Agent did · +0m
    Explored existing MarkdownRenderer.svelte, its marked/DOMPurify/Shiki/Mermaid usage, and dug into @comark/svelte's package internals (Comark, ComarkNode, plugins, security options) to understand how to replicate current behavior.
  3. Agent did · +3m
    Checked git status before making changes and traced how MarkdownRenderer's dependencies (file references, theme, highlight) are used across ChatTranscript and other components.
  4. Intervention · +3m
    Agent found uncommitted changes in package.json and pnpm-lock.yaml not made by itself, stopped, and asked how to proceed. Developer just said 'continue'.
    Why: I wanted it to keep going without worrying about those files, they were probably from an earlier pnpm install for this same migration.
  5. Agent did · +8m
    Investigated Comark's security options (allowed link/image prefixes, unsafe tags), task-list plugin, and ran node scripts to test how comark's parse() outputs AST for markdown snippets like paragraphs and task lists.
  6. Agent did · +13m
    Rewrote MarkdownRenderer.svelte (731 lines) to use the Comark component with html:false, then made a follow-up edit reworking renderCodeBlocks to keep Shiki highlighting behavior intact.
  7. Agent did · +14m
    Ran pnpm build:web and svelte-check to validate the migration; build succeeded and svelte-check found 0 errors. Verified via grep that Comark import, file reference enhancement, code block rendering, and Mermaid rendering were all wired up.
  8. Outcome · +15m
    MarkdownRenderer migrated to @comark/svelte with file references, Shiki highlighting, and Mermaid diagrams preserved; build passed and svelte-check reported 0 errors.
VERDICT

I'd start by pointing out the uncommitted package.json/pnpm-lock.yaml changes myself so the agent doesn't have to pause and ask — that stop-and-ask was reasonable but cost time I could've saved with more context up front. The deep dive into @comark/svelte's internals (types, security options, plugin behavior) before writing any code is what made the rewrite work cleanly on the first pass, since build and svelte-check both passed with zero errors.

I tried this · 0

Discussion · 0

How Builds work