diff --git a/.github/ci-paths.yml b/.github/ci-paths.yml index 87fc924b6..baf6de02e 100644 --- a/.github/ci-paths.yml +++ b/.github/ci-paths.yml @@ -50,6 +50,7 @@ desktop: app: - "packages/app/**" - "packages/expo-two-way-audio/**" + - "packages/react-native-enriched-markdown/**" sdk: - "packages/plugin/**" @@ -80,6 +81,7 @@ browser: - "packages/app/index.ts" - "packages/app/*config.{cjs,js,ts}" - "packages/app/package.json" + - "packages/react-native-enriched-markdown/**" relay: - "packages/relay/**" diff --git a/.oxfmtrc.json b/.oxfmtrc.json index 5838c7dc1..e5fab8507 100644 --- a/.oxfmtrc.json +++ b/.oxfmtrc.json @@ -11,5 +11,10 @@ "arrowParens": "always", "bracketSameLine": false, "bracketSpacing": true, - "ignorePatterns": ["*.lock", "**/*.gen.ts", "**/*.gen.tsx"] + "ignorePatterns": [ + "*.lock", + "**/*.gen.ts", + "**/*.gen.tsx", + "packages/react-native-enriched-markdown/**" + ] } diff --git a/.oxlintrc.json b/.oxlintrc.json index fdbb91730..474a249b0 100644 --- a/.oxlintrc.json +++ b/.oxlintrc.json @@ -3,7 +3,7 @@ "options": { "typeAware": false }, - "ignorePatterns": [".dev/**"], + "ignorePatterns": [".dev/**", "packages/react-native-enriched-markdown/**"], "plugins": ["react", "react-perf", "unicorn", "typescript", "oxc", "import", "promise"], "jsPlugins": ["./scripts/oxlint/paseo-plugin.mjs"], "categories": { diff --git a/CLAUDE.md b/CLAUDE.md index 1496bd407..e188836ab 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -56,7 +56,7 @@ At the start of non-trivial work, list `docs/` and skim anything relevant to the | [docs/terminal-rendering.md](docs/terminal-rendering.md) | Native terminal view: xterm owns the grid, cluster placement, emoji widths, mixed-direction limits, render regression | | [docs/agent-stream-performance.md](docs/agent-stream-performance.md) | Assistant text pipeline — coalescing window, paced reveal, why arrival lumps are smoothed at render | | [docs/agent-stream-disclosure.md](docs/agent-stream-disclosure.md) | Expand/collapse in the chat timeline — hold contract, native anchor sequence, frame spacing, render-window cost | -| [docs/markdown-renderer.md](docs/markdown-renderer.md) | Shared Markdown engine, native selection, links, images and library constraints | +| [docs/markdown-renderer.md](docs/markdown-renderer.md) | Shared Markdown engine, the vendored library fork, native selection, links, images and library constraints | | [docs/native-text-selection.md](docs/native-text-selection.md) | Native diagram grouping, selection boundaries and leading inline image limitations | | [docs/file-observation.md](docs/file-observation.md) | Recursive watcher ownership, Linux constraints, teardown invariants, and Parcel comparison | | [docs/testing.md](docs/testing.md) | TDD workflow, determinism, real dependencies over mocks, test organization | diff --git a/docs/markdown-renderer.md b/docs/markdown-renderer.md index 1bde975d2..5f7a3d1af 100644 --- a/docs/markdown-renderer.md +++ b/docs/markdown-renderer.md @@ -14,19 +14,38 @@ Workspace file links use the shared file-link resolver. The workspace supplies i 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 (local patch in `patches/react-native-enriched-markdown+*.patch`). +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](https://github.com/software-mansion/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`. A parser change rebuilds them with upstream's `packages/core/cpp/wasm/build.sh`. +- 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](https://github.com/software-mansion/enriched-markdown/pull/924) | after `1.2.0-nightly-20261019-926ef06f0` | +| Android nested list items start their text after their own marker | [#1015](https://github.com/software-mansion/enriched-markdown/pull/1015), [#1023](https://github.com/software-mansion/enriched-markdown/pull/1023) (Android) | `1.2.0` | ## Engine constraints -The pinned nightly has the same React Native package and core source trees as upstream commit `73ac5085eb1fdc743973b3473d4dba65abad5261`. Compatibility was checked with React Native 0.81.5. Native dependencies must be rebuilt when changing the highlighting configuration; JavaScript refresh cannot enable compiled grammars. - 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. 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](native-text-selection.md) for diagram grouping and leading inline images. Streaming keeps the last valid diagram visible while the next revision renders. -Native code blocks use the library's copy control and compiled grammars. Web code blocks use `HighlightedCodeBlock` through the library's `renderers.codeBlock` override. 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 patch 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. The package patch is tracked by [upstream PR #997](https://github.com/software-mansion/enriched-markdown/pull/997); remove the patch when the pinned release includes it. +Native code blocks use the library's copy control and compiled grammars. Web code blocks use `HighlightedCodeBlock` through the library's `renderers.codeBlock` override. 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](https://github.com/software-mansion/enriched-markdown/pull/997) tracks these changes. -The package patch 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. +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](https://github.com/software-mansion/enriched-markdown/issues/1131) is resolved. diff --git a/knip.json b/knip.json index e4f5cec73..0879c2862 100644 --- a/knip.json +++ b/knip.json @@ -72,6 +72,7 @@ "project": ["src/**/*.ts"] } }, + "ignoreWorkspaces": ["packages/react-native-enriched-markdown"], "ignoreDependencies": [ "sherpa-onnx-node", "@playwright/test", diff --git a/nix/desktop-package.nix b/nix/desktop-package.nix index 48cbd9bbb..fe4515ad7 100644 --- a/nix/desktop-package.nix +++ b/nix/desktop-package.nix @@ -30,6 +30,8 @@ buildNpmPackage { # Exclude mobile-only platform code (we only need the web/electron build) !(lib.hasPrefix "/packages/app/android" relPath) && !(lib.hasPrefix "/packages/app/ios" relPath) + && !(lib.hasPrefix "/packages/react-native-enriched-markdown/android" relPath) + && !(lib.hasPrefix "/packages/react-native-enriched-markdown/ios" relPath) # Website is unrelated to the desktop app && !(lib.hasPrefix "/packages/website" relPath) # Documentation, CI definitions and agent/editor configuration. None of diff --git a/package-lock.json b/package-lock.json index 2294a85b3..7fcf3f35f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "workspaces": [ "plugins", "packages/expo-two-way-audio", + "packages/react-native-enriched-markdown", "packages/highlight", "packages/plugin", "packages/protocol", @@ -31902,6 +31903,10 @@ "react-native": "*" } }, + "node_modules/react-native-enriched-markdown": { + "resolved": "packages/react-native-enriched-markdown", + "link": true + }, "node_modules/react-native-gesture-handler": { "version": "2.32.0", "resolved": "https://registry.npmjs.org/react-native-gesture-handler/-/react-native-gesture-handler-2.32.0.tgz", @@ -37561,7 +37566,7 @@ "react-native": "0.86.3", "react-native-draggable-flatlist": "^4.0.3", "react-native-edge-to-edge": "^1.7.0", - "react-native-enriched-markdown": "1.2.0-nightly-20261014-766fc0e67", + "react-native-enriched-markdown": "*", "react-native-gesture-handler": "~2.32.0", "react-native-keyboard-controller": "1.21.12", "react-native-nitro-modules": "0.35.5", @@ -39474,23 +39479,6 @@ "dev": true, "license": "MIT" }, - "packages/app/node_modules/react-native-enriched-markdown": { - "version": "1.2.0-nightly-20261014-766fc0e67", - "resolved": "https://registry.npmjs.org/react-native-enriched-markdown/-/react-native-enriched-markdown-1.2.0-nightly-20261014-766fc0e67.tgz", - "integrity": "sha512-PyYAAVJAyjlcqHXgSnzxok13MDmyxs/nt46hHIOBdCc0prfaL2Ef6nYkZu7fFCeaETOJXd/xQr4n2/79I+gvdA==", - "hasInstallScript": true, - "license": "MIT", - "peerDependencies": { - "katex": ">=0.16.0", - "react": "*", - "react-native": "*" - }, - "peerDependenciesMeta": { - "katex": { - "optional": true - } - } - }, "packages/app/node_modules/react-native-keyboard-controller": { "version": "1.21.12", "resolved": "https://registry.npmjs.org/react-native-keyboard-controller/-/react-native-keyboard-controller-1.21.12.tgz", @@ -40303,6 +40291,21 @@ "node": ">=10" } }, + "packages/react-native-enriched-markdown": { + "version": "0.17.1", + "hasInstallScript": true, + "license": "MIT", + "peerDependencies": { + "katex": ">=0.16.0", + "react": "*", + "react-native": "*" + }, + "peerDependenciesMeta": { + "katex": { + "optional": true + } + } + }, "packages/relay": { "name": "@getpaseo/relay", "version": "0.17.3", diff --git a/package.json b/package.json index 315249878..8ea1d2792 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "workspaces": [ "plugins", "packages/expo-two-way-audio", + "packages/react-native-enriched-markdown", "packages/highlight", "packages/plugin", "packages/protocol", diff --git a/packages/app/e2e/mobile/markdown-formatting/README.md b/packages/app/e2e/mobile/markdown-formatting/README.md index 28cdb87c6..51f9fbe86 100644 --- a/packages/app/e2e/mobile/markdown-formatting/README.md +++ b/packages/app/e2e/mobile/markdown-formatting/README.md @@ -28,12 +28,13 @@ bounds cannot establish measurement parity. compares them with the shipped headers. This catches missing C++ fields in the measurement path, which the Kotlin tests cannot exercise. -The package patch contains `InlineCodeFormattingTest`, which exercises actual -Android spans in Robolectric native graphics mode, covering draw and measurement, -span order, code inside paragraph/heading sizes, bold/italic composition, and -links preserving code and emphasized prose fonts. -It runs in the existing `test:android` CI job. To run only this regression locally, -from `packages/app/android` after Expo prebuild: +The vendored library (`packages/react-native-enriched-markdown`) contains +`InlineCodeFormattingTest`, which exercises actual Android spans in Robolectric +native graphics mode, covering draw and measurement, span order, code inside +paragraph/heading sizes, bold/italic composition, and links preserving code and +emphasized prose fonts. It runs in `npm run test:android`; CI does not run it. +To run only this regression locally, from `packages/app/android` after Expo +prebuild: ```sh ./gradlew :react-native-enriched-markdown:testDebugUnitTest \ diff --git a/packages/app/package.json b/packages/app/package.json index d2ee413ce..43703353d 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -40,7 +40,7 @@ "dev:ios": "npm --prefix ../.. run build:client && cross-env APP_VARIANT=development expo run:ios", "build:apk": "npm --prefix ../.. run build:apk", "build:apk:arm64": "npm --prefix ../.. run build:apk:arm64", - "test:android": "expo prebuild --platform android --no-install && cd android && ./gradlew :paseo-native-trace:testReleaseUnitTest :paseo-hardware-keyboard:testReleaseUnitTest :react-native-enriched-markdown:testReleaseUnitTest --tests '*InlineCodeFormattingTest' --no-daemon --max-workers=2 -Dorg.gradle.parallel=false" + "test:android": "expo prebuild --platform android --no-install && cd android && ./gradlew :paseo-native-trace:testReleaseUnitTest :paseo-hardware-keyboard:testReleaseUnitTest :react-native-enriched-markdown:testReleaseUnitTest --tests '*InlineCodeFormattingTest' --tests '*ListRenderingTest' --tests '*TaskListInteractionTest' --tests '*ListBlockquoteMeasurementTest' --no-daemon --max-workers=2 -Dorg.gradle.parallel=false" }, "dependencies": { "@codemirror/commands": "6.10.4", @@ -125,7 +125,7 @@ "react-native": "0.86.3", "react-native-draggable-flatlist": "^4.0.3", "react-native-edge-to-edge": "^1.7.0", - "react-native-enriched-markdown": "1.2.0-nightly-20261014-766fc0e67", + "react-native-enriched-markdown": "*", "react-native-gesture-handler": "~2.32.0", "react-native-keyboard-controller": "1.21.12", "react-native-nitro-modules": "0.35.5", diff --git a/packages/react-native-enriched-markdown/.gitignore b/packages/react-native-enriched-markdown/.gitignore new file mode 100644 index 000000000..79ebd0345 --- /dev/null +++ b/packages/react-native-enriched-markdown/.gitignore @@ -0,0 +1,10 @@ +# Native assets the postinstall script downloads (see postinstall.mjs). +/cpp/highlight/vendor/grammars/ +/cpp/highlight/vendor/tree-sitter/ +/ios/vendor/ +/ios/vendor.staging/ +/ios/vendor.backup/ + +# Android build output when Gradle builds this library from source. +/android/.cxx/ +/android/.gradle/ diff --git a/packages/react-native-enriched-markdown/LICENSE b/packages/react-native-enriched-markdown/LICENSE new file mode 100644 index 000000000..8d7210586 --- /dev/null +++ b/packages/react-native-enriched-markdown/LICENSE @@ -0,0 +1,20 @@ +MIT License + +Copyright (c) 2025 Software Mansion +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/react-native-enriched-markdown/README.md b/packages/react-native-enriched-markdown/README.md new file mode 100644 index 000000000..9bb27e015 --- /dev/null +++ b/packages/react-native-enriched-markdown/README.md @@ -0,0 +1,287 @@ + + + + Enriched Markdown by Software Mansion + + + + + +# react-native-enriched-markdown + +`react-native-enriched-markdown` is a powerful React Native library that renders Markdown content as native text and provides a rich text input with Markdown output. It supports iOS, Android, macOS, and Web, and requires the New Architecture (Fabric) for native platforms. + +### EnrichedMarkdownText + +- ⚡ Fully native text rendering (no WebView) +- 🌐 Web support via [react-native-web](https://necolas.github.io/react-native-web/) + [md4c](https://github.com/mity/md4c) compiled to WebAssembly +- 🎯 High-performance Markdown parsing with [md4c](https://github.com/mity/md4c) +- 📐 CommonMark standard compliant +- 📊 GitHub Flavored Markdown (GFM) +- 🧮 LaTeX math rendering (block `$$...$$` with `flavor="github"`, inline `$...$` in all flavors) +- 🔀 [Markdown Streaming](../../docs-md/MARKDOWN_STREAMING.md) support (via [react-native-streamdown](https://github.com/software-mansion-labs/react-native-streamdown)) +- 🎨 Fully customizable styles for all elements +- ✨ Text selection and copy support +- 📌 Custom text selection context menu items +- 🔗 Interactive link handling with [per-URL-pattern styling](../../docs-md/MENTIONS.md#link-variants-styling) (`linkVariants`) +- 💊 [Native link pills](../../docs-md/MENTIONS.md#native-link-pills) — links as rounded chips with an icon and label, per URL pattern or per link (iOS, Android) +- 📎 [Long-press menus for links](../../docs-md/API_REFERENCE.md#linkcontextmenuitems) with your own items per URL pattern (`linkContextMenuItems`, iOS 17+) +- 👤 Renders mentions as styled links (compatible with `EnrichedMarkdownTextInput` mention output) +- 🙈 Spoiler text with animated particle overlay and tap-to-reveal +- 🖼️ Native image interactions (iOS: Copy, Save to Camera Roll) +- 🎬 Native video playback — block-level videos via HTML `