diff --git a/CHANGELOG.md b/CHANGELOG.md index eeaefcc..71fc0b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- Count visible text when checking SVG label widths so RTL labels can isolate command-line flags at the column limit. - Preserve the SVG manifest's byte hashes when writing files on Windows. - Ignore footnote examples inside inline code when auditing wiki Markdown. - Exercise Windows in CI and document a live bilingual GitHub showcase check and a Copilot CLI audit. diff --git a/skills/github-markdown-studio/references/multilingual.md b/skills/github-markdown-studio/references/multilingual.md index 7b9cbc5..881bd11 100644 --- a/skills/github-markdown-studio/references/multilingual.md +++ b/skills/github-markdown-studio/references/multilingual.md @@ -27,3 +27,16 @@ Never refresh hashes just to make a check green. Review the source diff, update Use a single canonical diagram topology and translate labels into locale-specific assets. Keep theme variants derived from that locale's same layout. Prefer short labels and a text explanation outside the image. For RTL, inspect text direction, numbering, arrows, mixed Latin identifiers and alignment. Do not mirror a causal flow without checking its meaning. The bundled SVG renderer accepts locale tags and an explicit `ltr` or `rtl` direction, but it is a fixed process-card layout, not a universal typography engine. It rejects long labels rather than silently clipping them. Browser/font review is still necessary. + +In an RTL label, isolate a left-to-right command-line option so its leading +hyphens stay on the left. Write the Unicode escapes directly in the diagram +JSON. This step keeps the flag visible as `--output`. + +```json +{"title":"حفظ التقرير","detail":"استخدم \u2066--output\u2069 لحفظ التقرير."} +``` + +`\u2066` begins the left-to-right span and `\u2069` ends it. The renderer +preserves both characters in the SVG and excludes them from the label width. +Check a rendered asset in both themes when punctuation carries meaning. +[W3C guidance on direction isolates](https://www.w3.org/International/questions/qa-bidi-unicode-controls.en) diff --git a/skills/github-markdown-studio/scripts/render_diagram.py b/skills/github-markdown-studio/scripts/render_diagram.py index 896b936..8ec8997 100644 --- a/skills/github-markdown-studio/scripts/render_diagram.py +++ b/skills/github-markdown-studio/scripts/render_diagram.py @@ -20,6 +20,7 @@ "dark": {"background": "#0d1117", "surface": "#161b22", "text": "#f0f6fc", "muted": "#b7c4d5", "accent": "#5eead4", "border": "#39495c"}, } LANGUAGE = re.compile(r"[a-z]{2,3}(?:-[A-Za-z0-9]{2,8})*\Z") +REMOVE_DIRECTION_ISOLATES = str.maketrans("", "", "\u2066\u2067\u2068\u2069") def display_width(text: str) -> int: @@ -27,11 +28,14 @@ def display_width(text: str) -> int: def label(value: object, maximum: int, name: str) -> str: - if not isinstance(value, str) or not value.strip() or display_width(value) > maximum: + text = value if isinstance(value, str) else "" + # Measure the visible label and keep the original isolates for SVG layout. + visible = text.translate(REMOVE_DIRECTION_ISOLATES) + if not visible.strip() or display_width(visible) > maximum: raise ValueError(f"{name} must be non-empty text within {maximum} display columns; use shorter labels") - if any(unicodedata.category(c) in {"Cc", "Cs"} for c in value): + if any(unicodedata.category(c) in {"Cc", "Cs"} for c in text): raise ValueError(f"{name} contains control characters") - return value.strip() + return text.strip() def build_assets(spec: dict) -> dict[str, str]: diff --git a/tests/test_studio.py b/tests/test_studio.py index 7463b84..8db02b6 100644 --- a/tests/test_studio.py +++ b/tests/test_studio.py @@ -303,6 +303,25 @@ def test_rtl_smoke(self): self.assertIn('direction="rtl"', svg) self.assertIn('xml:lang="ar"', svg) + def test_rtl_flag_at_visible_width_limit(self): + content = copy.deepcopy(self.spec["locales"]["en"]) + content["direction"] = "rtl" + detail = "استخدم \u2066--output\u2069 لحفظ التقرير في الملف، ثم راجعه قبل النشر." + content["steps"][0]["detail"] = detail + self.spec["locales"] = {"ar": content} + assets = render.build_assets(self.spec) + for theme in ("light", "dark"): + svg = ET.fromstring(assets[f"workflow.ar.{theme}.svg"]) + self.assertIn(detail, [node.text for node in svg.findall(".//{*}text")]) + content["steps"][0]["detail"] += "!" + with self.assertRaisesRegex(ValueError, "58 display columns"): + render.build_assets(self.spec) + + def test_direction_isolates_without_label_text_are_rejected(self): + for opening in ("\u2066", "\u2067", "\u2068"): + with self.subTest(opening=ascii(opening)), self.assertRaises(ValueError): + render.label(opening + " " + "\u2069", 32, "title") + def test_no_overwrite_without_flag(self): with tempfile.TemporaryDirectory() as directory: output = Path(directory)