mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
ext.napoleon: Do not consume colons within inline code
Fixes gh-7581
This commit is contained in:
parent
21ca43719a
commit
453fe55dc9
@ -30,7 +30,9 @@ _google_section_regex = re.compile(r'^(\s|\w)+:\s*$')
|
|||||||
_google_typed_arg_regex = re.compile(r'\s*(.+?)\s*\(\s*(.*[^\s]+)\s*\)')
|
_google_typed_arg_regex = re.compile(r'\s*(.+?)\s*\(\s*(.*[^\s]+)\s*\)')
|
||||||
_numpy_section_regex = re.compile(r'^[=\-`:\'"~^_*+#<>]{2,}\s*$')
|
_numpy_section_regex = re.compile(r'^[=\-`:\'"~^_*+#<>]{2,}\s*$')
|
||||||
_single_colon_regex = re.compile(r'(?<!:):(?!:)')
|
_single_colon_regex = re.compile(r'(?<!:):(?!:)')
|
||||||
_xref_regex = re.compile(r'(:(?:[a-zA-Z0-9]+[\-_+:.])*[a-zA-Z0-9]+:`.+?`)')
|
_xref_or_code_regex = re.compile(
|
||||||
|
r'((?::(?:[a-zA-Z0-9]+[\-_+:.])*[a-zA-Z0-9]+:`.+?`)|'
|
||||||
|
r'(?:``.+``))')
|
||||||
_bullet_list_regex = re.compile(r'^(\*|\+|\-)(\s+\S|\s*$)')
|
_bullet_list_regex = re.compile(r'^(\*|\+|\-)(\s+\S|\s*$)')
|
||||||
_enumerated_list_regex = re.compile(
|
_enumerated_list_regex = re.compile(
|
||||||
r'^(?P<paren>\()?'
|
r'^(?P<paren>\()?'
|
||||||
@ -728,7 +730,7 @@ class GoogleDocstring:
|
|||||||
after_colon = []
|
after_colon = []
|
||||||
colon = ''
|
colon = ''
|
||||||
found_colon = False
|
found_colon = False
|
||||||
for i, source in enumerate(_xref_regex.split(line)):
|
for i, source in enumerate(_xref_or_code_regex.split(line)):
|
||||||
if found_colon:
|
if found_colon:
|
||||||
after_colon.append(source)
|
after_colon.append(source)
|
||||||
else:
|
else:
|
||||||
|
@ -78,15 +78,17 @@ class InlineAttributeTest(BaseDocstringTest):
|
|||||||
|
|
||||||
def test_class_data_member(self):
|
def test_class_data_member(self):
|
||||||
config = Config()
|
config = Config()
|
||||||
docstring = """data member description:
|
docstring = dedent("""\
|
||||||
|
data member description:
|
||||||
|
|
||||||
- a: b
|
- a: b
|
||||||
"""
|
""")
|
||||||
actual = str(GoogleDocstring(docstring, config=config, app=None,
|
actual = str(GoogleDocstring(docstring, config=config, app=None,
|
||||||
what='attribute', name='some_data', obj=0))
|
what='attribute', name='some_data', obj=0))
|
||||||
expected = """data member description:
|
expected = dedent("""\
|
||||||
|
data member description:
|
||||||
|
|
||||||
- a: b"""
|
- a: b""")
|
||||||
|
|
||||||
self.assertEqual(expected, actual)
|
self.assertEqual(expected, actual)
|
||||||
|
|
||||||
@ -95,10 +97,30 @@ class InlineAttributeTest(BaseDocstringTest):
|
|||||||
docstring = """b: data member description with :ref:`reference`"""
|
docstring = """b: data member description with :ref:`reference`"""
|
||||||
actual = str(GoogleDocstring(docstring, config=config, app=None,
|
actual = str(GoogleDocstring(docstring, config=config, app=None,
|
||||||
what='attribute', name='some_data', obj=0))
|
what='attribute', name='some_data', obj=0))
|
||||||
expected = """data member description with :ref:`reference`
|
expected = dedent("""\
|
||||||
|
data member description with :ref:`reference`
|
||||||
|
|
||||||
:type: b"""
|
:type: b""")
|
||||||
|
self.assertEqual(expected, actual)
|
||||||
|
|
||||||
|
def test_class_data_member_inline_no_type(self):
|
||||||
|
config = Config()
|
||||||
|
docstring = """data with ``a : in code`` and :ref:`reference` and no type"""
|
||||||
|
actual = str(GoogleDocstring(docstring, config=config, app=None,
|
||||||
|
what='attribute', name='some_data', obj=0))
|
||||||
|
expected = """data with ``a : in code`` and :ref:`reference` and no type"""
|
||||||
|
|
||||||
|
self.assertEqual(expected, actual)
|
||||||
|
|
||||||
|
def test_class_data_member_inline_ref_in_type(self):
|
||||||
|
config = Config()
|
||||||
|
docstring = """:class:`int`: data member description"""
|
||||||
|
actual = str(GoogleDocstring(docstring, config=config, app=None,
|
||||||
|
what='attribute', name='some_data', obj=0))
|
||||||
|
expected = dedent("""\
|
||||||
|
data member description
|
||||||
|
|
||||||
|
:type: :class:`int`""")
|
||||||
self.assertEqual(expected, actual)
|
self.assertEqual(expected, actual)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user