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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ All notable changes to this project will be documented in this file.
- Add `force_refs_lower` to enable `:ref:` links with mixed-case program names and arguments.
- Fix Sphinx smart quotes rewriting `--` to an en dash in `--option` names within descriptions, epilogs, and help text.
- Register flags and positional arguments as Sphinx program options so the `:option:` role links to them.
- Leave apostrophes inside words (`don't`, `it's`) alone in help text instead of turning them into broken inline
literals.

## 1.13.1

Expand Down
8 changes: 8 additions & 0 deletions roots/test-help-apostrophe/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent))
extensions = ["sphinx_argparse_cli"]
nitpicky = True
3 changes: 3 additions & 0 deletions roots/test-help-apostrophe/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. sphinx_argparse_cli::
:module: parser
:func: make
10 changes: 10 additions & 0 deletions roots/test-help-apostrophe/parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from __future__ import annotations

from argparse import ArgumentParser


def make() -> ArgumentParser:
parser = ArgumentParser(prog="prog", add_help=False)
parser.add_argument("--a", help="don't use it's value")
parser.add_argument("--b", help="it's a 'thing' to see")
return parser
5 changes: 3 additions & 2 deletions src/sphinx_argparse_cli/_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,9 @@ def make_id(key: str) -> str:


_HELP_SUBSTITUTIONS: Final[list[tuple[re.Pattern[str], str]]] = [
(re.compile(r"[']+(.+?)[']+"), "``'\\1'``"),
(re.compile(r'["]+(.+?)["]+'), '``"\\1"``'),
# a quote glued to a word character is an apostrophe (don't, it's), not the edge of a quoted span
(re.compile(r"(?<!\w)'([^']+?)'(?!\w)"), "``'\\1'``"),
(re.compile(r'(?<!\w)"([^"]+?)"(?!\w)'), '``"\\1"``'),
(re.compile(r"[{](.+?)[}]"), "``{\\1}``"),
]

Expand Down
39 changes: 32 additions & 7 deletions tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,27 @@ def test_set_usage_first(build_outcome: str) -> None:
assert "complex first [-h]" in build_outcome.split("a-first-desc", maxsplit=1)[0]


@pytest.mark.sphinx(buildername="text", testroot="help-apostrophe")
def test_help_apostrophe(build_outcome: str, warning: StringIO) -> None:
assert (
build_outcome
== """prog - CLI interface
********************

prog [--a A] [--b B]


prog options
============

* **"--a"** "A" - don't use it's value

* **"--b"** "B" - it's a "'thing'" to see
"""
)
assert not warning.getvalue()


@pytest.mark.sphinx(buildername="text", testroot="suppressed-action")
def test_suppressed_action(build_outcome: str) -> None:
assert "--activities-since" not in build_outcome
Expand All @@ -183,13 +204,17 @@ def test_suppressed_action(build_outcome: str) -> None:
@pytest.mark.parametrize(
("example", "output"),
[
("", ""),
("{", "{"),
('"', '"'),
("'", "'"),
("{a}", "``{a}``"),
('"a"', '``"a"``'),
("'a'", "``'a'``"),
pytest.param("", "", id="empty"),
pytest.param("{", "{", id="lone-brace"),
pytest.param('"', '"', id="lone-double-quote"),
pytest.param("'", "'", id="lone-single-quote"),
pytest.param("{a}", "``{a}``", id="braces"),
pytest.param('"a"', '``"a"``', id="double-quoted"),
pytest.param("'a'", "``'a'``", id="single-quoted"),
pytest.param("don't use it's value", "don't use it's value", id="apostrophes"),
pytest.param("it's a 'thing' to see", "it's a ``'thing'`` to see", id="apostrophe-and-quoted"),
pytest.param("'a' and 'b'", "``'a'`` and ``'b'``", id="two-quoted"),
pytest.param('say "hi" or "bye"', 'say ``"hi"`` or ``"bye"``', id="two-double-quoted"),
],
)
def test_help_loader(example: str, output: str) -> None:
Expand Down