Skip to content

Commit 4d8cfa3

Browse files
committed
DOP-1015: Consider <reference> nodes inline
1 parent c351fc7 commit 4d8cfa3

File tree

5 files changed

+93
-45
lines changed

5 files changed

+93
-45
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+
### Fixed
11+
12+
- Support for links in step file headings (DOP-1015).
13+
1014
## [v0.4.4] - 2020-04-21
1115

1216
### Added

snooty/gizaparser/test_steps.py

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -46,45 +46,58 @@ def create_page(filename: Optional[str]) -> Tuple[Page, EmbeddedRstParser]:
4646
print(repr(ast_to_testing_string(pages[0].ast)))
4747
check_ast_testing_string(
4848
pages[0].ast,
49-
"".join(
50-
(
51-
'<directive name="steps"><directive name="step">',
52-
"<section>",
53-
'<heading id="import-the-public-key-used-by-the-package-management-system">',
54-
"<text>Import the public key used by the package management system.</text>",
55-
"</heading><paragraph><text>Issue the ",
56-
"following command to import the\n</text><reference ",
57-
'refuri="https://www.mongodb.org/static/pgp/server-3.4.asc">',
58-
"<text>MongoDB public GPG Key</text>",
59-
"</reference></paragraph></section></directive>",
60-
'<directive name="step">',
61-
"<section>",
62-
'<heading id="create-a-etc-apt-sources-list-d-mongodb-org-3-4-list-file-for-mongodb">',
63-
"<text>Create a </text><literal><text>",
64-
"/etc/apt/sources.list.d/mongodb-org-3.4.list</text></literal><text> file for </text>",
65-
'<role name="guilabel"><text>MongoDB</text></role>',
66-
"<text>.</text></heading>",
67-
'<section><heading id="optional-action-heading">',
68-
"<text>Optional: action heading</text></heading>"
69-
"<paragraph><text>Create the list file using the command appropriate for ",
70-
"your version\nof Debian.</text></paragraph>",
71-
"<paragraph><text>action-content</text></paragraph>",
72-
"<paragraph><text>action-post</text></paragraph>",
73-
"</section></section></directive>",
74-
'<directive name="step"><section>',
75-
'<heading id="reload-local-package-database"><text>Reload local package database.</text>',
76-
"</heading><paragraph><text>Issue the following command to reload the local package ",
77-
'database:</text></paragraph><code copyable="True" lang="sh">sudo apt-get update\n</code>',
78-
"</section></directive>",
79-
'<directive name="step"><section><heading id="install-the-mongodb-packages">',
80-
"<text>Install the MongoDB packages.</text>",
81-
"</heading><paragraph><text>hi</text></paragraph>",
82-
"<paragraph><text>You can install either the latest stable version of MongoDB ",
83-
"or a\nspecific version of MongoDB.</text></paragraph>",
84-
'<code lang="sh" copyable="True">',
85-
'echo "mongodb-org hold" | sudo dpkg --set-selections',
86-
"</code><paragraph><text>bye</text></paragraph>",
87-
"</section></directive></directive>",
88-
)
89-
),
49+
"""
50+
<directive name="steps">
51+
<directive name="step">
52+
<section>
53+
<heading id="import-the-public-key-used-by-the-package-management-system">
54+
<text>Import the </text>
55+
<emphasis><text>public key</text></emphasis>
56+
<text> used by the </text>
57+
<reference refuri="https://en.wikipedia.org/wiki/Package_manager">
58+
<text>package management system</text>
59+
</reference>
60+
</heading>
61+
<paragraph>
62+
<text>Issue the following command to import the\n</text>
63+
<reference refuri="https://www.mongodb.org/static/pgp/server-3.4.asc">
64+
<text>MongoDB public GPG Key</text></reference>
65+
</paragraph></section></directive>
66+
<directive name="step">
67+
<section>
68+
<heading id="create-a-etc-apt-sources-list-d-mongodb-org-3-4-list-file-for-mongodb">
69+
<text>Create a </text><literal><text>
70+
/etc/apt/sources.list.d/mongodb-org-3.4.list</text></literal><text> file for </text>
71+
<role name="guilabel"><text>MongoDB</text></role>
72+
<text>.</text>
73+
</heading>
74+
<section><heading id="optional-action-heading">
75+
<text>Optional: action heading</text></heading>
76+
<paragraph>
77+
<text>Create the list file using the command appropriate for your version\nof Debian.</text>
78+
</paragraph>
79+
<paragraph><text>action-content</text></paragraph>
80+
<paragraph><text>action-post</text></paragraph>
81+
</section></section></directive>
82+
<directive name="step"><section>
83+
<heading id="reload-local-package-database">
84+
<text>Reload local package database.</text>
85+
</heading>
86+
<paragraph>
87+
<text>Issue the following command to reload the local package database:</text>
88+
</paragraph>
89+
<code copyable="True" lang="sh">sudo apt-get update\n</code>
90+
</section></directive>
91+
<directive name="step"><section>
92+
<heading id="install-the-mongodb-packages">
93+
<text>Install the MongoDB packages.</text>
94+
</heading>
95+
<paragraph><text>hi</text></paragraph>
96+
<paragraph>
97+
<text>You can install either the latest stable version of MongoDB or a\nspecific version of MongoDB.</text>
98+
</paragraph>
99+
<code lang="sh" copyable="True">
100+
echo "mongodb-org hold" | sudo dpkg --set-selections
101+
</code><paragraph><text>bye</text></paragraph></section></directive>
102+
</directive>""",
90103
)

snooty/parser.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,13 +658,17 @@ class InlineJSONVisitor(JSONVisitor):
658658
"""A JSONVisitor subclass which does not emit block nodes."""
659659

660660
def dispatch_visit(self, node: docutils.nodes.Node) -> None:
661-
if isinstance(node, docutils.nodes.Body):
661+
if isinstance(node, docutils.nodes.Body) and not isinstance(
662+
node, docutils.nodes.Inline
663+
):
662664
return
663665

664666
JSONVisitor.dispatch_visit(self, node)
665667

666668
def dispatch_departure(self, node: docutils.nodes.Node) -> None:
667-
if isinstance(node, docutils.nodes.Body):
669+
if isinstance(node, docutils.nodes.Body) and not isinstance(
670+
node, docutils.nodes.Inline
671+
):
668672
return
669673

670674
JSONVisitor.dispatch_departure(self, node)

snooty/test_parser.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,41 @@
99
CannotOpenFile,
1010
InvalidLiteralInclude,
1111
)
12-
from .parser import parse_rst, JSONVisitor
12+
from .parser import parse_rst, JSONVisitor, InlineJSONVisitor
1313

1414
ROOT_PATH = Path("test_data")
1515

1616
# Some of the tests in this file may seem a little weird around refs: the raw parser output
1717
# does NOT include postprocessing artifacts such as nonlocal link titles and intersphinx lookups.
1818

1919

20+
def test_inline_parser_references() -> None:
21+
tabs_path = ROOT_PATH.joinpath(Path("test.rst"))
22+
project_config = ProjectConfig(ROOT_PATH, "")
23+
parser = rstparser.Parser(project_config, InlineJSONVisitor)
24+
25+
# Test a simple code-block
26+
page, diagnostics = parse_rst(
27+
parser,
28+
tabs_path,
29+
"""
30+
`package management system <https://en.wikipedia.org/wiki/Package_manager>`_
31+
""",
32+
)
33+
page.finish(diagnostics)
34+
assert diagnostics == []
35+
print(ast_to_testing_string(page.ast))
36+
check_ast_testing_string(
37+
page.ast,
38+
"""
39+
<root>
40+
<reference refuri="https://en.wikipedia.org/wiki/Package_manager">
41+
<text>package management system</text>
42+
</reference>
43+
</root>""",
44+
)
45+
46+
2047
def test_tabs() -> None:
2148
tabs_path = ROOT_PATH.joinpath(Path("test_tabs.rst"))
2249
project_config = ProjectConfig(ROOT_PATH, "")

test_data/steps-test-child.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
title: Import the public key used by the package management system.
1+
title: Import the *public key* used by the `package management system <https://en.wikipedia.org/wiki/Package_manager>`_
22
stepnum: 1
33
level: 4
44
ref: import-key

0 commit comments

Comments
 (0)