|
From: <mi...@us...> - 2020-12-15 23:06:46
|
Revision: 8594
http://sourceforge.net/p/docutils/code/8594
Author: milde
Date: 2020-12-15 23:06:43 +0000 (Tue, 15 Dec 2020)
Log Message:
-----------
Merge adjoining <Text> nodes in recommonmark post-processing.
Ensure similar XML and pseudoXML output for rst and markdown input
while preserving whitespace in HTML and LaTeX output.
Modified Paths:
--------------
trunk/docutils/docutils/parsers/recommonmark_wrapper.py
trunk/docutils/test/test_parsers/test_recommonmark/test_html_blocks.py
trunk/docutils/test/test_parsers/test_recommonmark/test_inline_markup.py
Modified: trunk/docutils/docutils/parsers/recommonmark_wrapper.py
===================================================================
--- trunk/docutils/docutils/parsers/recommonmark_wrapper.py 2020-12-15 23:06:34 UTC (rev 8593)
+++ trunk/docutils/docutils/parsers/recommonmark_wrapper.py 2020-12-15 23:06:43 UTC (rev 8594)
@@ -62,11 +62,17 @@
# Post-Processing
# ---------------
- # remove spurious empty lines
+ # merge adjoining Text nodes:
for node in document.traverse(nodes.TextElement):
- node.children = [child for child in node.children
- if not (isinstance(child, nodes.Text)
- and str(child) == '\n')]
+ children = node.children
+ i = 0
+ while i+1 < len(children):
+ if (isinstance(children[i], nodes.Text)
+ and isinstance(children[i+1], nodes.Text)):
+ children[i] = nodes.Text(children[i]+children.pop(i+1))
+ children[i].parent = node
+ else:
+ i += 1
# add "code" class argument to inline literal (code spans)
for node in document.traverse(lambda n: isinstance(n,
@@ -85,7 +91,7 @@
if node.children or [v for v in node.attributes.values() if v]:
continue
node.parent.remove(node)
-
+
# replace raw nodes if raw is not allowed
if not document.settings.raw_enabled:
for node in document.traverse(nodes.raw):
Modified: trunk/docutils/test/test_parsers/test_recommonmark/test_html_blocks.py
===================================================================
--- trunk/docutils/test/test_parsers/test_recommonmark/test_html_blocks.py 2020-12-15 23:06:34 UTC (rev 8593)
+++ trunk/docutils/test/test_parsers/test_recommonmark/test_html_blocks.py 2020-12-15 23:06:43 UTC (rev 8594)
@@ -68,8 +68,10 @@
<paragraph>
<raw format="html" xml:space="preserve">
<a href="foo">
+ \n\
<emphasis>
bar
+ \n\
<raw format="html" xml:space="preserve">
</a>
"""],
Modified: trunk/docutils/test/test_parsers/test_recommonmark/test_inline_markup.py
===================================================================
--- trunk/docutils/test/test_parsers/test_recommonmark/test_inline_markup.py 2020-12-15 23:06:34 UTC (rev 8593)
+++ trunk/docutils/test/test_parsers/test_recommonmark/test_inline_markup.py 2020-12-15 23:06:43 UTC (rev 8594)
@@ -38,6 +38,7 @@
<paragraph>
<emphasis>
emphasis
+ \n\
<emphasis>
also emphasis
"""],
@@ -69,8 +70,7 @@
"""\
<document source="test data">
<paragraph>
- *
- no emphasis without closing asterisk
+ *no emphasis without closing asterisk
"""],
[r"""
No markup when \*escaped or unbalanced *.
@@ -81,22 +81,16 @@
"""\
<document source="test data">
<paragraph>
- No markup when \n\
- *
- escaped or unbalanced \n\
- *
- .
+ No markup when *escaped or unbalanced *.
<paragraph>
What about \n\
<emphasis>
this
- *
- ?
+ *?
Unbalanced \n\
<emphasis>
markup
- _
- is kept as-is without warning.
+ _ is kept as-is without warning.
"""],
[r"""
Emphasized asterisk: *\**
@@ -112,8 +106,7 @@
<paragraph>
Emphasized double asterisk: \n\
<emphasis>
- *
- *
+ **
"""],
]
@@ -127,6 +120,7 @@
<paragraph>
<strong>
strong
+ \n\
<strong>
also strong
"""],
@@ -144,8 +138,7 @@
<paragraph>
Strong double asterisk: \n\
<strong>
- *
- *
+ **
"""],
["""\
**not strong without closing asterisks
@@ -153,8 +146,7 @@
"""\
<document source="test data">
<paragraph>
- **
- not strong without closing asterisks
+ **not strong without closing asterisks
"""],
]
@@ -277,13 +269,10 @@
literal
no literal
<paragraph>
- No warning for \n\
- `
- standalone TeX quotes\' or other \n\
+ No warning for `standalone TeX quotes\' or other \n\
<emphasis>
unbalanced markup
- *
- .
+ *.
"""],
["""\
``not literal without closing backquotes
@@ -291,8 +280,7 @@
"""\
<document source="test data">
<paragraph>
- ``
- not literal without closing backquotes
+ ``not literal without closing backquotes
"""],
[r"""
Python ``list``s use square bracket syntax.
@@ -311,9 +299,7 @@
"""\
<document source="test data">
<paragraph>
- Blank after opening \n\
- ``
- not allowed.
+ Blank after opening `` not allowed.
"""],
[r"""
no blank ``after closing``still ends a literal.
@@ -351,6 +337,7 @@
<paragraph>
Inline image \n\
<image alt="foo " title="train & tracks" uri="train.jpg">
+ \n\
in a paragraph.
"""],
["""\
@@ -429,9 +416,7 @@
"""\
<document source="test data">
<paragraph>
- [
- URI must follow immediately
- ]
+ [URI must follow immediately]
(http://example.com)
"""],
["""\
@@ -504,9 +489,9 @@
<document source="test data">
<paragraph>
Hard line breaks are not supported by Docutils.
- Not the soft line break preceded by two or more spaces,
- nor the more visible alternative,
- a backslash before the line ending.
+ Not the soft line break preceded by two or more spaces,\
+nor the more visible alternative,\
+a backslash before the line ending.
"""],
]
@@ -525,10 +510,7 @@
r
<literal classes="code">
k
- _
- u
- _
- p
+ _u_p
works except for underline.
"""],
]
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|