Repository navigation
feat(autoindex): extract man pages (roff man(7)), one record per .SH section - #1134
Merged
Merged
Conversation
…section
Motivation: most of a Unix system's own documentation is man pages, and
autoindex had no reader for them. A page sniffed as txt-lines (or
txt-prose), so /usr/share/man indexed as 40-line windows of raw roff:
every line a macro (`.TP`, `.B \-a`), words wrapped in font escapes
(`\fBls\fR`), and pod2man pages opening with ~100 lines of preamble.
Nothing knew the page was ls(1) or that it lists directory contents.
sqlite3(1)/psql(1)-style pages, whose examples hold `CREATE TABLE ...;`,
were at risk of being routed to the SQL dump extractor.
Change:
- New `Family::Man` ("man"), sniffed by content in step 2b, before the
text heuristics: after comments, a generator's preamble requests
(`.de`/`.ds`/`.if`/...), and calls of macros the page defines itself,
the first request is `.TH`. mdoc pages (`.Dd`, BSD/macOS), `.so` stubs
and text-first files do not match and keep their current family.
Gzip is the existing magic-byte detection, so `ls.1.gz` works.
- extract/man.rs: reads the macros rather than formatting them. Records
carry `title` (`.TH` NAME(SECTION), else the logical file name minus
`.gz`), `man_section`, `heading` (the `.SH` text), `description` (the
NAME line's summary: "list directory contents"), `body`, and `section`
when a long section is split. Locator `sh{k}-s{j}`. `.SS` stays in its
section as a heading line; `.TP`/`.IP`/`.TQ` keep each term on its own
line above its description; no-fill blocks keep lines and indentation;
tbl tables become one ` | ` line per row. Escapes, special characters,
strings and conditionals are evaluated (nroff answers, groff present),
which handles pod2man and DocBook preambles with no special case.
- Wiring: dispatch (with the logical name, xerj-org#722 class), SourceAndDocs
band in both order.rs functions, whole-file arms in estimate.rs and
lib.rs's size cap, and the two family lists in estimate.rs tests.
Provenance: a port of the man parser in all2md (parsers/man.py, MIT,
(c) 2025 Tom Villani, the author of this PR), reduced to plain text.
Deliberate departures from it:
- `\}` is not stripped before a conditional is evaluated; doing so made
a one-line false `.if t \{ ... \}` skip the rest of the page.
- `.ig XX` ends at `.XX`, as in roff (all2md ended it at `..`).
- `\N`/`\[u...]`/`charNNN` above U+10FFFF yield nothing instead of an
error.
- A macro the page defines (bash's `.FN`, grep's `.dT`) cannot be run,
so after the first `.SH` its arguments are kept as text (all2md drops
them; bash.1's file names were lost).
- A forward `\h` motion prints a space (DocBook's `1.\h'+01'\c` list
numbers ran into the item text).
- Bounds: 16 MiB decompressed input (read_whole), 32 MiB produced text,
string interpolation depth 8 and 200k interpolations per page.
Evidence:
- 22 tests in extract/man.rs; cargo test -p xerj-autoindex --lib: 1211
passed, 0 failed, 2 ignored. clippy -D warnings, fmt and the release
build clean.
- Mutation: disabling the sniff rule fails the gzipped end-to-end test.
- 15 real pages from Debian (rust:latest image), extracted in a
temporary probe test removed before commit: pod2man (perl, cpan,
Git.3pm, EVP_CIPHER-AES.7ssl), DocBook (git, git-commit, apt.conf),
help2man (ls), hand-written (bash, find, grep, make, tar, curl) all
sniff as man with correct titles and NAME summaries, e.g. BASH(1)
"GNU Bourne-Again SHell" in 210 records over 38 sections; ssh (mdoc)
stays txt-lines. Release build: 2.5-12 ms per page (bash.1, 350 KB,
is the 12 ms).
thomas-villani
added a commit
to thomas-villani/xerj
that referenced
this pull request
Oct 4, 2026
…org#1132-xerj-org#1134) Motivation: xerj-org#1132 fills vertical merges down, xerj-org#1133 names columns from a two-row grouped header (Q1_Jan) and xerj-org#1134 adds a roff man(7) extractor. The format lists and the fact-check matrix should say so. This commit must merge AFTER those three code PRs, because it describes them as shipped. - README, landing/llms.txt, landing/llms-full.txt: man pages added to the format lists (llms-full: plain or gzipped, one record per section, titled NAME(SECT), mdoc(7) pages stay plain text). The XLSX entry in llms-full now says vertical merges are filled down, a two-row grouped header is combined, and merges across columns are not expanded. It replaces "merged cells not expanded". - scripts/seo/claims_rules.py: new GREEN THING row "Man pages (roff man(7))" citing extract/man.rs:1, and its gate says mdoc is not parsed. The .xlsx gate gets the same merged-cell wording as llms-full. - testdata/factcheck: new good_man_answer.md fixture (git check-ignore confirms the !scripts/seo/testdata/**/*.md re-include applies), and good_xlsx_answer.md loses the old "merged cells are not expanded" line. Verified: factcheck --self-test OK (35 THING rows); --fail-on error 0 ERROR; build_articles --check current; landing-constants-guard passes. --fixture-check reports 1 false positive (FC-EV-DANGLING) on this branch alone, because good_man_answer.md cites extract/man.rs, which only exists once xerj-org#1134 merges. With man.rs from xerj-org#1134 checked out it reports 0 false positives and 13/13 good fixtures clean.
2 of 7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes, and why
Most of a Unix system's own documentation is man pages, and autoindex had no reader for them:
txt-lines(ortxt-prose), so/usr/share/manwas indexed as 40-line windows of raw roff:.TP,.B \-a);\fBls\fR);ls(1), or that it lists directory contents.CREATE TABLE …;(sqlite3, psql) risked being sent to the SQL dump extractor.This adds
Family::Man.Detection is by content, never by extension. It runs in step 2b, before the text heuristics. A file counts as a man page when its first request is
.TH, skipping over:.de,.ds,.if, …);.dT).mdoc pages (
.Dd, BSD/macOS),.soredirect stubs and files that start with text don't match, so they keep their current family. Gzipped pages (ls.1.gz) use the existing magic-byte detection.Extraction: one record per
.SHsection. Fields:title.THNAME(SECTION), e.g.LS(1); otherwise the logical file name minus.gzman_section.TH(1,7SSL, …)heading.SHheadingdescriptionbodysectionLocators are
sh{k}-s{j}. The parser reads the macros instead of formatting them:.SSstays inside its section as a heading line..TP/.IP/.TQ) keep each term on its own line above its description.|line per row..ds) and conditionals are evaluated as nroff running under groff. That covers pod2man and DocBook preambles without special cases.Wiring:
SourceAndDocsband in bothorder.rsfunctions;estimate.rsand in thelib.rssize cap;estimate.rs's tests.Origin: a port of the man parser in all2md (
parsers/man.py, MIT, © 2025 Tom Villani, who is the author of this PR), reduced to plain text. Deliberate departures from it:\}is no longer stripped before a conditional is evaluated. Stripping it made a one-line false.if t \{ … \}skip the rest of the page..ig XXends at.XX, as roff does.\N,\[u…]andcharNNNabove U+10FFFF produce nothing instead of an error..FN, grep's.dT) can't be run. After the first.SH, its arguments are kept as text; before it, the call is treated as preamble.\hmotion prints a space. Without that, DocBook's1.\h'+01'\clist numbers ran into the item's text.Reference-code note (AGENTS.md): groff (GPL) and mandoc (ISC) were not consulted. The port is from the author's own MIT code.
Evidence
Mutation check: with the sniff rule disabled, the gzipped end-to-end test fails.
Real pages: 15 man pages from Debian (the
rust:latestimage), run through sniffing and extraction in a temporary probe test that was removed before commit. Release build: 2.5–12 ms per page.An excerpt of ls(1)'s DESCRIPTION record as extracted:
Checks
cargo fmt --all(--checkclean)cargo build --release -j 32 -p xerj-autoindexcargo test -p xerj-autoindex --libpasseslanding/llms.txt, and only one PR may edit it at a time (docs/research/llms-txt-2026-09). Once docs: list .pptx/.xlsx as extracted formats; retire "no XLSX/PPTX extractor" #1130 lands, I'll add man pages to the format lists in README,llms.txtandllms-full.txt, plus a fact-check matrix row.txt-prose). A page that fails to parse cannot fail the run, because the parser has no error path; unknown macros are ignored.Not run: no end-to-end
xerj autoindex /usr/share/manrun against a live node. The checks were the crate tests and the extractor probe described above.Provenance
rst2man, ronn, pandoc) parse equally well..THfalls beyond the 8 KiB sniff prefix. None of the 15 did. Such a page keeps its current family and is not lost.🤖 Generated with Claude Code