book/quarto/scripts/README.md
This directory contains scripts that run after Quarto builds to fix various issues.
When using selective rendering to speed up builds (only building index + introduction instead of all 20+ chapters), Quarto cannot resolve cross-references to chapters that weren't built. This results in broken references appearing as ?@sec-chapter-name in the HTML output.
This particularly affects:
_build/html/ directory<strong>?@sec-xxx</strong><strong><a href="../path/to/chapter.html#sec-xxx">Chapter Title</a></strong>The script is configured as a post-render hook in the Quarto configuration files:
# In config/_quarto-html.yml
project:
post-render:
- scripts/clean_svgs.py
- scripts/fix_cross_references.py # Fixes cross-references
When adding new chapters to the book:
CHAPTER_MAPPING dictionaryCHAPTER_TITLES dictionary.qmd file (e.g., {#sec-new-chapter})Example:
CHAPTER_MAPPING = {
# ... existing chapters ...
"sec-new-chapter": "../core/new_chapter/new_chapter.html#sec-new-chapter",
}
CHAPTER_TITLES = {
# ... existing chapters ...
"sec-new-chapter": "New Chapter Title",
}
# Test on all HTML files
python3 scripts/fix_cross_references.py
# Test on specific file
python3 scripts/fix_cross_references.py _build/html/contents/backmatter/glossary/glossary.html
The script provides clear output showing what it fixed:
š [Cross-Reference Fix] Scanning 3 HTML files...
ā
Fixed 850 cross-references in 2 files:
š contents/backmatter/glossary/glossary.html: 810 refs
š contents/core/introduction/introduction.html: 40 refs
Cleans up SVG files generated during the build process.
These post-render scripts enable fast iterative development by allowing selective chapter builds while maintaining a fully functional website with working cross-references. Without them, developers would need to build all 20+ chapters every time (taking minutes) just to test changes to a single chapter.