Expand description
mdbook-repo-links: an mdBook preprocessor for a book whose chapters
include documents from elsewhere in the repository.
The book mirrors the repositoryβs layout β docs/src/installer/DESIGN.md
includes installer/DESIGN.md β so a relative link written for the
original resolves the same way in the book. What the mirror cannot hold
are the targets that are not chapters: source files, scripts, the licence.
In the book those would be dead links; this points each one at the file
on GitHub instead, and leaves every other link as it is.
Configured in book.toml:
[preprocessor.repo-links]
command = "cargo run --quiet --locked -p mdbook-repo-links --"
repository = "https://github.com/<owner>/<repo>"
branch = "master" # default
repo-root = ".." # from the book's root; defaultModulesΒ§
- links π
- Finding the link targets in Markdown, and replacing the ones a resolver has an answer for. Code is left alone: fenced blocks and inline code spans show links as text, and rewriting them would change what they show.
- resolver π
- Where a link target written in a chapter lands: in the book, which leaves it alone, or in the repository, which points it at GitHub.
FunctionsΒ§
- main π
- rewrite_
book π - Every chapter, wherever it sits: the walk is over the JSON itself, so a change in how mdBook nests sections between versions does not matter.
- rewrite_
chapter π - run π
- Reads
[context, book]from stdin and writes the book back to stdout.