|
From: <mi...@us...> - 2022-02-03 18:03:49
|
Revision: 8997
http://sourceforge.net/p/docutils/code/8997
Author: milde
Date: 2022-02-03 18:03:47 +0000 (Thu, 03 Feb 2022)
Log Message:
-----------
Fix FilterMessages transform [bug:#435].
The "Messages" transform no longer tests for to-be-ignored messages
but inserts all `system-messages` without parent into a
"System Messages" section.
This allows the "FilterMessages" transform to find and convert
matching `problematic` nodes (but now it also has to remove the
"System Messages" section if empty).
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docutils/transforms/universal.py
Added Paths:
-----------
trunk/docutils/test/test_transforms/test_filter_messages.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2022-02-03 14:13:03 UTC (rev 8996)
+++ trunk/docutils/HISTORY.txt 2022-02-03 18:03:47 UTC (rev 8997)
@@ -49,6 +49,10 @@
- Don't use mutable default values for function arguments. Fixes bug #430.
+* docutils/transforms/universal.py
+
+ - Fix bug 435: invalid references in `problematic` nodes with report_level=4.
+
* docutils/utils/__init__.py
- decode_path() returns `str` instance instead of `nodes.reprunicode`.
@@ -69,7 +73,7 @@
* test/DocutilsTestSupport.py
- - exception_data() returns None if no exception was raised.
+ - exception_data() now returns None if no exception was raised.
- recommonmark_wrapper only imported if upstream parser is present.
* test/test_parsers/test_rst/test_directives/test_tables.py
Modified: trunk/docutils/docutils/transforms/universal.py
===================================================================
--- trunk/docutils/docutils/transforms/universal.py 2022-02-03 14:13:03 UTC (rev 8996)
+++ trunk/docutils/docutils/transforms/universal.py 2022-02-03 18:03:47 UTC (rev 8997)
@@ -121,11 +121,7 @@
def apply(self):
unfiltered = self.document.transform_messages
- threshold = self.document.reporter.report_level
- messages = []
- for msg in unfiltered:
- if msg['level'] >= threshold and not msg.parent:
- messages.append(msg)
+ messages = [msg for msg in unfiltered if not msg.parent]
if messages:
section = nodes.section(classes=['system-messages'])
# @@@ get this from the language module?
@@ -145,6 +141,9 @@
"""
Remove system messages below verbosity threshold.
+
+ Convert <problematic> nodes referencing removed messages to <Text>.
+ Remove "System Messages" section if empty.
"""
default_priority = 870
@@ -153,6 +152,16 @@
for node in tuple(self.document.findall(nodes.system_message)):
if node['level'] < self.document.reporter.report_level:
node.parent.remove(node)
+ try: # also remove id-entry
+ del(self.document.ids[node['ids'][0]])
+ except (IndexError):
+ pass
+ for node in tuple(self.document.findall(nodes.problematic)):
+ if node['refid'] not in self.document.ids:
+ node.parent.replace(node, nodes.Text(node.astext()))
+ for node in self.document.findall(nodes.section):
+ if "system-messages" in node['classes'] and len(node) == 1:
+ node.parent.remove(node)
class TestMessages(Transform):
Added: trunk/docutils/test/test_transforms/test_filter_messages.py
===================================================================
--- trunk/docutils/test/test_transforms/test_filter_messages.py (rev 0)
+++ trunk/docutils/test/test_transforms/test_filter_messages.py 2022-02-03 18:03:47 UTC (rev 8997)
@@ -0,0 +1,75 @@
+#!/usr/bin/env python3
+
+# $Id$
+# :Copyright: © 2021 Günter Milde.
+# :Maintainer: doc...@li...
+# :License: Released under the terms of the `2-Clause BSD license`_, in short:
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+# This file is offered as-is, without any warranty.
+#
+# .. _2-Clause BSD license: https://opensource.org/licenses/BSD-2-Clause
+
+"""
+Tests for docutils.transforms.universal.FilterMessages.
+"""
+
+if __name__ == '__main__':
+ import __init__
+from test_transforms import DocutilsTestSupport
+from docutils.transforms.universal import Messages, FilterMessages
+from docutils.transforms.references import Substitutions
+from docutils.parsers.rst import Parser
+
+
+def suite():
+ parser = Parser()
+ settings = {'report_level': 5} # filter all system messages
+ s = DocutilsTestSupport.TransformTestSuite(
+ parser, suite_settings=settings)
+ s.generateTests(totest)
+ return s
+
+totest = {}
+
+totest['system_message_sections'] = ((Substitutions, Messages, FilterMessages), [
+["""\
+.. unknown-directive:: block markup is filtered without trace.
+""",
+"""\
+<document source="test data">
+"""],
+["""\
+Invalid *inline markup is restored to text.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Invalid \n\
+ *
+ inline markup is restored to text.
+"""],
+["""\
+This |unknown substitution| will generate a system message, thanks to
+the "Substitutions" transform. The "Messages" transform will
+generate a "System Messages" section and the "FilterMessages" transform
+will remove it.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ This \n\
+ |unknown substitution|
+ will generate a system message, thanks to
+ the "Substitutions" transform. The "Messages" transform will
+ generate a "System Messages" section and the "FilterMessages" transform
+ will remove it.
+"""],
+])
+
+
+if __name__ == '__main__':
+ import unittest
+ unittest.main(defaultTest='suite')
Property changes on: trunk/docutils/test/test_transforms/test_filter_messages.py
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|