mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #8352: std domain: Failed to parse an option that starts with bracket
This commit is contained in:
parent
e4bd3bd3dd
commit
6d24579f40
1
CHANGES
1
CHANGES
@ -70,6 +70,7 @@ Bugs fixed
|
||||
* #8131: linkcheck: Use GET when HEAD requests cause Too Many Redirects, to
|
||||
accommodate infinite redirect loops on HEAD
|
||||
* #8437: Makefile: ``make clean`` with empty BUILDDIR is dangerous
|
||||
* #8352: std domain: Failed to parse an option that starts with bracket
|
||||
|
||||
Testing
|
||||
--------
|
||||
|
@ -43,7 +43,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# RE for option descriptions
|
||||
option_desc_re = re.compile(r'((?:/|--|-|\+)?[^\s=[]+)(=?\s*.*)')
|
||||
option_desc_re = re.compile(r'((?:/|--|-|\+)?[^\s=]+)(=?\s*.*)')
|
||||
# RE for grammar tokens
|
||||
token_re = re.compile(r'`(\w+)`', re.U)
|
||||
|
||||
@ -197,6 +197,11 @@ class Cmdoption(ObjectDescription):
|
||||
location=signode)
|
||||
continue
|
||||
optname, args = m.groups()
|
||||
if optname.endswith('[') and args.endswith(']'):
|
||||
# optional value surrounded by brackets (ex. foo[=bar])
|
||||
optname = optname[:-1]
|
||||
args = '[' + args
|
||||
|
||||
if count:
|
||||
signode += addnodes.desc_addname(', ', ', ')
|
||||
signode += addnodes.desc_name(optname, optname)
|
||||
|
@ -91,6 +91,28 @@ def test_get_full_qualified_name():
|
||||
assert domain.get_full_qualified_name(node) == 'ls.-l'
|
||||
|
||||
|
||||
def test_cmd_option_with_optional_value(app):
|
||||
text = ".. option:: -j[=N]"
|
||||
doctree = restructuredtext.parse(app, text)
|
||||
assert_node(doctree, (index,
|
||||
[desc, ([desc_signature, ([desc_name, '-j'],
|
||||
[desc_addname, '[=N]'])],
|
||||
[desc_content, ()])]))
|
||||
objects = list(app.env.get_domain("std").get_objects())
|
||||
assert ('-j', '-j', 'cmdoption', 'index', 'cmdoption-j', 1) in objects
|
||||
|
||||
|
||||
def test_cmd_option_starting_with_bracket(app):
|
||||
text = ".. option:: [enable=]PATTERN"
|
||||
doctree = restructuredtext.parse(app, text)
|
||||
assert_node(doctree, (index,
|
||||
[desc, ([desc_signature, ([desc_name, '[enable'],
|
||||
[desc_addname, '=]PATTERN'])],
|
||||
[desc_content, ()])]))
|
||||
objects = list(app.env.get_domain("std").get_objects())
|
||||
assert ('[enable', '[enable', 'cmdoption', 'index', 'cmdoption-arg-enable', 1) in objects
|
||||
|
||||
|
||||
def test_glossary(app):
|
||||
text = (".. glossary::\n"
|
||||
"\n"
|
||||
|
Loading…
Reference in New Issue
Block a user