SF.net SVN: docutils:[9745 ] trunk/docutils

milde--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9745
          http://sourceforge.net/p/docutils/code/9745
Author:   milde
Date:     2024-06-06 14:03:45 +0000 (Thu, 06 Jun 2024)
Log Message:
-----------
xml-parser: register decoration element

Update the internal attribute `document.decoration`
after creating a `decoration` element.

Prevents `transforms.universal.Decoration` from adding a second
`decoration` element.

Modified Paths:
--------------
    trunk/docutils/docutils/parsers/docutils_xml.py
    trunk/docutils/test/test_parsers/test_docutils_xml/test_misc.py

Modified: trunk/docutils/docutils/parsers/docutils_xml.py
===================================================================
--- trunk/docutils/docutils/parsers/docutils_xml.py	2024-06-06 14:03:33 UTC (rev 9744)
+++ trunk/docutils/docutils/parsers/docutils_xml.py	2024-06-06 14:03:45 UTC (rev 9745)
@@ -131,7 +131,9 @@
         node = nodeclass()
 
     node.line = int(element.get('source line'))
-    if isinstance(node, Unknown):
+    if isinstance(node, nodes.decoration):
+        document.decoration = node
+    elif isinstance(node, Unknown):
         node.tagname = element.tag
         document.reporter.warning(
             f'Unknown element type <{element.tag}>.',

Modified: trunk/docutils/test/test_parsers/test_docutils_xml/test_misc.py
===================================================================
--- trunk/docutils/test/test_parsers/test_docutils_xml/test_misc.py	2024-06-06 14:03:33 UTC (rev 9744)
+++ trunk/docutils/test/test_parsers/test_docutils_xml/test_misc.py	2024-06-06 14:03:45 UTC (rev 9745)
@@ -49,10 +49,29 @@
 
 totest = {}
 
-totest['hyperlinks'] = ({},
+totest['decoration'] = ({'datestamp': 'pi-day'},  # generate footer
 [
-# resolve anonymous hyperlinks
 ["""\
+<decoration>
+    <footer>
+        <paragraph>myfooter</paragraph>
+    </footer>
+</decoration>
+""",
+"""\
+<document source="<string>">
+    <decoration>
+        <footer>
+            <paragraph>
+                myfooter
+            <paragraph>
+                Generated on: pi-day.
+"""],
+])
+
+totest['hyperlinks'] = ({},  # resolve hyperlinks
+[
+["""\
 <document source="test data">
     <paragraph>A <reference anonymous="1" name="link">link</reference> to Docutils.</paragraph>
     <target anonymous="1" ids="target-1" refuri="http://docutils.sourceforge.io"/>
@@ -87,5 +106,6 @@
 """],
 ])
 
+
 if __name__ == '__main__':
     unittest.main()

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.