feat: add RTL support for Hebrew, Arabic, Farsi, and other languages#75
feat: add RTL support for Hebrew, Arabic, Farsi, and other languages#75adamatan wants to merge 6 commits intojfernandez:mainfrom
Conversation
Automatic detection and rendering of right-to-left (RTL) documents with support for Hebrew, Arabic, Farsi, Syriac, Thaana, NKo, and related scripts. Features: - Auto-detect RTL when ≥50% of alphabetic characters are RTL script - CLI flags: --rtl (force RTL), --no-rtl (disable detection) - dir="rtl" attribute on content div - RTL font stack (Hebrew + Arabic system fonts, no CDN) - Blockquote border/padding flipped for RTL - Code blocks forced LTR (only in RTL documents) - Logical CSS table alignment (text-align: start) Implementation: - Single-pass detect_rtl() with no allocation - RtlMode enum (Copy) with resolve() method - RenderedFile struct bundles HTML + RTL flag - Professional fixture files for testing (Hebrew, Arabic, Farsi, English) Testing: 60 tests (all in src/app.rs #[cfg(test)]) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Hey, nice work on the RTL support. I want to merge this but with a simpler approach.
Since mdserve is an agent companion, the AI agent already knows what language it's writing in. So I'd rather keep the --rtl flag and drop all the auto-detection (detect_rtl, is_rtl_char, RtlMode, RenderedFile, --no-rtl, per-file detection, fixtures). That's ~100 lines of plumbing for something the caller already knows. I'll teach the skill to pass --rtl when needed.
So keep: --rtl flag, dir="rtl", RTL fonts, code blocks forced LTR, text-align: start on tables.
Also, for blockquotes: use border-inline-start / padding-inline-start / margin-inline-start instead of the conditional override block. You already used logical properties for tables, so this keeps it consistent and removes another {% if is_rtl %} block.
Happy to merge once that's cleaned up.
|
Yeah, that make sense. |
Since mdserve is an agent companion, the AI agent already knows what
language it's writing in — auto-detection is unnecessary plumbing.
Drop `detect_rtl`, `is_rtl_char`, `RtlMode`, `RenderedFile`, `--no-rtl`,
per-file detection, and the four language fixture files (~500 lines
removed).
Keep `--rtl` as a simple global bool: `dir="rtl"` on the content div,
RTL font stack, code blocks forced LTR, `text-align: start` on tables.
Switch blockquote styling from physical properties with a conditional
`{% if is_rtl %}` override to logical properties (`border-inline-start`,
`padding-inline-start`, `margin-inline-start`), consistent with the
existing table approach.
Add `tests/fixtures/rtl.md` and five new tests covering `--rtl`
rendering, code block LTR scoping, and fixture integration.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@jfernandez done |
|
Thanks. I'll take another look before the end of the week. |
…z#76) The file watcher calls handle_markdown_file_change only after the OS reports a rename, create, or data modification event. Re-checking mtime inside refresh_file is redundant and fails when the renamed file has the same mtime as the original (sub-second filesystem granularity). Use force_refresh_file in the watcher path to unconditionally re-read the file. The mtime guard remains in refresh_file for the HTTP handler path where it prevents unnecessary disk reads on every page load. Also refactor refresh_file to delegate to force_refresh_file to avoid duplicating the read/parse logic.
Add rtl parameter to create_test_server_impl instead of maintaining a separate helper with duplicated setup logic. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
f2ed2e2 to
d26a5d7
Compare
|
Hi - is there anything I should do to promote this one? |
|
Hey @adamatan, thanks for iterating on this, the RTL implementation looks solid and matches the feedback from the first review. A few things to clean up before we merge:
Once that's done we'll do a final review and merge. Thanks! |
Motivation
mdserveis designed as an AI coding agent companion. Developers working in Hebrew, Arabic, Farsi, and other RTL languages need their markdown previews to render correctly without manual configuration. This feature makes it work out of the box while preserving zero-config defaults.Solution
Auto-detect popular RTL languages by counting RTL characters in the document. Documents that contain more than 50% RTL characters will be rendered in RTL mode, except for code blocks which should stay LTR. Two new CLI params -
--rtland--no-rtl- will override the detection if needed.Implementation
Adds automatic detection and rendering of right-to-left (RTL) documents, with support for Hebrew, Arabic, Farsi, Syriac, Thaana, NKo, and related scripts.
--rtlto force RTL,--no-rtlto disable detectiondir="rtl"on content div, RTL blockquote styling, code blocks forced LTR, logical table alignment (text-align: start)Test plan
cargo test— 60 tests pass (detection unit tests, axum-test integration tests, fixture file tests)cargo build --release— clean build, zero warnings--rtland--no-rtlCLI flags🤖 Generated with Claude Code