A visual, example-driven guide to Claude Code — from basic concepts to advanced agents, with copy-paste templates that bring immediate value.
fix(scripts): keep ZWNJ in heading anchors (#222)
Luong NGUYENb968f429866a
diff --git a/scripts/build_website.py b/scripts/build_website.pyindex 266c7ef..305edef 100644--- a/scripts/build_website.py+++ b/scripts/build_website.py@@ -204,12 +204,13 @@ def heading_to_anchor(heading: str) -> str:r"\U0000FE00-\U0000FE0F"r"\U0000200D"r"\U000000A9\U000000AE"- r"\U00002000-\U0000206F"+ r"\U00002000-\U0000200B"+ r"\U0000200D-\U0000206F" # keep U+200C zero-width non-joinerr"]","",heading,)- anchor = re.sub(r"[^\w\s-]", "", heading.lower(), flags=re.UNICODE)+ anchor = re.sub(r"[^\w\s\U0000200C-]", "", heading.lower(), flags=re.UNICODE)anchor = anchor.replace(" ", "-")return anchor.rstrip("-")diff --git a/scripts/check_cross_references.py b/scripts/check_cross_references.pyindex a02efc7..a1c53bd 100644--- a/scripts/check_cross_references.py+++ b/scripts/check_cross_references.py@@ -37,13 +37,16 @@ def heading_to_anchor(heading: str) -> str:r"\U0000FE00-\U0000FE0F" # Variation selectorsr"\U0000200D" # Zero-width joinerr"\U000000A9\U000000AE" # (C) (R)- r"\U00002000-\U0000206F" # General punctuation (some emoji-adjacent)+ r"\U00002000-\U0000200B" # General punctuation (some emoji-adjacent),+ r"\U0000200D-\U0000206F" # minus U+200C zero-width non-joiner (see below)r"]","",heading,)- # 2. Remove punctuation but keep Unicode word chars, spaces, and hyphens- anchor = re.sub(r"[^\w\s-]", "", heading.lower(), flags=re.UNICODE)+ # 2. Remove punctuation but keep Unicode word chars, spaces, hyphens, and+ # U+200C zero-width non-joiner: Persian uses it inside words and GitHub+ # keeps it in heading ids.+ anchor = re.sub(r"[^\w\s\U0000200C-]", "", heading.lower(), flags=re.UNICODE)# 3. Replace spaces with hyphensanchor = anchor.replace(" ", "-")# 4. Strip trailing hyphens (keep leading hyphens for emoji-prefixed headings)diff --git a/scripts/tests/test_build_website.py b/scripts/tests/test_build_website.pyindex 3523f61..6fa6df6 100644--- a/scripts/tests/test_build_website.py+++ b/scripts/tests/test_build_website.py@@ -16,6 +16,7 @@ from bs4 import BeautifulSoupsys.path.insert(0, str(Path(__file__).parent.parent))+import check_cross_referencesfrom build_website import (BuildState,PageInfo,@@ -35,6 +36,10 @@ from build_website import (source_to_site_url,)+# Invisible characters, spelled as escapes so editors can't strip them silently.+ZWNJ = "\u200c" # zero-width non-joiner (Persian, kept in GitHub heading ids)+ZWJ = "\u200d" # zero-width joiner (stripped)+# =============================================================================# Fixtures# =============================================================================@@ -105,6 +110,27 @@ class TestHeadingToAnchor:# The validator strips emoji; we mirror that exactly.assert heading_to_anchor("🔥 Trending") == "-trending"+ def test_zero_width_non_joiner_preserved(self) -> None:+ # Persian uses U+200C inside words; GitHub keeps it in heading ids.+ assert (+ heading_to_anchor(f"نام{ZWNJ}گذاری فایل و پوشه")+ == f"نام{ZWNJ}گذاری-فایل-و-پوشه"+ )++ @pytest.mark.parametrize(+ "heading",+ [+ f"نام{ZWNJ}گذاری فایل و پوشه",+ "[v2.1.245] — 2026-08-25",+ f"A{ZWJ}B test",+ "Hướng dẫn bắt đầu nhanh",+ ],+ )+ def test_matches_validator(self, heading: str) -> None:+ assert heading_to_anchor(heading) == check_cross_references.heading_to_anchor(+ heading+ )+# =============================================================================# source_to_site_urldiff --git a/scripts/tests/test_check_cross_references.py b/scripts/tests/test_check_cross_references.pyindex 7dbae29..f7219c9 100644--- a/scripts/tests/test_check_cross_references.py+++ b/scripts/tests/test_check_cross_references.py@@ -59,3 +59,62 @@ def test_numbered_lesson_dir_missing_readme_is_reported(assert check_cross_references.main() == 1assert "01-intro: missing README.md" in capsys.readouterr().out+++# U+200C ZERO WIDTH NON-JOINER: Persian uses it inside words, and GitHub keeps+# it in heading ids (e.g. the rendered fa/STYLE_GUIDE.md in PR #208). Spelled as+# escapes so editors can't strip them silently.+ZWNJ = "\u200c"+ZWJ = "\u200d"+PERSIAN_HEADING = f"نام{ZWNJ}گذاری فایل و پوشه"+PERSIAN_ANCHOR = f"نام{ZWNJ}گذاری-فایل-و-پوشه"+++def test_heading_anchor_keeps_zero_width_non_joiner() -> None:+ assert check_cross_references.heading_to_anchor(PERSIAN_HEADING) == PERSIAN_ANCHOR+++def test_heading_anchor_still_strips_em_dash_and_zero_width_joiner() -> None:+ assert (+ check_cross_references.heading_to_anchor("[v2.1.245] — 2026-08-25")+ == "v21245--2026-08-25"+ )+ assert check_cross_references.heading_to_anchor(f"A{ZWJ}B test") == "ab-test"+++ ("heading", "anchor"),+ [+ ("Hướng dẫn bắt đầu nhanh", "hướng-dẫn-bắt-đầu-nhanh"),+ ("快速入门 (Quick Start)", "快速入门-quick-start"),+ ("Швидкий старт: встановлення", "швидкий-старт-встановлення"),+ ("クイックスタート — 概要", "クイックスタート--概要"),+ ],+)+def test_heading_anchor_unchanged_for_existing_locales(+ heading: str, anchor: str+) -> None:+ assert check_cross_references.heading_to_anchor(heading) == anchor+++def test_in_page_link_keeping_zwnj_passes(+ repo: Path, capsys: pytest.CaptureFixture[str]+) -> None:+ (repo / "README.md").write_text(+ f"# {PERSIAN_HEADING}\n\n[link](#{PERSIAN_ANCHOR})\n", encoding="utf-8"+ )++ assert check_cross_references.main() == 0+ assert "broken anchor" not in capsys.readouterr().out+++def test_in_page_link_missing_zwnj_is_reported(+ repo: Path, capsys: pytest.CaptureFixture[str]+) -> None:+ anchor_without_zwnj = PERSIAN_ANCHOR.replace(ZWNJ, "")+ (repo / "README.md").write_text(+ f"# {PERSIAN_HEADING}\n\n[link](#{anchor_without_zwnj})\n", encoding="utf-8"+ )++ assert check_cross_references.main() == 1+ assert "broken anchor" in capsys.readouterr().out