Module markdown
Expand description
Turning documentation written for another reader into Markdown.
Two kinds of prose reach a generated page: clap’s help text and rustdoc doc
comments. Neither is Markdown a page can paste verbatim — help text is
soft-wrapped for a terminal, and a doc comment links with [Item] shortcuts
that mean nothing outside rustdoc. Both conversions live here so that all
three generators do them the same way.
A third conversion joined them at M7.D9b, and it is the mirror image of the
first two: a doc comment that cites the guide must spell an absolute site
URL, because docs.rs renders the same text and a relative path there means
nothing — but a page on this site republishing that URL would send a reader
of /0.1/reference/catalog/ to /latest/, and would be a string
mkdocs build --strict never checks. site_links_page_relative is the one
place that resolves it.
Constants§
- DOCS_
DIR 🔒 - The directory a generated page must live under for its links to be rewritable.
- INLINE_
LINK_ 🔒OPEN - The only spelling from which a site URL can be made page-relative: the target half of a Markdown inline link.
- SITE_
PAGE_ PREFIX - This site’s own pages, absolute, as a doc comment has to spell them.
- SITE_
ROOT - The published site’s root, one segment above
SITE_PAGE_PREFIX. - SITE_
VERSION - The version segment the rewrite and the checkers require prose to cite.
Functions§
- code_
span - Wraps
textin a code span that survives backticks inside it. - definition 🔒
- Splits a
[label]: targetline into its two halves. - demote_
headings - Adds one
#to every heading in a section’s body. - is_
item_ 🔒path - Does
targetname a Rust item rather than a document? - is_
markdown - Is
patha Markdown page? - one_
line - Collapses one paragraph’s soft wrapping into a single line.
- page_
relative 🔒 - One site URL’s path, as a Markdown link target relative to a page at
prefix. - paragraphs
- Splits prose into paragraphs, each collapsed onto one line.
- relative_
prefix 🔒 - The run of
../that reachesdocs/from the directory holdingpage. - resolve_
reference_ links - Resolves rustdoc’s reference-style link definitions, then removes them.
- sections
- Splits a doc comment into its
#-headed sections. - site_
links_ page_ relative - Rewrites this site’s absolute page URLs into page-relative Markdown links.
- site_
version_ segment - Splits the tail of a
SITE_ROOTmatch into its version segment and the rest. - strip_
intra_ doc_ links - Rewrites rustdoc’s intra-doc links into plain text.
- surviving_
path_ 🔒link - The byte offset of a
](…::…)link target that survived the rewrite. - url_
slug 🔒 - The URL path characters following a site or repository prefix, up to whatever ends the link.