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

milde--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9687
          http://sourceforge.net/p/docutils/code/9687
Author:   milde
Date:     2024-05-06 07:55:16 +0000 (Mon, 06 May 2024)
Log Message:
-----------
Fix recommonmark parser post-processing.

Do not insert a `<system_message>` where it is invalid (paragraphs, ...).
Use a `<problematic>` node instead and place the `<system_message>`
at the end of the document.

Modified Paths:
--------------
    trunk/docutils/docutils/parsers/recommonmark_wrapper.py
    trunk/docutils/test/test_parsers/test_recommonmark/test_misc.py

Modified: trunk/docutils/docutils/parsers/recommonmark_wrapper.py
===================================================================
--- trunk/docutils/docutils/parsers/recommonmark_wrapper.py	2024-05-05 11:33:37 UTC (rev 9686)
+++ trunk/docutils/docutils/parsers/recommonmark_wrapper.py	2024-05-06 07:55:16 UTC (rev 9687)
@@ -123,8 +123,17 @@
         # replace raw nodes if raw is not allowed
         if not document.settings.raw_enabled:
             for node in document.findall(nodes.raw):
-                warning = document.reporter.warning('Raw content disabled.')
-                node.parent.replace(node, warning)
+                message = document.reporter.warning('Raw content disabled.')
+                if isinstance(node.parent, nodes.TextElement):
+                    msgid = document.set_id(message)
+                    problematic = nodes.problematic('', node.astext(),
+                                                    refid=msgid)
+                    node.parent.replace(node, problematic)
+                    prbid = document.set_id(problematic)
+                    message.add_backref(prbid)
+                    document.append(message)
+                else:
+                    node.parent.replace(node, message)
 
         # drop pending_xref (Sphinx cross reference extension)
         for node in document.findall(addnodes.pending_xref):

Modified: trunk/docutils/test/test_parsers/test_recommonmark/test_misc.py
===================================================================
--- trunk/docutils/test/test_parsers/test_recommonmark/test_misc.py	2024-05-05 11:33:37 UTC (rev 9686)
+++ trunk/docutils/test/test_parsers/test_recommonmark/test_misc.py	2024-05-06 07:55:16 UTC (rev 9687)
@@ -44,6 +44,11 @@
 @unittest.skipIf(Parser is None, 'Optional "recommonmark" module not found.')
 class RecommonmarkParserTests(unittest.TestCase):
 
+    mysettings = {'output_encoding': 'unicode',
+                  'warning_stream': '',
+                  'raw_enabled': False,
+                  }
+
     def test_parser_name(self):
         # cf. ../test_rst/test_directives/test__init__.py
         # this is used in the "include" directive's :parser: option.
@@ -51,22 +56,18 @@
 
     def test_raw_disabled(self):
         output = publish_string(sample_with_html, parser=Parser(),
-                                settings_overrides={
-                                    'warning_stream': '',
-                                    'raw_enabled': False,
-                                    })
-        self.assertNotIn(b'<raw>', output)
-        self.assertIn(b'<system_message', output)
-        self.assertIn(b'Raw content disabled.', output)
+                                settings_overrides=self.mysettings)
+        self.assertNotIn('<raw>', output)
+        self.assertIn('<system_message', output)
+        self.assertIn('Raw content disabled.', output)
 
     def test_raw_disabled_inline(self):
         output = publish_string('foo <a href="uri">', parser=Parser(),
-                                settings_overrides={'warning_stream': '',
-                                                    'raw_enabled': False,
-                                                    })
-        self.assertNotIn(b'<raw>', output)
-        self.assertIn(b'<system_message', output)
-        self.assertIn(b'Raw content disabled.', output)
+                                settings_overrides=self.mysettings)
+        self.assertNotIn('<raw>', output)
+        self.assertIn('<problematic', output)
+        self.assertIn('<system_message', output)
+        self.assertIn('Raw content disabled.', output)
 
 
 if __name__ == '__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.