Skip to content

Commit 0619a5c

Browse files
committed
DOP-2300: Correct recursive directive parsing line offsets
1 parent bb4492e commit 0619a5c

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

snooty/rstparser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ def run(self) -> List[docutils.nodes.Node]:
533533

534534
# Parse the content
535535
self.state.nested_parse(
536-
self.content, self.state_machine.line_offset, node, match_titles=True
536+
self.content, self.content_offset, node, match_titles=True
537537
)
538538

539539
return [node]
@@ -557,7 +557,7 @@ def parse_argument(self, node: directive, source: str, line: int) -> None:
557557
content_lines = prepare_viewlist(self.arguments[0])
558558
self.state.nested_parse(
559559
docutils.statemachine.ViewList(content_lines, source=self.arguments[0]),
560-
self.state_machine.line_offset,
560+
self.content_offset,
561561
node,
562562
match_titles=True,
563563
)
@@ -757,7 +757,7 @@ def make_tab_node(
757757
content_lines = prepare_viewlist(child.content)
758758
self.state.nested_parse(
759759
docutils.statemachine.ViewList(content_lines, source=source),
760-
self.state_machine.line_offset,
760+
self.content_offset,
761761
node,
762762
match_titles=True,
763763
)
@@ -826,7 +826,7 @@ def run(self) -> List[docutils.nodes.Node]:
826826

827827
if self.content:
828828
self.state.nested_parse(
829-
self.content, self.state_machine.line_offset, node, match_titles=True
829+
self.content, self.content_offset, node, match_titles=True
830830
)
831831

832832
return [node]

snooty/test_parser.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2653,3 +2653,37 @@ def test_escape() -> None:
26532653
<paragraph><substitution_reference name="adl"></substitution_reference><text>ss</text></paragraph>
26542654
</root>""",
26552655
)
2656+
2657+
2658+
def test_directive_line_offset() -> None:
2659+
"""Ensure that line numbers are correctly tracked inside of directives."""
2660+
path = ROOT_PATH.joinpath(Path("test.rst"))
2661+
project_config = ProjectConfig(ROOT_PATH, "")
2662+
parser = rstparser.Parser(project_config, JSONVisitor)
2663+
2664+
page, diagnostics = parse_rst(
2665+
parser,
2666+
path,
2667+
r""".. _kotlin-multiplatform-install:
2668+
2669+
========================================
2670+
Install Realm - Kotlin Multiplatform SDK
2671+
========================================
2672+
2673+
.. default-domain:: mongodb
2674+
2675+
Prerequisites
2676+
-------------
2677+
2678+
.. warning::
2679+
2680+
You can track an issue with line numbers in :github:`this GitHub issue
2681+
<https://github.com/mongodb/snooty-parser/pull/328>`__.
2682+
2683+
.. include:: /includes/steps/install-kotlin-multiplatform.rst
2684+
""",
2685+
)
2686+
2687+
page.finish(diagnostics)
2688+
assert len(diagnostics) == 1
2689+
assert diagnostics[0].start[0] == 13

0 commit comments

Comments
 (0)