docs: link manpage cross-references in HTML output - #4246
Conversation
1be89ba to
653e6cf
Compare
|
Some parts of the manual pages are a bit stale and needs cleaning up. In fact, I was doing exactly that for the hal_*(3) set of pages and adding a lot of them when this issue of linking caught my attention. |
|
Should I drop the doc fixes then? just have the script? |
No, your fixes are just fine. The "other" fixes is to read them all from start to end, fix inconsistencies, add missing, remove obsolete and reformat them to become uniform. But that is a different affair of incremental changes over a longer period. |
|
One thing though, maybe add to lcnc-overrides.css: .man-xref {
font-family: monospace;
font-size: 90%;
}We'll tackle the spurious bolds, italics and splits ( |
| html.scan(/([^<]+)|(<[^>]*>)/) do | ||
| text, tag = Regexp.last_match(1), Regexp.last_match(2) |
There was a problem hiding this comment.
Isn't there supposed to be at least one char in between the '<' and '>' in a tag? How are you catching <mytag attrib="<oops>">?
The "proper" way to look at HTML is to use a HTML/XML parser and then find the text nodes matching the manpage(sec) pattern. That would be safer than regex parsing, which is known to be unstable for structured files like HTML.
Wouldn't it just be better to do this in a Tree-processor extension?
There are examples of tree-processors: https://github.com/asciidoctor/asciidoctor-extensions-lab/tree/main/lib/
You should also be able to check for the selected output format while it is running.
There was a problem hiding this comment.
Good point on the tree-processor, I have rewritten the extension as one. It now runs on the parsed AST before conversion, so code blocks, monospace spans, passthroughs and existing links are excluded by node context instead of by splitting HTML with a regex, and it checks document.backend while running, as you suggested.
On the two concrete regex cases: they cannot occur in asciidoctor output. > inside an attribute value is escaped (link:https://x/?a=1>b[t] produces href="https://x/?a=1>b"), and a stray < in text becomes <, so neither attrib="<oops>" nor an empty <> reaches the output. The exception is raw pass:[...] passthrough, which the docs do use, so the concern was valid in principle even if no current input triggered it.
The rewrite also fixed a real bug this kind of parsing hid: list item and table cell text accessors apply substitutions, which had to be handled explicitly. Verified by rebuilding all 456 English manpages: link sets and visible text are unchanged compared to the postprocessor version.
There was a problem hiding this comment.
One correction and one addition. The substitution issue I mentioned was introduced by my first treeprocessor draft (the #text getters on list items and table cells apply inline substitutions, so raw text must be rewritten instead), not something the postprocessor version hid. Verification since extended to the full htmldocs build: 537 English pages, no missed links, no broken targets, no self-links. Related asciidoctor gotcha found along the way: in compat-mode legacy 'single quotes' render as emphasis, not code, so manpage references written that way stay linkable.
Add an asciidoctor postprocessor that turns name(section) references in the HTML manpages into clickable links to the sibling page. Index-gated against the rendered troff tree so false positives (enum values, external and misspelled pages) stay plain text; self-links, code spans and existing links are left untouched. Wired into the manpage HTML rule via manxref-root.
motion(1) and hal_thread_new(3) name pages that do not exist. Point them at the actual pages motion(9) and hal_create_thread(3).
Extend the man_xref postprocessor to the User/HAL/Integrator HTML manuals, which cite man pages in the same name(section) form. A per-page manxref-linkbase attribute carries the depth-adjusted path to the language's man/man<N>/ tree; manpages keep the sibling default. Index-gated as before, so only real pages link and prose like TRUE(1) stays plain.
Rewrite manpage cross-references to link: macros on the parsed AST before conversion, so verbatim blocks, monospace, passthroughs and existing links are excluded by node context instead of HTML regex splitting. The backend is checked via document.backend.
274999d to
1d2beef
Compare
Addresses #4244.
What
Adds an asciidoctor postprocessor (
docs/src/extensions/man_xref.rb) that turnsname(section)manpage references (halcmd(1),stepgen(9), ...) into clickable links to the corresponding HTML page. Applied to both:man/), and../man/manN/.Wired into both HTML rules in
docs/src/Submakefile. Per-pagemanxref-root(troff tree) andmanxref-linkbase(depth-adjusted path) attributes drive it; absent => no-op.How it stays correct
Index-gated: a token links only when a real page
name.sectionexists in that language's troff tree. Common false positives resolve to nothing and stay plain, with no skip list:feed(2)/arc(3)inmotion(9)open(2),printf(3),udev(8)TRUE(1),time.sleep(1)Also: never self-links; skips
<a> <code> <pre> <script> <style> <head> <title> <h1>(code, attributes, existing links untouched); case-insensitive match with verbatim visible text.Verification
de/man/).BUILD_DOCS_TRANSLATED=yesbuild currently cannot complete due to a pre-existing po4a NAME-drift issue (a stray space in a German man page NAME yields a dangling.soalias), tracked in docs: pin manpage troff filename to the make target #4193 / CI: Check html links for doc #4178. Unrelated to this change; the links themselves render correctly per language.Also included
Source refs the linker surfaced as broken, fixed to the real pages:
motion(1)=>motion(9)inhal_manualtoolchange(1)hal_thread_new(3)=>hal_create_thread(3)inhal_add_funct_to_thread(3)stegen(9)=>stepgen(9)in the hostmot2 driver docsNotes
link:refs (e.g.SSERIAL(9),debounce(9)) are left untouched: the postprocessor skips anything already inside an<a>.hm2_uart_setup_chan(3)inhostmot2(9)names no existing page; left as-is. @pcw-mesa stale/renamed name, or a missing page?