Skip to content

Commit 8e7f514

Browse files
committed
fix(web): render Hebrew/Arabic chat markdown right-to-left
Every leaf block in .chat-markdown resolves its own base direction from its first strong character (unicode-bidi: plaintext + text-align: start), and lists / blockquotes / tables get dir="auto" so markers, the quote bar and column order land on the content's side. Physical paddings/borders on those containers become logical. Code stays LTR. No global flip: a mixed English/Hebrew message renders block by block.
1 parent f2d5fc9 commit 8e7f514

2 files changed

Lines changed: 45 additions & 11 deletions

File tree

‎apps/web/src/components/ChatMarkdown.tsx‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,12 +1563,16 @@ function ChatMarkdown({
15631563
String((props as Record<string, unknown>)["data-alert"] ?? "")
15641564
];
15651565
if (!alert) {
1566-
return <blockquote {...props}>{children}</blockquote>;
1566+
return (
1567+
<blockquote dir="auto" {...props}>
1568+
{children}
1569+
</blockquote>
1570+
);
15671571
}
15681572
// Not a <blockquote>: the stylesheet mutes those, and an alert's body is ordinary
15691573
// text under a colored title — which is how the host renders it.
15701574
return (
1571-
<div role="note" className={cn("my-1 border-l-2 pl-3", alert.borderClassName)}>
1575+
<div role="note" dir="auto" className={cn("my-1 border-s-2 ps-3", alert.borderClassName)}>
15721576
<p className={cn("flex items-center gap-1.5 font-medium", alert.titleClassName)}>
15731577
<alert.Icon aria-hidden className="size-3.5 shrink-0" />
15741578
{alert.label}
@@ -1583,9 +1587,20 @@ function ChatMarkdown({
15831587
.length ?? 0;
15841588
const gutterStyle = orderedListGutterStyle(itemCount, start);
15851589
return (
1586-
<ol {...props} start={start} style={gutterStyle ? { ...style, ...gutterStyle } : style} />
1590+
<ol
1591+
dir="auto"
1592+
{...props}
1593+
start={start}
1594+
style={gutterStyle ? { ...style, ...gutterStyle } : style}
1595+
/>
15871596
);
15881597
},
1598+
// `dir="auto"`: the browser picks each list's / quote's / table's base direction from its
1599+
// first strong character, so Hebrew/Arabic content gets its markers, bar and column order
1600+
// on the right while English blocks stay LTR (paired with the bidi rules in index.css).
1601+
ul({ node: _node, ...props }) {
1602+
return <ul dir="auto" {...props} />;
1603+
},
15891604
li({ node, children, ...props }) {
15901605
const listItemStart = node?.position?.start.offset;
15911606
const markerOffset =
@@ -1730,7 +1745,7 @@ function ChatMarkdown({
17301745
);
17311746
},
17321747
table({ node: _node, ...props }) {
1733-
return <MarkdownTable {...props} />;
1748+
return <MarkdownTable dir="auto" {...props} />;
17341749
},
17351750
details({ node: _node, children, open: detailsOpen }) {
17361751
return <MarkdownDetails open={detailsOpen}>{children}</MarkdownDetails>;

‎apps/web/src/index.css‎

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,24 @@ code {
15841584

15851585
/* Chat markdown rendering */
15861586

1587+
/* Bidi: Hebrew/Arabic messages. Every leaf block resolves its own base direction
1588+
from its first strong character (`plaintext`), so a Hebrew paragraph reads and
1589+
aligns right-to-left while the English block above it stays put — no global
1590+
flip, mixed-language threads just work. Containers that carry a directional
1591+
decoration (list markers, blockquote bar, table column order) get `dir="auto"`
1592+
in ChatMarkdown.tsx and use logical properties below. Code stays LTR. */
1593+
.chat-markdown :is(p, li, h1, h2, h3, h4, h5, h6, td, th, dt, dd) {
1594+
unicode-bidi: plaintext;
1595+
text-align: start;
1596+
}
1597+
1598+
.chat-markdown pre,
1599+
.chat-markdown code,
1600+
.chat-markdown .chat-markdown-codeblock {
1601+
direction: ltr;
1602+
unicode-bidi: isolate;
1603+
}
1604+
15871605
.chat-markdown > :first-child {
15881606
margin-top: 0;
15891607
}
@@ -1640,7 +1658,7 @@ code {
16401658
custom property, so without this a task-list under a 3+ digit ordered
16411659
list would inherit the outer gutter instead of its own default. */
16421660
--list-gutter: 1.25rem;
1643-
padding-left: 1.25rem;
1661+
padding-inline-start: 1.25rem;
16441662
list-style-type: disc;
16451663
}
16461664

@@ -1651,7 +1669,7 @@ code {
16511669
nested ol without its own widened marker doesn't inherit the outer one. */
16521670
.chat-markdown ol {
16531671
--list-gutter: 1.25rem;
1654-
padding-left: var(--list-gutter, 1.25rem);
1672+
padding-inline-start: var(--list-gutter, 1.25rem);
16551673
list-style-type: decimal;
16561674
}
16571675

@@ -1681,7 +1699,8 @@ code {
16811699
}
16821700

16831701
.chat-markdown li.task-list-item input[type="checkbox"] {
1684-
margin: 0 0.35em 0.15em calc(-1 * var(--list-gutter, 1.25rem));
1702+
margin-block: 0 0.15em;
1703+
margin-inline: calc(-1 * var(--list-gutter, 1.25rem)) 0.35em;
16851704
vertical-align: middle;
16861705
}
16871706

@@ -1705,8 +1724,8 @@ code {
17051724
}
17061725

17071726
.chat-markdown blockquote {
1708-
border-left: 2px solid var(--border);
1709-
padding-left: 0.8rem;
1727+
border-inline-start: 2px solid var(--border);
1728+
padding-inline-start: 0.8rem;
17101729
color: var(--muted-foreground);
17111730
}
17121731

@@ -1720,7 +1739,7 @@ code {
17201739

17211740
.chat-markdown section[data-footnotes] ol {
17221741
margin: 0;
1723-
padding-left: 1.25rem;
1742+
padding-inline-start: 1.25rem;
17241743
}
17251744

17261745
.chat-markdown section[data-footnotes] li + li {
@@ -1832,7 +1851,7 @@ code {
18321851
.chat-markdown th,
18331852
.chat-markdown td {
18341853
padding: 0.45rem 0.75rem;
1835-
text-align: left;
1854+
text-align: start;
18361855
}
18371856

18381857
.chat-markdown thead th {

0 commit comments

Comments
 (0)