[PR #4489] [MERGED] Add right-to-left rendering support to the docs viewer #6397

Closed
opened 2026-10-23 04:10:02 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/4489
Author: @kolacheee
Created: 8/2/2026
Status: ✅ Merged
Merged: 8/3/2026
Merged by: @kolacheee

Base: staging ← Head: agent/docs-rtl-viewer


📝 Commits (5)

  • c029fb6 Add right-to-left rendering support to the docs viewer
  • 8277c71 Reference #4489 in the changelog entry
  • 52a7b53 Merge branch 'staging' into agent/docs-rtl-viewer
  • 0885af1 Merge branch 'staging' into agent/docs-rtl-viewer
  • 464518d Merge branch 'staging' into agent/docs-rtl-viewer

📊 Changes

6 files changed (+151 additions, -32 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/client/src/components/modals/DocsViewerModal.tsx (+46 -18)
📝 packages/client/src/lib/markdown.tsx (+12 -7)
📝 packages/client/src/styles/globals.css (+37 -6)
📝 packages/shared/src/constants/docs-languages.ts (+13 -0)
📝 scripts/regressions/docs-language.regression.ts (+42 -1)

📄 Description

Why

The Documentation Language roadmap has one language left: Arabic, the only right-to-left locale in the app's Language list. Rendering an RTL pack through today's viewer corrupts it in ways translators cannot write around — inside an RTL paragraph the bidi algorithm reorders code spans (--flag value renders as flag value--, {{char}} as }}char{{), fences inherit direction: rtl and scramble whole lines, list markers sit on the opposite side of their padding, and search highlights sever Arabic cursive joining mid-word. This PR lands the viewer-side groundwork first, on its own, so it can be regression-tested against the eleven shipped LTR packs before a single Arabic word exists. The scoping investigation behind it covered 18 items; the Arabic pack itself follows as the usual per-language docs-i18n cycle once this merges.

What

Shared (packages/shared/src/constants/docs-languages.ts)

  • DocsLanguageLabel gains an optional direction field ("ltr"/"rtl"); omitted means LTR, so the eleven existing rows are untouched.
  • New docsLanguageDirection(code) helper: unknown or unmarked codes read "ltr". The ar row itself is not added here — it ships with the Arabic pack so the selector never offers a language whose pack does not exist yet.

Markdown renderer (packages/client/src/lib/markdown.tsx, shared with chat)

  • Inline code and fenced blocks render dir="ltr" on the React-node path. The HTML string path deliberately carries no dir attribute: that path is re-sanitized by sanitizeChatHtml, whose attribute allowlist strips dir (verified against the real DOMPurify config), so its LTR forcing lives in the stylesheet instead (below). dir is intentionally NOT added to the sanitizer allowlist — that would let arbitrary card HTML flip text direction in chat.
  • Table alignment from :---/---: separators now emits logical start/end instead of left/right — identical in LTR, correct reading-order alignment in RTL.

Styles (packages/client/src/styles/globals.css)

  • List/table rules swap physical properties for logical ones (padding-inline-start, text-align: start, inset-inline-end).
  • .mari-md-codeblock and .mari-md-inline-code force direction: ltr in CSS — the only protection on the sanitized chat HTML path, and defence-in-depth everywhere else. Deliberately no text-align on the fence: direction alone realigns it, and a text-align would override card/theme CSS that chat honors today.
  • Links and strong runs get unicode-bidi: isolate scoped to a new .docs-reader-content class so embedded LTR runs (English UI labels, URLs) cannot drag punctuation around inside RTL docs prose. Scoped rather than on the shared .mari-message-content because isolation would change how existing RTL chat prose reorders.
  • .docs-search-mark loses its 0 0.1em inline padding with no substitute inset (native-find style): padding inside a word severs Arabic contextual letter forms and the lam-alef ligature at every highlight boundary, and a box-shadow replacement was measured to grow the tint vertically and double-paint where two marks abut. The docs reader also zeroes ==highlight== padding (.docs-reader-content .mari-md-highlight) for the same shaping reason — chat keeps its padded look.

Docs viewer (packages/client/src/components/modals/DocsViewerModal.tsx)

  • The reader pane sets dir from docsLanguageDirection(doc.language) — keyed off the served doc, not the pack, so an untranslated English fallback inside an RTL pack stays LTR.
  • Sidebar titles and search snippets get dir="auto"; file paths and the on-disk root get dir="ltr" so ellipsis/truncation clip the correct end; the search input gets dir="auto" for caret and clear-button placement.
  • Six physical Tailwind classes become logical (pe-1, ps-6, text-start, border-s/ps-3). These matter independently of docs direction: the app already flips <html dir="rtl"> under the Arabic UI locale, and the modal chrome mirrors with the rest of the app (kept deliberately — pinning the modal LTR inside a mirrored app would be incoherent).
  • Category headers keep their tracked small-caps look only when every header in the pack's sidebar is a script where letter-spacing is typographically safe (Latin, Greek, Cyrillic) — all-or-nothing per pack, so a mixed sidebar (e.g. Hindi's English "Game Mode" beside Devanagari labels) renders uniformly. Letter-spacing visibly severs Arabic cursive joining and misfit the shipped CJK/Hindi labels.
  • The updated-at footer line splits into isolated spans so an RTL UI locale cannot reorder the path against the date, and formatUpdatedAt now formats with the UI locale (resolvedLanguage precedent from relative-time.ts) instead of the browser locale, so the date always matches the language of the sentence around it.

Regressions (scripts/regressions/docs-language.regression.ts)

  • docsLanguageDirection contract: unknown/null/non-Latin-but-LTR codes → ltr; a declared rtl row → rtl.
  • Source pins: the reader must key direction off doc.language (never index.language); the JSX code paths must carry dir="ltr"; and the two code CSS rules must keep direction: ltr (the stylesheet is the only protection on the sanitized chat path).

Deliberate visible deltas for existing packs (exactly three)

  1. Search-highlight marks lose their slight inset (shaping safety).
  2. Sidebars whose category headers use non-Latin scripts (ja/ko/zh-hans/hi) drop the small-caps letter-spacing.
  3. "Last updated" dates follow the app language instead of the browser locale.

Everything else was verified as a rendering no-op for LTR packs and for chat, including by an adversarial review pass that measured candidate deltas in a live browser (that pass is what scoped the isolate rule away from chat, removed a redundant text-align, and replaced the originally planned box-shadow inset with the no-inset highlight).

What deliberately does NOT change

Search matching (already code-unit-literal and Arabic-safe), the server (no direction logic exists there), the language selectors, the chat sanitizer allowlist, the code-block Copy button (correct because fences are forced LTR), and the app-wide physical-CSS inventory outside this modal. The ar label-map row ships with the Arabic pack.

Validation

  • pnpm regression:docs — passes (direction contract + source/CSS pins included).
  • pnpm check — passes.
  • Runtime-verified against a synthetic two-file Arabic fixture pack (hazard-loaded: inline flags/braces/JSON, fences with Arabic comments, :---/---: tables, task lists, arrow paths, lam-alef search probes) materialized in a throwaway DATA_DIR. DOM/computed-style assertions all pass: reader pane rtl for the Arabic doc and ltr for the English fallback in the same pack; code spans byte-correct (--flag value, {{char}}, { "port": 7860 }, 7860-7870); list markers at inline start; table :---→start/---:→end with column 1 rightmost; search كتاب matching inside الكتاب with shaping-safe marks; and under an Arabic UI locale the modal chrome mirrors (border-s paints right) while English content stays LTR.

Summary by CodeRabbit

  • New Features

    • Added right-to-left support for documentation layouts, sidebars, search, highlights, tables, and lists.
    • Localized “Last updated” dates according to the selected interface language.
    • Improved typography for script-sensitive documentation headings.
    • Preserved left-to-right rendering for code and code snippets.
  • Bug Fixes

    • Improved direction fallback handling for unknown or missing language information.
  • Tests

    • Added regression coverage for RTL documentation and code rendering.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/4489 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 8/2/2026 **Status:** ✅ Merged **Merged:** 8/3/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `agent/docs-rtl-viewer` --- ### 📝 Commits (5) - [`c029fb6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c029fb6575d1e4acaffec6e2f33059b6de504a8a) Add right-to-left rendering support to the docs viewer - [`8277c71`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8277c718b8e470b563a08e9c91f7c11d890834a7) Reference #4489 in the changelog entry - [`52a7b53`](https://github.com/Pasta-Devs/Marinara-Engine/commit/52a7b53d72514bed9365c9a469c825dae22a5aaa) Merge branch 'staging' into agent/docs-rtl-viewer - [`0885af1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0885af117053f4784b857a2daa7838c3fe5bb30c) Merge branch 'staging' into agent/docs-rtl-viewer - [`464518d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/464518d2c04b14f79b2edace40bb10adb35c26ee) Merge branch 'staging' into agent/docs-rtl-viewer ### 📊 Changes **6 files changed** (+151 additions, -32 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/client/src/components/modals/DocsViewerModal.tsx` (+46 -18) 📝 `packages/client/src/lib/markdown.tsx` (+12 -7) 📝 `packages/client/src/styles/globals.css` (+37 -6) 📝 `packages/shared/src/constants/docs-languages.ts` (+13 -0) 📝 `scripts/regressions/docs-language.regression.ts` (+42 -1) </details> ### 📄 Description ## Why The Documentation Language roadmap has one language left: Arabic, the only right-to-left locale in the app's Language list. Rendering an RTL pack through today's viewer corrupts it in ways translators cannot write around — inside an RTL paragraph the bidi algorithm reorders code spans (`--flag value` renders as `flag value--`, `{{char}}` as `}}char{{`), fences inherit `direction: rtl` and scramble whole lines, list markers sit on the opposite side of their padding, and search highlights sever Arabic cursive joining mid-word. This PR lands the viewer-side groundwork first, on its own, so it can be regression-tested against the eleven shipped LTR packs before a single Arabic word exists. The scoping investigation behind it covered 18 items; the Arabic pack itself follows as the usual per-language `docs-i18n` cycle once this merges. ## What **Shared** (`packages/shared/src/constants/docs-languages.ts`) - `DocsLanguageLabel` gains an optional `direction` field (`"ltr"`/`"rtl"`); omitted means LTR, so the eleven existing rows are untouched. - New `docsLanguageDirection(code)` helper: unknown or unmarked codes read `"ltr"`. The `ar` row itself is **not** added here — it ships with the Arabic pack so the selector never offers a language whose pack does not exist yet. **Markdown renderer** (`packages/client/src/lib/markdown.tsx`, shared with chat) - Inline code and fenced blocks render `dir="ltr"` on the React-node path. The HTML string path deliberately carries **no** `dir` attribute: that path is re-sanitized by `sanitizeChatHtml`, whose attribute allowlist strips `dir` (verified against the real DOMPurify config), so its LTR forcing lives in the stylesheet instead (below). `dir` is intentionally NOT added to the sanitizer allowlist — that would let arbitrary card HTML flip text direction in chat. - Table alignment from `:---`/`---:` separators now emits logical `start`/`end` instead of `left`/`right` — identical in LTR, correct reading-order alignment in RTL. **Styles** (`packages/client/src/styles/globals.css`) - List/table rules swap physical properties for logical ones (`padding-inline-start`, `text-align: start`, `inset-inline-end`). - `.mari-md-codeblock` and `.mari-md-inline-code` force `direction: ltr` in CSS — the only protection on the sanitized chat HTML path, and defence-in-depth everywhere else. Deliberately no `text-align` on the fence: `direction` alone realigns it, and a `text-align` would override card/theme CSS that chat honors today. - Links and `strong` runs get `unicode-bidi: isolate` **scoped to a new `.docs-reader-content` class** so embedded LTR runs (English UI labels, URLs) cannot drag punctuation around inside RTL docs prose. Scoped rather than on the shared `.mari-message-content` because isolation would change how existing RTL chat prose reorders. - `.docs-search-mark` loses its `0 0.1em` inline padding with no substitute inset (native-find style): padding inside a word severs Arabic contextual letter forms and the lam-alef ligature at every highlight boundary, and a box-shadow replacement was measured to grow the tint vertically and double-paint where two marks abut. The docs reader also zeroes `==highlight==` padding (`.docs-reader-content .mari-md-highlight`) for the same shaping reason — chat keeps its padded look. **Docs viewer** (`packages/client/src/components/modals/DocsViewerModal.tsx`) - The reader pane sets `dir` from `docsLanguageDirection(doc.language)` — keyed off the **served** doc, not the pack, so an untranslated English fallback inside an RTL pack stays LTR. - Sidebar titles and search snippets get `dir="auto"`; file paths and the on-disk root get `dir="ltr"` so ellipsis/truncation clip the correct end; the search input gets `dir="auto"` for caret and clear-button placement. - Six physical Tailwind classes become logical (`pe-1`, `ps-6`, `text-start`, `border-s`/`ps-3`). These matter independently of docs direction: the app already flips `<html dir="rtl">` under the Arabic **UI** locale, and the modal chrome mirrors with the rest of the app (kept deliberately — pinning the modal LTR inside a mirrored app would be incoherent). - Category headers keep their tracked small-caps look only when **every** header in the pack's sidebar is a script where letter-spacing is typographically safe (Latin, Greek, Cyrillic) — all-or-nothing per pack, so a mixed sidebar (e.g. Hindi's English "Game Mode" beside Devanagari labels) renders uniformly. Letter-spacing visibly severs Arabic cursive joining and misfit the shipped CJK/Hindi labels. - The updated-at footer line splits into isolated spans so an RTL UI locale cannot reorder the path against the date, and `formatUpdatedAt` now formats with the UI locale (`resolvedLanguage` precedent from `relative-time.ts`) instead of the browser locale, so the date always matches the language of the sentence around it. **Regressions** (`scripts/regressions/docs-language.regression.ts`) - `docsLanguageDirection` contract: unknown/null/non-Latin-but-LTR codes → `ltr`; a declared `rtl` row → `rtl`. - Source pins: the reader must key direction off `doc.language` (never `index.language`); the JSX code paths must carry `dir="ltr"`; and the two code CSS rules must keep `direction: ltr` (the stylesheet is the only protection on the sanitized chat path). ## Deliberate visible deltas for existing packs (exactly three) 1. Search-highlight marks lose their slight inset (shaping safety). 2. Sidebars whose category headers use non-Latin scripts (ja/ko/zh-hans/hi) drop the small-caps letter-spacing. 3. "Last updated" dates follow the app language instead of the browser locale. Everything else was verified as a rendering no-op for LTR packs and for chat, including by an adversarial review pass that measured candidate deltas in a live browser (that pass is what scoped the isolate rule away from chat, removed a redundant `text-align`, and replaced the originally planned box-shadow inset with the no-inset highlight). ## What deliberately does NOT change Search matching (already code-unit-literal and Arabic-safe), the server (no direction logic exists there), the language selectors, the chat sanitizer allowlist, the code-block Copy button (correct because fences are forced LTR), and the app-wide physical-CSS inventory outside this modal. The `ar` label-map row ships with the Arabic pack. ## Validation - `pnpm regression:docs` — passes (direction contract + source/CSS pins included). - `pnpm check` — passes. - Runtime-verified against a synthetic two-file Arabic fixture pack (hazard-loaded: inline flags/braces/JSON, fences with Arabic comments, `:---`/`---:` tables, task lists, arrow paths, lam-alef search probes) materialized in a throwaway `DATA_DIR`. DOM/computed-style assertions all pass: reader pane `rtl` for the Arabic doc and `ltr` for the English fallback in the same pack; code spans byte-correct (`--flag value`, `{{char}}`, `{ "port": 7860 }`, `7860-7870`); list markers at inline start; table `:---`→start/`---:`→end with column 1 rightmost; search `كتاب` matching inside `الكتاب` with shaping-safe marks; and under an Arabic UI locale the modal chrome mirrors (`border-s` paints right) while English content stays LTR. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added right-to-left support for documentation layouts, sidebars, search, highlights, tables, and lists. * Localized “Last updated” dates according to the selected interface language. * Improved typography for script-sensitive documentation headings. * Preserved left-to-right rendering for code and code snippets. * **Bug Fixes** * Improved direction fallback handling for unknown or missing language information. * **Tests** * Added regression coverage for RTL documentation and code rendering. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:10:02 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#6397
No description provided.