fix(response-viewer): lay out Persian, Arabic and Hebrew right to left (#715)

The Response Viewer and the File Viewer's markdown view gave no block a
dir, so a right-to-left answer was left-aligned with its punctuation on
the wrong end and its bullets and quote bar on the left.

_renderMarkdown now gives each outermost prose block dir="auto" (nested
blocks inherit, so a list keeps its markers on one side), pins pre and
code to dir="ltr", and keeps a dir the agent wrote. _linkifyFilePaths
pins the path anchors it creates to ltr. Because dir="auto" skips
descendants that carry a dir, code and paths no longer decide a
sentence's direction. The list indent, quote bar and table borders move
to logical properties, and the phone Compose textarea gets dir="auto".

The terminal pane is unchanged: xterm.js has no right-to-left support
(xtermjs/xterm.js#701).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer committed 2026-10-25 16:03:41 +01:00
1 parent 3e06f3c141
commit 538fcae708
5 files changed
+233 -7

No files matched your search

+26
View File
@@ -2835,6 +2835,29 @@ class CodemanApp {
a.setAttribute('target', '_blank');
a.setAttribute('rel', 'noopener noreferrer');
});
// Right-to-left text (issue #715). With no `dir`, every block was laid
// out left to right, so a Persian, Arabic or Hebrew answer was
// left-aligned, its punctuation landed on the wrong end and its lists
// and quotes hung off the left edge. Each OUTERMOST prose block now
// takes its direction from its own first letter (`dir="auto"`, what
// GitHub does for rendered markdown), so an RTL paragraph beside an
// English one reads correctly in both; nested blocks inherit, which
// keeps a list's markers and indent on one side. A `dir` the agent
// wrote (the sanitizer allows it) is kept, and so is what it covers.
//
// Code and preformatted text are always left to right. `dir="ltr"`
// also isolates them, and `dir="auto"` skips any descendant that
// carries a `dir`, so `npm install` at the head of a Persian sentence
// no longer turns the whole sentence left to right.
tmpl.content
.querySelectorAll('p, h1, h2, h3, h4, h5, h6, ul, ol, dl, blockquote, .rv-table-wrap')
.forEach((el) => {
if (el.parentElement?.closest('[dir]') || el.hasAttribute('dir')) return;
el.setAttribute('dir', 'auto');
});
tmpl.content.querySelectorAll('pre, code').forEach((el) => {
if (!el.hasAttribute('dir')) el.setAttribute('dir', 'ltr');
});
return tmpl.innerHTML;
} catch { /* fall through */ }
}
@@ -3064,6 +3087,9 @@ class CodemanApp {
link.dataset.path = path;
link.dataset.linkified = '1';
if (folder) link.dataset.folder = '1';
// A path reads left to right, and in a right-to-left sentence it must
// not vote on the sentence's direction (`_renderMarkdown`, issue #715).
link.dir = 'ltr';
link.title = path;
link.textContent = path;
frag.appendChild(link);