Skip to main content

Crate mdbook_repo_links

Crate mdbook_repo_links 

Source
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; default

ModulesΒ§

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.