Menu

#211 Doctest nodes have incorrect `line` field

None
open-accepted
nobody
None
5
2024-11-11
2024-09-12
No

For most nodes, node.line refers to the source line that the node started on. However, doctest nodes report the end line.

This can be fixed with the following patch:

--- a/docutils/docutils/parsers/rst/states.py
+++ b/docutils/docutils/parsers/rst/states.py
@@ -1587,11 +1587,14 @@ def parse_option_marker(self, match):
         return optlist

     def doctest(self, match, context, next_state):
+        line = self.document.current_line
         data = '\n'.join(self.state_machine.get_text_block())
         # TODO: prepend class value ['pycon'] (Python Console)
         # parse with `directives.body.CodeBlock` (returns literal-block
         # with class "code" and syntax highlight markup).
-        self.parent += nodes.doctest_block(data, data)
+        n = nodes.doctest_block(data, data)
+        n.line = line
+        self.parent += n
         return [], next_state, []

     def line_block(self, match, context, next_state):

Discussion

  • Hood Chatham

    Hood Chatham - 2024-09-12

    Actually, I think we should set n.line = line + 1?

     
  • Günter Milde

    Günter Milde - 2024-11-11
    • status: open --> open-accepted
     
  • Günter Milde

    Günter Milde - 2024-11-11

    Applied in [r9979]. Thank you for the patch.

     

    Related

    Commit: [r9979]


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.