mirror of
https://github.com/luongnv89/claude-howto.git
synced 2026-12-03 02:03:31 +01:00
Closes #219
## Summary
`heading_to_anchor()` in `scripts/check_cross_references.py` removed
U+200C ZERO WIDTH NON-JOINER (ZWNJ) from heading anchors, but GitHub
keeps it in heading ids. Persian uses ZWNJ inside ordinary words, so a
correct in-page link to a Persian heading failed the `cross-references`
hook and the "Cross-reference Check" CI job, while a link with the ZWNJ
removed passed the checker even though it is broken on github.com. The
checker now keeps U+200C. `scripts/build_website.py` has its own copy of
the function, documented as mirroring the checker, and gets the
identical change. All other characters are handled as before.
## Approach
Keep U+200C in heading anchors (checker plus website copy). The function
dropped ZWNJ in two places, so both change:
1. The step-1 class that strips `U+2000–U+206F` is split into
`U+2000–U+200B` and `U+200D–U+206F`, so it skips U+200C.
2. The step-2 filter `[^\w\s-]` becomes `[^\w\s\U0000200C-]`. ZWNJ is
category Cf, which neither `\w` nor `\s` matches, so without this step 2
would still remove it.
ZWJ (U+200D), the em dash and every other General Punctuation character
are still stripped.
## Decision Record
- **Root cause:** `heading_to_anchor()` removes U+200C twice: the step-1
character class strips all of U+2000–U+206F (General Punctuation, which
contains ZWNJ), and the step-2 `[^\w\s-]` filter strips any Cf
character. GitHub keeps ZWNJ in heading ids. Checked against the
rendered `fa/STYLE_GUIDE.md` on PR #208's branch: 24 of its 62 distinct
heading ids (48 of the 124 `user-content-` ids) contain U+200C, e.g.
`نامگذاری-فایل-و-پوشه`. Before this change the checker's anchors missed
27 of those 62 ids, 24 of them because of ZWNJ.
- **Options considered:** Option 1 — Keep U+200C in heading anchors
(checker plus website copy)
- **Options rejected:** n/a — trivial change, direct plan (light
profile)
- **Selected option:** Option 1 — Keep U+200C in heading anchors
(checker plus website copy)
- **Residual risk:**
- **Only U+200C changes.** The rendered ids are evidence for ZWNJ and
the em dash only. On the rendered `CHANGELOG.md` on `main`, all 96
heading ids (19 with an em dash) match both the old and the new output.
ZWJ (U+200D) and the rest of U+2000–U+206F are still stripped, because
no rendered page here shows GitHub keeping them.
- **U+0654 is still dropped (out of scope).** U+0654 ARABIC HAMZA ABOVE
is a combining mark. Python's `\w` drops it but GitHub keeps it. With
this change, 59 of the 62 headings in `fa/STYLE_GUIDE.md` match GitHub's
ids, and the 3 that still differ all contain U+0654. Links to those
headings will still disagree with GitHub. This needs a separate issue.
- **PR #208 must put the ZWNJ back.** That branch removed the ZWNJ from
78 anchors (c890c24) to pass the old checker. Once this merges, those
ZWNJ-less links are reported as broken, which is correct (they are
broken on GitHub), so they need the ZWNJ restored.
- **Website build and Persian.**
`scripts/build_website.py:heading_to_anchor` had the same ZWNJ
stripping. It gets the identical change because `scripts/README.md` says
the website uses "the exact algorithm in
`check_cross_references.heading_to_anchor`". Also, the English website
build excludes `vi/`, `zh/`, `ja/` and `uk/` but not `fa/`, so once
`fa/` lands its pages would be built with ids missing the ZWNJ while
their links keep it. `fa` is not a website locale (`--lang` choices: en,
vi, zh, ja, uk). Whether `fa/` should be excluded from the English build
or added as a locale is not part of this fix.
- **Effort profile:** light — fast path (pre-work Effort S); synthesis
skipped, QA capped at 1 cycle
- **Reproduction:** `python -m pytest
scripts/tests/test_check_cross_references.py
scripts/tests/test_build_website.py::TestHeadingToAnchor -q` confirmed
red on unmodified code for the stated reason (`assert
'نامگذاری-فایل-و-پوشه' == 'نامگذاری-فایل-و-پوشه'`; main() returned 1
for the ZWNJ link and 0 for the ZWNJ-less link; 4 failed) → regression
tests
`scripts/tests/test_check_cross_references.py::test_heading_anchor_keeps_zero_width_non_joiner`,
`::test_in_page_link_keeping_zwnj_passes`,
`::test_in_page_link_missing_zwnj_is_reported`
Analyzed at: `main @ 9c44df1` (2026-10-28)
## Changes
| File | Change |
|------|--------|
| `scripts/check_cross_references.py` | `heading_to_anchor`: skip U+200C
in the step-1 strip range and keep it in the step-2 filter, with a
comment explaining why |
| `scripts/build_website.py` | The same change in its own copy of
`heading_to_anchor` |
| `scripts/tests/test_check_cross_references.py` | ZWNJ kept; em dash
and ZWJ still stripped; vi/zh/uk/ja anchors unchanged (parametrized);
`main()` passes a link that keeps the ZWNJ and reports a link without it
|
| `scripts/tests/test_build_website.py` | ZWNJ kept; website and checker
return the same anchor for Persian, em-dash, ZWJ and Vietnamese headings
|
## Test Results
- Unit tests: 188 passed (`pytest scripts/tests`; 13 new cases)
- Integration tests: 2 `main()`-level cases included in the count above
- E2e tests: skipped (no e2e framework)
- Build: `pre-commit run --all-files` passed, with
`SKIP=mermaid,vietnamese-mermaid,japanese-mermaid` (a local pre-commit
problem, #210/#211, so the Mermaid hooks did not run; no Mermaid or
Markdown files changed). `ruff check`, `ruff format --check` and
`bandit` are clean. `mypy` reports 2 errors in
`scripts/sync_translations.py:84`, a file this PR does not change; the
`mypy-type-check` hook passes.
- QA cycles: 1
- Test integrity: removed or weakened: none (the existing
`TestHeadingToAnchor` and checker tests pass unedited)
## Acceptance Criteria Verification
| Criterion | Status | Evidence |
|-----------|--------|----------|
| For a heading that contains U+200C, the checker's anchor matches
GitHub's rendered heading id, ZWNJ included | pass | Verified red:
reproduction command above → fixed →
`test_heading_anchor_keeps_zero_width_non_joiner`. All 24 ZWNJ headings
of the rendered `fa/STYLE_GUIDE.md` (#208 branch) now match GitHub's
ids. Sensitive: the test fails when either half of the fix is reverted,
then passes again once restored |
| An in-page link whose anchor keeps the ZWNJ passes the
`cross-references` hook and the "Cross-reference Check" CI job | pass |
Verified red: reproduction command above → fixed →
`test_in_page_link_keeping_zwnj_passes` (`main()` == 0). The hook and
the CI job both run this same `main()`. Sensitive: fails when either
half of the fix is reverted |
| A link whose anchor has the ZWNJ removed is reported as broken | pass
| Verified red: reproduction command above → fixed →
`test_in_page_link_missing_zwnj_is_reported` (`main()` == 1, "broken
anchor"). Sensitive: fails when either half of the fix is reverted |
| Existing locales (vi, zh, uk, ja) still pass | pass |
`test_heading_anchor_unchanged_for_existing_locales` (vi/zh/uk/ja). No
`.md` in the repo contains U+200C, and none of the repo's 13,666
headings gets a different anchor. The `cross-references`,
`vietnamese-cross-references` and `japanese-cross-references` hooks
pass. Sensitive: a broader fix that also keeps U+2000–U+206F fails the
em-dash, ZWJ and ja cases |