The reStructuredText Markup Specification states that
A backslash followed by any character (except whitespace characters in non-URI contexts) escapes that character. The escaped character represents the character itself, and is prevented from playing a role in any markup interpretation.
--- http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#escaping-mechanism
However, the "classifier delimiter" in definition list terms (" : ") and the "author separator" in the "authors" Docinfo field (";" or ",") are not escaped, when preceded by a backslash. (The backslash is removed before the relevant source part is parsed.)
An attempt to fix this situation in the 0.15 development version relied on the undocumented "rawsource" attribute. Because this attribute is not part of the Docutils API but a developer aid not to be relied on in document generation, the respective patches were reversed.
A solution would be to store NULL-escaped text strings in the doctree nodes , e.g.
- return [self.node_class(rawtext, utils.unescape(text), **options)], []
+ return [self.node_class(rawtext, text, **options)], []
and unescape in nodes.Text.astext():
def astext(self):
- return reprunicode(self)
+ return reprunicode(docutils.utils.unescape(self))
This enables functions and transforms processing Text nodes
to respect backslash escapes.
The attached patch to r8241 fixes the problem and passes all tests (including 2 new tests for escaped markup).
Diff:
Diff:
Patch applied in [r8284] .
Related
Commit: [r8284]
This fix now breaks my code.
with the log file
Could you please undo this change or provide a workaround, e.g., a "try...except" (as would be reasonable to do)?
Actually, this fix is only in the development version (0.16.dev). Your problem with the code is due to
the (partially reversed) addition of "sourcecode" to some more nodes in 0.15 in combination with a non-standard node added to the doctree. (See discussion in #369.)
Hi folks!
I started faicing the similar issue as @alx posted. I guess first time it had happened at our project's CI several week ago. Downgrading to docutils<0.15.0 helps.
The code that triggers docutils to fail is a custom role. The simplified version looks like:
As said in the discussion in [#369], this should be solved by nesting the
Text
node inside aninline
node.(Besides this, the cited code should work with the repository version 0.16.dev (try a snapshot).)
Related
Bugs:
#369