Files
paseo/docs/markdown-renderer.md
T
Galaxy RoamingandMohamed Boudra bd20e3fe98 fix(app): keep Markdown table <br> line breaks inside their cells (#9587)
* fix(app): keep Markdown table <br> line breaks inside their cells

* fix(app): scan HTML table wrappers in a single forward pass

* fix(app): preserve tag-only line prefixes before wrapped tables

* fix(app): pad <br> U+2028 separator on both sides for flanking emphasis

* build(app): rebuild the Markdown web parser with table cell line breaks

The engine moved into the repository, so the table cell change now lives
once in cpp/parser/MD4CParser.cpp and web gets it from a rebuilt WASM
instead of a second TypeScript pass over the parsed tree. Built with
emsdk 4.0.10; a build of the unchanged sources parses every Markdown file
in the repository the same as the previous artifact.

The parser now autolinks a bare URL after a table cell break, as it does
the first one. Sources without `<br` skip the extra table parse.

Co-authored-by: Ouyang Xingyuan <galaxyroaming@qq.com>

* fix(app): keep table cell line breaks when copying a table

A table cell can now hold a line break, but the copy paths wrote it as a
newline, which splits the Markdown row. Web selection copy and the native
serializers write it back as `<br>`. The native row accessibility label
joined the two lines into one word, so it now reads them apart.

---------

Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
2026-11-30 17:16:48 +07:00

15 KiB
Raw Blame History

Markdown rendering

Use MarkdownRenderer for chat replies, file previews, plans, pull requests and changelog content. It uses react-native-enriched-markdown on iOS, Android and web. Keep source adaptation and renderer configuration in components/markdown; consumers supply Markdown and, when needed, its file location.

Native selection belongs to the library's text view. Keep an assistant message in one row so selection can cross paragraphs, headings and lists. Code blocks and tables use the library's native views and their selection behavior. Web uses browser selection over semantic HTML. Once its WASM parser is initialized, the library parses synchronously for the first commit of each mounted row; an empty interim row would corrupt virtualized measurements and move the reader. Chat owns paced reveal, the web render cap, message identity and list measurement. Native renders completed messages together. While streaming, it keeps closed blocks in one head view and updates a separate tail, then reunites the text on completion. See native parsing cost for the boundary and pacing constraints.

Block spacing

Every block is separated by one gap, density.blockGap: 12 on compact layouts, 16 wider. Inside the library's text, every element style ends with that gap and the library drops it after the last block. Views stacked outside the library (Mermaid segments, streaming head and tail) use the same gap through MarkdownBlockStack. Do not give a block type its own margins; change the gap.

Workspace file links use the shared file-link resolver. The workspace supplies its client, root and open-file action once; chat can supply the agent's more specific context. URLs use the same link press path. Recognized inline-code paths stay tappable. The library callback carries the tapped occurrence’s syntax context. Preserve it when opening files: explicit Markdown links decode URL escapes, while recognized inline-code paths preserve literal percent characters and use suffix lookup. Identical URL strings in different occurrences must stay distinct. Explicit absolute workspace links receive a relative hover title; existing authored titles remain intact. Inside a workspace, forge references such as #12 and owner/repo#12 are recognized in prose (not code) and open the workspace forge; the reference pattern comes before path recognition so group/project#12 is not read as a path. See forge providers.

Right-click on web and long press on native open one link menu per rendered part (components/markdown/link-menu), not one per link: a menu root cannot sit inside a paragraph without producing invalid markup on web. The native long-press event carries only the URL, with no position and no syntax context. The menu takes the position from the touch that started the press, and treats a URL that is no ](destination) in the source as recognized text.

Pass external for author-controlled Markdown from outside the host, such as a plugin README. It follows the registry's overview contract in packages/protocol/src/plugin-overview.ts, which the website also uses: only absolute https links and images work, and any other destination renders as its label or alt text. The parser still autolinks bare http://, www. and email text, so a link press checks the URL again and opens only https. None of the workspace recognition above applies, so Node.js is prose, not a file. The lines of a paragraph join, as they do on the README's forge.

Resolve workspace image paths over the existing session RPC, then give the library a cached native file URL or web blob URL. HTTP(S) images pass through unchanged. This preserves relay, SSH and local socket connections, which do not expose a daemon HTTP endpoint. Each mounted renderer owns its image acquisition identity, so a later reply reads a rewritten path again while the earlier mounted reply retains its snapshot. Image taps open the attachment lightbox. File previews resolve relative images against the Markdown file's directory. An image alone on its line becomes its own paragraph before the library sees it, so it renders as a block on every platform; the library only treats sole-child paragraph images as blocks, and with hard soft breaks every newline is a break node, which left own-line images inline on iOS and web. Images that share a line with text stay inline at line height and keep their aspect ratio. A linked image counts as an image, so review-bot badges such as [![Retrigger](badge.svg)](url) Confidence stay inline on web; the library's web renderer only checked direct paragraph children, so it rendered them as full-width block images (fixed in the fork).

The fork

The library is a private workspace, packages/react-native-enriched-markdown. It is upstream enriched-markdown at npm 1.2.0-nightly-20261014-766fc0e67 (upstream commit 766fc0e67) plus Paseo's changes, which lived in a patch-package patch until the package moved into the repository. It is never published. Keep the name react-native-enriched-markdown: autolinking, the Gradle project :react-native-enriched-markdown, the CocoaPods spec and app imports all use it.

The package keeps the npm tarball's layout, including its build output:

  • Metro, Vitest and TypeScript load lib/, not src/. A JavaScript change edits src/ and the matching lib/module and lib/typescript files.
  • android/generated and ios/generated are checked-in codegen output (includesGeneratedCode). A change to a native component spec regenerates both; scripts/postinstall-patches.test.mjs compares them against the specs.
  • src/web/wasm/md4c.js and lib/module/web/wasm/md4c.js are an Emscripten build of cpp/md4c, cpp/parser and cpp/wasm. A parser change rebuilds both, or web keeps the old behavior while iOS and Android change. Run cpp/wasm/build.sh with OUT_DIR set to src/web/wasm, in emscripten/emsdk:4.0.10 with the -s GROWABLE_ARRAYBUFFERS=0 line removed. That version reproduces the committed JavaScript glue and has no such setting. The lib/module copy is the Babel output of the new file.
  • Upstream's Gradle, CMake and CocoaPods scripts detect upstream's own monorepo by the paths packages/core and a root vendor/. Do not add either path to this repository.
  • postinstall.mjs downloads the tree-sitter grammars into the ignored cpp/highlight/vendor/grammars and vendor/tree-sitter. The enriched-markdown block in packages/app/package.json chooses the languages.

CI does not build native code or run the fork's Robolectric suites. Run npm run test:android --workspace=@getpaseo/app for Android changes. Native changes require a client rebuild; JavaScript refresh cannot enable compiled grammars.

Some fork changes are backports. A sync past the upstream version drops them in favour of upstream's code:

Fork change Upstream Released in
Android measurements survive parent clones #924 after 1.2.0-nightly-20261019-926ef06f0
Android long-press drag selection keeps parent intercept disallowed #1012 1.2.0
Android nested list items start their text after their own marker #1015, #1023 (Android) 1.2.0

Engine constraints

Math and video are disabled. Task lists and admonitions are enabled; task checkboxes are read-only. Source adaptation spaces adjacent empty GFM table delimiters before escaping prose spoiler delimiters and decodes entity text before the engine can discard it. Code spans and fences keep their literal source. Comment HTML is normalized to Markdown before parsing; details show their summary and body expanded. <br> becomes a Markdown hard break, except inside a table, where a newline would end the row. There it becomes U+2028, and cpp/parser/MD4CParser.cpp turns U+2028 back into a line break in table cell text, never in code.

Mermaid fences use the existing isolated diagram runtime and fullscreen viewer. Web dispatches them through the library’s code-block override. Native has no block-renderer hook, so the renderer extracts only Mermaid fences and places the existing WebView host between library-rendered segments. This is the only block exception; see native selection limitations for diagram grouping and leading inline images. Streaming keeps the last valid diagram visible while the next revision renders.

Code blocks and plain quotes have a copy control in their top trailing corner. Native code blocks use the library's compiled grammars. On native, the code block and quote container views share one control (HeaderCopyButton on Android, ENRMHeaderCopyButton on iOS). A quote reserves the code block's header band above its body, so the control never covers quote text at any font size. On web, code blocks use HighlightedCodeBlock through the library's renderers.codeBlock override, and quotes use WebBlockquote through renderers.blockquote. Both use BlockCopyButton. On compact layouts the control is always visible, so the web quote reserves a band above its body, as native does. On wide layouts the control appears on hover or focus, so the quote keeps a right gutter instead; a band there would leave an empty strip above every quote.

A quote copies its body without the > markers, with its nested Markdown, and reads the content at the time of the press, so a streaming quote copies what it shows. A nested quote or code block keeps its own control. Web quote copy uses the same two clipboard flavors as selection copy: text/plain is unescaped Markdown and text/html is rendered from escaped Markdown. A rendered Mermaid diagram copies as its fence because its wrapper carries the fence source. Native quote copy serializes the quote's parsed Markdown, so a workspace image copies as its cached file URL, as native selection copy does; native has no map back to the workspace path. A native Mermaid diagram in a quote renders outside it (see native selection limitations), so each quote fragment copies only its own text. Admonitions get no control: web renders them with a separate library renderer. On web an admonition inside a copied quote copies as its > [!TYPE] source; the fork marks the box and its generated title for this. Selection copy keeps the text it shows, because the cloned range cannot tell a whole callout from part of one. On native, quotes inside list items get no control, because they render as text spans in the item. Web renders them as blocks, so they get one.

Selection copy has to tell links Paseo recognized in the text (paths, forge references, code spans) from links in the Markdown, so the web link renderer marks the recognized ones. Plain-text paste carries them as the text the reply showed, and rich paste keeps them as links only when they point to an http or https URL. Authored links and parser autolinks such as a bare www.example.com copy as links. The fork also keeps the library's block spacing around the web code block override, preserves web list numbering and link titles, marks pending parses with aria-busy so Find waits for rendered text, and carries link syntax through native and web tap events. Web inline code inside a link inherits only the link colour; its code font, size and background stay intact. Keep link variants colour-only: native pills replace text runs and prevent paths from wrapping; Android pills also use the surrounding block’s font size. Upstream PR #997 tracks these changes.

The fork also keeps overflowing native horizontal blocks in control of their drags: Android claims parent interception at touch-down and releases it for vertical drags so the chat list can scroll; iOS keeps its scroll recognizer active for outward drags at the leading edge. This prevents compact sidebar pans from taking block scrolling without changing sidebar swipes on prose or non-overflowing blocks. Native changes require a client rebuild.

On iOS a newly mounted Markdown view paints empty for a frame or more after it is laid out at its measured height: the library parses even a view's first content on a background queue and applies it in a later main-queue turn. Expanding a turn in chat therefore shows its rows in place with the text arriving a frame later (165 ms when the mount keeps the main thread busy). Android paints the text in the first frame. Rendering a view's first content synchronously fixes the frame but costs frame time when a fling mounts history rows, so the app keeps the library's behavior until enriched-markdown #1131 is resolved.

Android measurements use a size-only, 512-entry LRU across view unmounts, matching the library’s existing iOS cache. Scrolling back through history can reuse layout sizes without parsing those rows again. Content, layout props and width identify each entry; font-scale changes and native layout invalidation discard affected sizes. The cache retains no views or spans.

The library determines how incomplete Markdown appears during streaming. Completed text uses the same component and engine as history. Find and scroll-to-message address source message ids; selection-copy understands semantic HTML and the web code component's copy metadata.

Verification

Follow QA and mobile testing. Exercise chat, file preview, plan and PR content on all three platforms. Include cross-paragraph selection, progressive streaming, a file-link tap, code copy/highlighting, quote copy (nested quote, code block in a quote, admonition, large font on native), a table and a workspace image. On iPad, repeat preview selection after opening and closing Explorer and after rotation. Check web find, selection-copy and source-message navigation after DOM changes.