Skip to content

Commit 20448b4

Browse files
madelinezeci80and
authored andcommitted
DOP-1188: fix for labels starting with number
Signed-off-by: Andrew Aldridge <[email protected]>
1 parent 31cb4bf commit 20448b4

File tree

6 files changed

+89
-2
lines changed

6 files changed

+89
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Support labels beginning with numbers that contain underscores (DOP-1188)
13+
1014
## [v0.5.0] - 2020-07-08
1115

1216
### Added

snooty/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def dispatch_visit(self, node: docutils.nodes.Node) -> None:
223223
self.diagnostics.append(InvalidURL(util.get_line(node)))
224224
raise docutils.nodes.SkipNode()
225225

226-
node_id = node["ids"][0]
226+
node_id = node["names"][0]
227227
children: Any = [n.TargetIdentifier((line,), [], [node_id])]
228228
refuri = node["refuri"] if "refuri" in node else None
229229
self.state.append(n.Target((line,), children, "std", "label", refuri))

snooty/test_parser.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,40 @@ def test_rst_replacement() -> None:
534534
)
535535

536536

537+
def test_labels() -> None:
538+
path = ROOT_PATH.joinpath(Path("test.rst"))
539+
project_config = ProjectConfig(ROOT_PATH, "", source="./")
540+
parser = rstparser.Parser(project_config, JSONVisitor)
541+
542+
# test label starting with a number
543+
page, diagnostics = parse_rst(
544+
parser,
545+
path,
546+
"""
547+
:ref:`100_stacked_example`
548+
549+
.. _100_stacked_example:
550+
""",
551+
)
552+
page.finish(diagnostics)
553+
assert diagnostics == []
554+
555+
ast = page.ast
556+
check_ast_testing_string(
557+
ast,
558+
"""
559+
<root>
560+
<paragraph>
561+
<ref_role domain="std" name="label" target="100_stacked_example"/>
562+
</paragraph>
563+
<target domain="std" name="label">
564+
<target_identifier ids="['100_stacked_example']" />
565+
</target>
566+
</root>
567+
""",
568+
)
569+
570+
537571
def test_roles() -> None:
538572
path = ROOT_PATH.joinpath(Path("test.rst"))
539573
project_config = ProjectConfig(ROOT_PATH, "", source="./")

snooty/test_postprocess.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,38 @@ def test_validate_ref_targets(backend: Backend) -> None:
140140
<literal><text>mongod</text></literal>
141141
</ref_role>""",
142142
)
143+
# Assert that refs beginning with number and containing underscores, work
144+
paragraph = ast.children[5]
145+
assert isinstance(paragraph, n.Parent)
146+
ref_role = paragraph.children[2]
147+
check_ast_testing_string(
148+
ref_role,
149+
"""<ref_role
150+
domain="std"
151+
name="label"
152+
target="100_stacked_example"
153+
fileid="index">
154+
<text>100 Stacked Examples</text>
155+
</ref_role>""",
156+
)
143157

158+
paragraph = ast.children[6]
159+
assert isinstance(paragraph, n.Parent)
160+
ref_role = paragraph.children[2]
161+
check_ast_testing_string(
162+
ref_role,
163+
"""<ref_role
164+
domain="std"
165+
name="label"
166+
target="z100_stacked_example"
167+
fileid="index">
168+
<text>Z100 Stacked Examples</text>
169+
</ref_role>""",
170+
)
144171
# Check that undeclared targets raise an error
145172
diagnostics = backend.diagnostics[page_id]
146-
assert len(diagnostics) == 1
147173
assert isinstance(diagnostics[0], TargetNotFound)
174+
assert isinstance(diagnostics[1], AmbiguousTarget)
148175

149176

150177
def test_role_explicit_title(backend: Backend) -> None:

test_data/test_postprocessor/source/index.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,21 @@ Testing Sibling Nodes
2828

2929
/page1
3030
/page2
31+
32+
.. _100_stacked_example:
33+
34+
100 Stacked Examples
35+
---------------------
36+
37+
.. method:: amethod(param1, param2)
38+
39+
Testing :ref:`<100_stacked_example>`.
40+
41+
.. _z100_stacked_example:
42+
43+
Z100 Stacked Examples
44+
---------------------
45+
46+
.. method:: amethod(param1, param2)
47+
48+
Testing :ref:`<z100_stacked_example>`.

test_data/test_postprocessor/source/refrole.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ requirements for sharding collections for |global-write|, see
1515
And this is a link to :method:`amethod`.
1616

1717
And this is a link to :binary:`mongod`.
18+
19+
|service| does not require developers, see :ref:`100_stacked_example`.
20+
21+
|service| does require developers, see :ref:`z100_stacked_example`.

0 commit comments

Comments
 (0)