Make CLI documentation searchable: Enable search for --options #14041
Replies: 3 comments 8 replies
-
|
@optimusprimeg happy to accept a PR. Makes sense to treat double hyphen at least as special. The single hyphen case is trickier, though. A |
Beta Was this translation helpful? Give feedback.
-
|
HI @optimusprimeg definitely interested in the extension you built. Please share the source code if you can. P.S. it looks like your theme has adopted my search-as-you-type UI, nice! |
Beta Was this translation helpful? Give feedback.
-
|
Hello there! I have tried working on this fix, It is just a minimal JS change, But I would like if somebody reviewed this code... https://github.com/chishxd/sphinx/tree/feature-better-hyphens |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
Command-line options with double hyphens (like
--run,--build-dir,--async) are currently not searchable in Sphinx documentation. This affects any project documenting CLI tools.Example: Searching for
--runin documentation returns results for 'run', even when the option is documented with '--run', because:-are treated as exclusion operators--runbecomes["--", "run"]instead of staying as["--run"]Our Solution
We successfully fixed this for the KDE Builder documentation with a custom Sphinx extension that patches
searchtools.jsin three ways:\-to the word character regex--optionsfrom being treated as exclusions (only single-should be)The fix is automatic—it runs after every build via the
build-finishedhook.Benefits to Sphinx Ecosystem
This would help any project documenting command-line tools:
Implementation
We have a working implementation as a Sphinx extension (~100 lines). The extension:
Video demonstration available
Questions
preserve_hyphens_in_search = True)?Related
Happy to provide more details, share the extension code, or create a PR if there's interest!
Note: This is based on real-world usage in KDE Builder documentation where searching for options like
--build-dir,--async, and--branch-groupnow works perfectly.Beta Was this translation helpful? Give feedback.
All reactions