Skip to content

Commit 2a6ea83

Browse files
author
Hashem Nasarat
committed
Allow options to contain multiple words
When documenting subcommands, sometimes mkdocs-click will only show the subcommand name. `:prog_name:` seems to be the right option to ensure the actuall command is shown, but due to an overly-strict regex, it used to ignore everything after the first whitespace. With this change, `prog_name` and other commands can contain multiple words in their values. For example ``` ::: mkdocs-click :module: foo.utils.bridge :prog_name: foo-utils bridge :command: cli ``` now properly renders as > foo-utils bridge [OPTIONS] instead of > foo-utils [OPTIONS] or > bridge [OPTIONS] (^^ if prog_name wasn't specified at all) Co-Authored-By: Bar Hochman <[email protected]> Fixes #42
1 parent a8742d9 commit 2a6ea83

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

7+
## Unreleased
8+
9+
### Fixed
10+
11+
- `:prog_name:` and other options can now contain multiple words (it used to stop at whitespace). (Pull #60)
12+
713
## 0.8.0 - 2022-06-19
814

915
### Added

mkdocs_click/_processing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def replace_blocks(lines: Iterable[str], title: str, replace: Callable[..., Iter
2222

2323
for line in lines:
2424
if in_block_section:
25-
match = re.search(r"^\s+:(?P<key>.+):(?:\s+(?P<value>\S+))?", line)
25+
match = re.search(r"^\s+:(?P<key>.+):(?:\s+(?P<value>.*\S))?", line)
2626
if match is not None:
2727
# New ':key:' or ':key: value' line, ingest it.
2828
key = match.group("key")

tests/test_processing.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ def test_replace_options():
1212
foo
1313
::: target
1414
:option1: value1
15-
:optiøn2: value2
15+
:optiøn2: val ue2
1616
\t:option3:
1717
:option4:\x20
18+
:option5: 1
1819
bar
1920
""".strip()
2021

2122
expected = """
2223
# Some content
2324
foo
24-
{'option1': 'value1', 'optiøn2': 'value2', 'option3': '', 'option4': ''}
25+
{'option1': 'value1', 'optiøn2': 'val ue2', 'option3': '', 'option4': '', 'option5': '1'}
2526
bar
2627
""".strip()
2728

0 commit comments

Comments
 (0)