Skip to content

fix: strip Sphinx roles and directives from plain help overviews - #510

Open
Shahzeb-DataEngineer wants to merge 2 commits into
canonical:mainfrom
Shahzeb-DataEngineer:fix/strip-sphinx-markup-help
Open

Shahzeb-DataEngineer wants to merge 2 commits into
canonical:mainfrom
Shahzeb-DataEngineer:fix/strip-sphinx-markup-help

Conversation

@Shahzeb-DataEngineer

Copy link
Copy Markdown
Contributor

Description

Overviews are shared between terminal help and rendered docs, so app authors write them with Sphinx markup. In plain terminal help that markup showed literally, e.g. an overview containing :doc:the tutorial <tutorials/index>`` or a .. note:: block rendered the raw Sphinx syntax in the terminal.

Like the existing double-backtick stripping from #306, this removes Sphinx markup from plain help only:

  • Roles :role:text, `:domain:role:`text, and explicit-title roles :role:Title `` become text / `Title`; a leading `~` shows only the last component, as Sphinx renders it.
  • Directive marker lines (.. note::, .. code-block:: python) are removed, keeping the directive content.

Markdown output is untouched, so rendered docs keep the markup.

Related issue

Fixes #351

Notes

  • New tests mirror the feat: remove code backticks in CLI help messages #306 tests: plain help strips the markup, markdown keeps it.
  • test_command_help_text_strip_sphinx_markup and test_command_help_text_sphinx_markup_markdown pass locally; the remaining failures in tests/unit/test_help.py are pre-existing in this environment (emitter-not-initiated errors, identical on the clean tree).
  • Canonical CLA already signed (Individual).

Overviews are shared between terminal help and rendered docs, so app
authors write them with Sphinx markup. In plain terminal help that
markup showed literally (e.g. :doc:`...`, .. note::). Like the
existing double-backtick stripping from canonical#306, remove Sphinx roles
(keeping the readable text, explicit titles, and the last component
for ~-prefixed references) and directive marker lines (keeping the
directive content) from plain help only; markdown output keeps the
markup for rendered docs.

Fixes canonical#351

Signed-off-by: Shahzeb Ali <126076773+Shahzeb-DataEngineer@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings October 18, 2026 04:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Directive-body handling can remove literal content, and the behavior needs a changelog entry.

1 open issue
What changed in this PR

Updates plain terminal help to strip Sphinx roles and directive markers while preserving markup in Markdown output.

Changes:

  • Added Sphinx role and directive filtering for plain help.
  • Added tests for plain and Markdown rendering.
  • A moderate issue remains with nested directive content; release-note documentation is also needed.
File Summary
tests/​unit/​test_help.py Adds coverage for plain-help stripping and Markdown preservation.
craft_cli/​helptexts.py Implements Sphinx markup filtering; nested directive content handling requires correction.

Review effort: Lite

Comment thread craft_cli/helptexts.py Outdated
Comment on lines +136 to +140
lines = [
line
for line in text.split("\n")
if not re.match(r"\s*\.\. [a-zA-Z][\w-]*::", line)
]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed in f48a5c0. The strip now tracks literal-body directives (code, code-block, raw, parsed-literal) and keeps marker-like lines inside their bodies as content, so the .. note:: example line survives. Nested real directives (e.g. a warning inside a note body) are still stripped. Also added the 3.4.2 release note.

The directive marker filter treated every indented ``.. x::`` line as a
marker, so a literal ``.. note::`` line inside a ``.. code-block::`` body
was stripped from plain help. Track literal-body directives (code,
code-block, raw, parsed-literal) and keep marker-like lines inside them
as content; nested real directives are still stripped. Also document the
change in the 3.4.2 release notes.

Signed-off-by: Shahzeb Ali <126076773+Shahzeb-DataEngineer@users.noreply.github.com>
@Shahzeb-DataEngineer
Shahzeb-DataEngineer requested a review from a team as a code owner October 18, 2026 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove sphinx directives from overview texts

2 participants