SF.net SVN: docutils:[10221 ] trunk/docutils/docutils/ parsers/rst/states.py
milde--- via Docutils-checkins <[email protected]> Mon, 25 Aug 2025 08:33:53 +0000
| Newsgroups | gmane.text.docutils.cvs |
|---|---|
| Message-ID | <[email protected]> |
Revision: 10221
http://sourceforge.net/p/docutils/code/10221
Author: milde
Date: 2025-08-25 08:33:52 +0000 (Mon, 25 Aug 2025)
Log Message:
-----------
Use a "property" for `parsers.rst.states.RSTState.parent`.
Using a property attribute instead of runtime initialization ensures
the "insertion point"/"current node" is synchronised across the
statemachine and all state instances.
This may allow support for nested parsing with document-wide section title styles.
Modified Paths:
--------------
trunk/docutils/docutils/parsers/rst/states.py
Modified: trunk/docutils/docutils/parsers/rst/states.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/states.py 2025-08-22 11:14:54 UTC (rev 10220)
+++ trunk/docutils/docutils/parsers/rst/states.py 2025-08-25 08:33:52 UTC (rev 10221)
@@ -232,11 +232,18 @@
self.document = memo.document
self.inliner = memo.inliner
self.reporter = self.document.reporter
- self.parent = self.state_machine.node
# enable the reporter to determine source and source-line
if not hasattr(self.reporter, 'get_source_and_line'):
self.reporter.get_source_and_line = self.state_machine.get_source_and_line # noqa:E501
+ @property
+ def parent(self) -> nodes.Element | None:
+ return self.state_machine.node
+
+ @parent.setter
+ def parent(self, value: nodes.Element):
+ self.state_machine.node = value
+
def goto_line(self, abs_line_offset) -> None:
"""
Jump to input line `abs_line_offset`, ignoring jumps past the end.
@@ -425,15 +432,7 @@
section_node += title_messages
self.document.note_implicit_target(section_node, section_node)
# Update state:
- self.state_machine.node = section_node
- # Also update the ".parent" attribute in all states.
- # This is a bit violent, but the state classes copy their .parent from
- # state_machine.node on creation, so we need to update them. We could
- # also remove RSTState.parent entirely and replace references to it
- # with statemachine.node, but that might break code downstream of
- # docutils.
- for s in self.state_machine.states.values():
- s.parent = section_node
+ self.parent = section_node
def paragraph(self, lines, lineno):
"""
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.