You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sphinx chooses to lower() all :ref: values, which means that we can
not link to a program that has an upper-case value in it's program
name, nor differentiate between upper and lower-case single character
flags in references (e.g. -A/-a).
While we could simply lower() the program name, it's not quite so
simple for mixed-case arguments because they can then make duplicate
refs. A alternative simple approach that fits nicely into the
existing code is to simply prefix capitals in references with "_" and
lower them.
Unfortunately since this changes the refs, this would be a backwards
incompatible change if made unconditionally. You may also decide that
mixed case references are more clear in your output HTML URL's if you
are not worried about ever making internal references in your
documentation.
Thus this adds a :force_refs_lower: flag to optionally enable the
prefix/lower behaviour.
A test-case and documentation is added as well.
Copy file name to clipboardExpand all lines: README.md
+15-1Lines changed: 15 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,7 +43,7 @@ Within the reStructuredText files use the `sphinx_argparse_cli` directive that t
43
43
| group_title_prefix | (optional) groups subsections title prefixes, accepts the string `{prog}` as a replacement for the program name - defaults to `{prog}`|
44
44
| group_sub_title_prefix | (optional) subcommands groups subsections title prefixes, accepts replacement of `{prog}` and `{subcommand}` for program and subcommand name - defaults to `{prog} {subcommand}`|
45
45
| no_default_values | (optional) suppresses generation of `default` entries |
46
-
46
+
| force_refs_lower | (optional) Sphinx `:ref:` only supports lower-case references. With this, any capital letter in generated reference anchors are lowered and given an `_` prefix (i.e. `A` becomes `_a`) |
47
47
For example:
48
48
49
49
```rst
@@ -84,3 +84,17 @@ being `cli`:
84
84
- to refer to the optional arguments group use ``:ref:`cli:tox-optional-arguments` ``,
85
85
- to refer to the run subcommand use ``:ref:`cli:tox-run` ``,
86
86
- to refer to flag `--magic` of the `run` sub-command use ``:ref:`cli:tox-run---magic` ``.
87
+
88
+
Due to Sphinx's `:ref:` only supporting lower-case values, if you need
89
+
to distinguish mixed case program names or arguments, set the
90
+
`:force_refs_lower:` argument. With this flag, captial-letters in
91
+
references will be converted to their lower-case counterpart and
92
+
prefixed with an `_`. For example:
93
+
94
+
- A `prog` name `SampleProgram` will be referenced as ``:ref:`_sample_program...` ``.
95
+
- To distinguish between mixed case flags `-a` and `-A` use ``:ref:`_sample_program--a` `` and ``:ref:`_sample_program--_a` `` respectively
96
+
97
+
Note that if you are _not_ concernced about using internal Sphinx
98
+
`:ref:` cross-references, you may choose to leave this off to maintain
99
+
mixed-case anchors in your output HTML; but be aware that later
100
+
enabling it will change your anchors in the output HTML.
0 commit comments