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 |
Build Scripts
This directory contains two generators that turn the tutorial markdown files into distributable formats:
- EPUB Builder —
build_epub.py - Static Website Builder —
build_website.py
Both treat the .md files as the single source of truth — re-run the relevant
script after editing markdown to regenerate the output.
EPUB Builder Script
Build an EPUB ebook from the Claude How-To markdown files.
Features
- Organizes chapters by folder structure (01-slash-commands, 02-memory, etc.)
- Renders Mermaid diagrams as SVG images with Pele, a pinned bundle run by Node.js; CSS variables are flattened to plain colours on a white background so every EPUB reader shows them
- Caches identical diagrams so each unique diagram is rendered only once
- Generates a cover image from the project logo
- Converts internal markdown links to EPUB chapter references
- Strict error mode - fails if any diagram cannot be rendered
Requirements
- Python 3.10+
- uv
- Node.js >= 20 on
PATHfor Mermaid diagram rendering. The pinned Pele bundle is downloaded on first run (network needed once), sha256-verified, and cached inscripts/.vendor-cache/pele/
Quick Start
# Simplest way - uv handles everything
uv run scripts/build_epub.py
Development Setup
# Create virtual environment
uv venv
# Activate and install dependencies
source .venv/bin/activate
uv pip install -r requirements-dev.txt
# Run tests
pytest scripts/tests/ -v
# Run the script
python scripts/build_epub.py
Command-Line Options
usage: build_epub.py [-h] [--root ROOT] [--output OUTPUT] [--verbose]
[--lang {en,vi,zh,ja}]
options:
-h, --help show this help message and exit
--root, -r ROOT Root directory (default: repo root)
--output, -o OUTPUT Output path (default: claude-howto-guide.epub)
--verbose, -v Enable verbose logging
--lang {en,vi,zh,ja} Language to build (default: en)
Examples
# Build with verbose output
uv run scripts/build_epub.py --verbose
# Custom output location
uv run scripts/build_epub.py --output ~/Desktop/claude-guide.epub
# Build a translated edition
uv run scripts/build_epub.py --lang vi
Output
Creates claude-howto-guide.epub in the repository root directory.
The EPUB includes:
- Cover image with project logo
- Table of contents with nested sections
- All markdown content converted to EPUB-compatible HTML
- Mermaid diagrams rendered as SVG images
Running Tests
# With virtual environment
source .venv/bin/activate
pytest scripts/tests/ -v
# Or with uv directly
uv run --with pytest --with pytest-asyncio \
--with ebooklib --with markdown --with beautifulsoup4 \
--with pillow \
pytest scripts/tests/ -v
Dependencies
Managed via PEP 723 inline script metadata:
| Package | Purpose |
|---|---|
ebooklib |
EPUB generation |
markdown |
Markdown to HTML conversion |
beautifulsoup4 |
HTML parsing |
pillow |
Cover image generation |
Troubleshooting
Build fails with Pele is unavailable: Install Node.js >= 20 and make sure node is on PATH (node --version).
Pele bundle download or checksum failure: The first build downloads the pinned Pele bundle from cdn.jsdelivr.net and checks every file's sha256. Offline or behind a proxy, run one build with network access; later builds use the cache in scripts/.vendor-cache/pele/<version>/. A checksum mismatch means the download was altered or truncated: delete that folder and build again.
Missing logo: The script generates a text-only cover if claude-howto-logo.png is not found.
Static Website Builder
Generate an elegant, mobile-friendly static website from the same markdown
files used by the EPUB build. The website is the rendered view; the .md
files remain the single source of truth.
Features
- One HTML page per markdown source — internal
.mdlinks are rewritten to the corresponding pages on the site - References to non-markdown repo files (templates, scripts, JSON) become GitHub blob URLs that open the source on github.com
- Mermaid diagrams render client-side with Pele (
pele.global.js), served from the built site (no CDN at runtime); they follow the dark mode toggle - Tailwind CSS compiled with the standalone CLI (Go binary, no Node.js) and served from the built site — responsive layout with sidebar nav, in-page TOC, dark mode toggle, and prev/next page navigation
- Inter + JetBrains Mono fonts are self-hosted alongside the CSS — no third-party requests at page load
- Mirrors the EPUB curriculum order (
01-…10-plus top-level docs) - Hostable as plain static files — designed to deploy to GitHub Pages
Quick Start
# Build the English website into ./site/
uv run scripts/build_website.py
# Preview locally
python -m http.server --directory site 8080
# then open http://localhost:8080
Command-Line Options
usage: build_website.py [-h] [--root ROOT] [--output OUTPUT]
[--lang {en,vi,zh,ja,uk}] [--repo-url REPO_URL]
[--branch BRANCH] [--verbose]
options:
--root, -r ROOT Source root (default: repo root)
--output, -o OUTPUT Output directory (default: <repo>/site)
--lang LANG Language to build: en | vi | zh | ja | uk
--repo-url URL GitHub repo for blob links (default: luongnv89/claude-howto)
--branch BRANCH Branch for blob links (default: main)
--verbose, -v Enable verbose logging
GitHub Pages Deploy
The repo ships a workflow at .github/workflows/pages.yml that builds the
site on every push to main (when any .md or generator file changes) and
publishes via actions/deploy-pages. Enable GitHub Pages in repo settings
with Source: GitHub Actions to activate it.
Architecture
build_website.py reuses the chapter-ordering logic from build_epub.py and
ships HTML templates under scripts/website_templates/:
page.html.j2— per-page Jinja2 template with sidebar nav, TOC, prev/nexttailwind.config.js,tailwind.input.css— config + entry CSS for the Tailwind standalone CLI; the CLI scans the built HTML and producessite/assets/tailwind.csswith just the utilities actually usedsite.css— small layer of site-specific styles plus Pygments theme
The Tailwind CLI binary, Pele bundle, and font files are downloaded on
first build into scripts/.vendor-cache/ (gitignored) — see
scripts/vendor_assets.py.
Heading anchors are generated using the exact algorithm in
check_cross_references.heading_to_anchor, so #anchor links validated by
the pre-commit hook resolve correctly on the rendered site.