[docutils:patches] #211 Doctest nodes have incorrect `line` field
Günter Milde via Docutils-develop <[email protected]> Mon, 11 Nov 2024 17:40:05 -0000
| Newsgroups | gmane.text.docutils.devel |
|---|---|
| Message-ID | </p/docutils/patches/211/1492274ad90dcf7e3fbbb6cc8cf1f2bcb3010f5f.patches@docutils.p.sourceforge.net> |
- **status**: open --> open-accepted
- **Comment**:
Applied in [r9979]. Thank you for the patch.
---
**[patches:#211] Doctest nodes have incorrect `line` field **
**Status:** open-accepted
**Group:** None
**Created:** Thu Sep 12, 2024 09:39 AM UTC by Hood Chatham
**Last Updated:** Thu Sep 12, 2024 09:47 AM UTC
**Owner:** nobody
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:
```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):
```
---
Sent from sourceforge.net because [email protected] is subscribed to https://sourceforge.net/p/docutils/patches/
To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/docutils/admin/patches/options. Or, if this is a mailing list, you can unsubscribe from the mailing list.