[docutils:patches] #211 Doctest nodes have incorrect `line` field
Günter Milde via Docutils-develop <[email protected]> Wed, 30 Jul 2025 09:29:05 -0000
| Newsgroups | gmane.text.docutils.devel |
|---|---|
| Message-ID | </p/docutils/patches/211/3ba06ed2dea6bdce6e6703e7d209c481d65ebf93.patches@docutils.p.sourceforge.net> |
This is a multi-part message in MIME format.
--===============2118076580661048028==
Content-Type: multipart/related; boundary="===============1426868860030840138=="
This is a multi-part message in MIME format.
--===============1426868860030840138==
Content-Type: multipart/alternative; boundary="===============1436373623701395689=="
MIME-Version: 1.0
--===============1436373623701395689==
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
- **status**: open-accepted --> closed-accepted
- **Comment**:
The patch is in Docutils 0.22 released 2025-07-29.
Thanks again.
---
**[patches:#211] Doctest nodes have incorrect `line` field **
**Status:** closed-accepted
**Group:** None
**Created:** Thu Sep 12, 2024 09:39 AM UTC by Hood Chatham
**Last Updated:** Mon Nov 11, 2024 05:40 PM 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.
--===============1436373623701395689==
MIME-Version: 1.0
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: 7bit
<div class="markdown_content"><ul>
<li><strong>status</strong>: open-accepted --> closed-accepted</li>
<li><strong>Comment</strong>:</li>
</ul>
<p>The patch is in Docutils 0.22 released 2025-07-29.<br/>
Thanks again.</p>
<hr/>
<p>**<a class="alink strikethrough" href="https://sourceforge.net/p/docutils/patches/211/">[patches:#211]</a> Doctest nodes have incorrect <code>line</code> field **</p>
<p><strong>Status:</strong> closed-accepted<br/>
<strong>Group:</strong> None<br/>
<strong>Created:</strong> Thu Sep 12, 2024 09:39 AM UTC by Hood Chatham<br/>
<strong>Last Updated:</strong> Mon Nov 11, 2024 05:40 PM UTC<br/>
<strong>Owner:</strong> nobody</p>
<p>For most nodes, <code>node.line</code> refers to the source line that the node started on. However, doctest nodes report the end line. </p>
<p>This can be fixed with the following patch:</p>
<div class="codehilite"><pre><span></span><code><span class="gd">--- a/docutils/docutils/parsers/rst/states.py</span>
<span class="gi">+++ b/docutils/docutils/parsers/rst/states.py</span>
<span class="gu">@@ -1587,11 +1587,14 @@ def parse_option_marker(self, match):</span>
<span class="w"> </span> return optlist
<span class="w"> </span> def doctest(self, match, context, next_state):
<span class="gi">+ line = self.document.current_line</span>
<span class="w"> </span> data = '\n'.join(self.state_machine.get_text_block())
<span class="w"> </span> # TODO: prepend class value ['pycon'] (Python Console)
<span class="w"> </span> # parse with `directives.body.CodeBlock` (returns literal-block
<span class="w"> </span> # with class "code" and syntax highlight markup).
<span class="gd">- self.parent += nodes.doctest_block(data, data)</span>
<span class="gi">+ n = nodes.doctest_block(data, data)</span>
<span class="gi">+ n.line = line</span>
<span class="gi">+ self.parent += n</span>
<span class="w"> </span> return [], next_state, []
<span class="w"> </span> def line_block(self, match, context, next_state):
</code></pre></div>
<hr/>
<p>Sent from sourceforge.net because [email protected] is subscribed to <a href="https://sourceforge.net/p/docutils/patches/">https://sourceforge.net/p/docutils/patches/</a></p>
<p>To unsubscribe from further messages, a project admin can change settings at <a href="https://sourceforge.net/p/docutils/admin/patches/options.">https://sourceforge.net/p/docutils/admin/patches/options.</a> Or, if this is a mailing list, you can unsubscribe from the mailing list.</p></div>
--===============1436373623701395689==--
--===============1426868860030840138==--
--===============2118076580661048028==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
--===============2118076580661048028==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline