Skip to content

Gnome: bidi-isolate inline code in RTL MDX views#125

Open
JumpLink wants to merge 1 commit into
mainfrom
fix/117-rtl-punctuation-isolation
Open

Gnome: bidi-isolate inline code in RTL MDX views#125
JumpLink wants to merge 1 commit into
mainfrom
fix/117-rtl-punctuation-isolation

Conversation

@JumpLink

Copy link
Copy Markdown
Owner

Fixes #117

Problem

In RTL locales, neutral characters (quotes, dots, colons) next to LTR runs could resolve to the wrong side. The root cause for the asymmetric case reported in #117: when punctuation sits between two LTR runs — typically an inline-code mnemonic and a following English word — the Unicode bidi algorithm joins everything into one left-to-right run.

Real example from the Hebrew tutorial (<tt>BNE</tt>: "Branch on not equal" inside a Hebrew sentence): the colon and the opening quote stuck to the LTR run while the closing quote correctly resolved right-to-left — exactly the "quote before but not after LTR letters" asymmetry described in the issue.

Note: the simpler cases from the issue (punctuation between an LTR run and Hebrew text, or at line end) were already fixed by the RTL paragraph direction from #121; this PR fixes the remaining run-joining case.

Fix

In MdxView.applyRtlBaseDirection, additionally wrap the content of <tt> spans in FIRST STRONG ISOLATE (U+2066–U+2069 family: FSI U+2068 / PDI U+2069) characters. Isolated runs are treated as neutral by the surrounding text, so all adjacent punctuation now resolves uniformly against the RTL paragraph direction, while the bidi algorithm still renders the isolated code itself left-to-right. FSI (first-strong) is used instead of LRI so the span direction always derives from its content. The transform is idempotent.

Verification

GJS integration test loading the real generated tutorial.ui with the real Hebrew translations and Gtk.TextDirection.RTL (mirroring the #121 methodology):

without fix with fix
Labels with Hebrew text 144 144
Hebrew labels with <tt> spans 84 84
Spans bidi-isolated 0 84
Labels with broken Pango markup 0 0
Hebrew labels rendered LTR (#116 regression check) 0 0
BNE paragraph: colon RTL-positioned
BNE paragraph: quotes hug the quoted phrase symmetrically

Glyph positions verified via PangoLayout.index_to_pos on the rendered labels.

Also passing: yarn format, yarn check:format, yarn build, app-gnome type check (blueprint validation included).

Notes

  • Code blocks (SourceView) keep their intentional LTR layout, unchanged.
  • The Android app renders the same MDX content with TextView/HTML and likely needs an equivalent fix — separate follow-up, same as noted in Gnome: force RTL base direction in MDX views #121.

Neutral punctuation between an LTR inline-code span and an adjacent
LTR word joined both into one left-to-right run, so quotes, dots and
colons jumped to their LTR position inside RTL text - e.g. in
'<tt>BNE</tt>: "Branch on not equal"' the colon and opening quote
stuck to the LTR run while the closing quote resolved right-to-left.

Wrap the content of <tt> spans in FIRST STRONG ISOLATE / POP
DIRECTIONAL ISOLATE characters so surrounding punctuation resolves
uniformly against the RTL paragraph direction; the isolated code
itself is still rendered left-to-right by the bidi algorithm.

Fixes #117
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LTR letters mess up quotes dots and columns

1 participant