Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/misc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ Linking to action groups
------------------------

As of version 0.2.0, action groups (e.g., "Optional arguments", "Required arguments", and subcommands) can be included in tables of contents and external links. The anchor name is the same as the title name (e.g., "Optional arguments"). In cases where titles are duplicated, as is often the case when subcommands are used, ``_repeatX``, where ``X`` is a number, is prepended to duplicate anchor names to ensure that they can all be uniquely linked.


Argparse color
--------------

Since Python 3.14, ``argparse`` uses `colors <https://docs.python.org/3/library/argparse.html#color>`__ in the output by default.
These ANSI color sequences won't show right at all in the Sphinx output, so this extension will disable colors first in your ``ArgumentParser`` instance before producing the output.
You can override this default behaviour by passing the ``:color:`` flag to your ``.. argparse`` directive, in this case the color setting of the argument parser is enabled.
7 changes: 7 additions & 0 deletions sphinxarg/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ class ArgParseDirective(SphinxDirective):
'nodescription': unchanged,
'markdown': flag,
'markdownhelp': flag,
'color': flag,
}

def _construct_manpage_specific_structure(self, parser_info):
Expand Down Expand Up @@ -538,6 +539,12 @@ def run(self):
path = str(self.options['path'])
if 'prog' in self.options:
parser.prog = self.options['prog']

# Argparse in Python 3.14 uses ANSI color codes by default (#72)
if hasattr(parser, 'color'):
parser.color = 'color' in self.options
# Disable colors, unless a flag is present in the user-settings

result = parse_parser(
parser,
skip_default_values='nodefault' in self.options,
Expand Down