Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:AFK surf Open agent Markdown Block Conversion

From Leeroopedia
Knowledge Sources
Domains Markdown, Import_Export, BlockSuite
Last Updated 2026-10-25 00:00 GMT

Overview

Pattern of converting Markdown text to and from a block tree by parsing GFM via the remark/rehype/micromark pipeline and mapping mdast nodes to block flavors.

Description

BlockSuite uses the remark ecosystem to round-trip Markdown through its block model. On import, MarkdownTransformer.importMarkdownToBlock parses Markdown (GFM tables, task lists, autolinks, strikethrough via remark-gfm) into an mdast tree, walks the tree mapping nodes to block flavors (paragraph, list, code, table, quote, headings), and appends them as children of a note block via job.snapshotToBlock. On export, the inverse MarkdownTransformer.exportDoc serializes the block tree back to a Markdown string. Middlewares (defaultImageProxyMiddleware, docLinkBaseURLMiddleware) adapt image and doc-link handling. The pipeline is used by playground presets, linked-doc embeds, and import/export surfaces.

Usage

Apply this principle whenever you need to ingest Markdown into a live editor (imported docs, AI-generated text, pasted content) or serialize a block tree back to portable Markdown for storage, sharing, or version control.

Theoretical Basis

The conversion is an isomorphism (lossy in the general case) between two document models: mdast (Markdown AST) and BlockSnapshot (BlockSuite's portable block tree). The forward transform is parse(Markdown) → mdast → walk → BlockSnapshot[]; the reverse is walk(blocks) → mdast → stringify → Markdown. GFM extensions widen the parse grammar; middlewares adapt specific node kinds.

Pseudo-code:

// Forward:
await MarkdownTransformer.importMarkdownToBlock({ doc, blockId, markdown, extensions });
// Reverse:
await MarkdownTransformer.exportDoc(doc);

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment