From 0bc7f09b946223ff23f3874483f5e292daf60d85 Mon Sep 17 00:00:00 2001 From: milde Date: Wed, 24 Jul 2019 10:52:23 +0000 Subject: Fix #332 and #342 (smartquotes problems). Standard backslash escape for smartquotes. No escape in roles descending from `inline literal`. git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk/docutils@8301 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/transforms/universal.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'docutils/transforms/universal.py') diff --git a/docutils/transforms/universal.py b/docutils/transforms/universal.py index d2ce4fbfd..59f0cd77f 100644 --- a/docutils/transforms/universal.py +++ b/docutils/transforms/universal.py @@ -222,9 +222,10 @@ class SmartQuotes(Transform): nodes_to_skip = (nodes.FixedTextElement, nodes.Special) """Do not apply "smartquotes" to instances of these block-level nodes.""" - literal_nodes = (nodes.image, nodes.literal, nodes.math, + literal_nodes = (nodes.FixedTextElement, nodes.Special, + nodes.image, nodes.literal, nodes.math, nodes.raw, nodes.problematic) - """Do not change quotes in instances of these inline nodes.""" + """Do apply smartquotes to instances of these inline nodes.""" smartquotes_action = 'qDe' """Setting to select smartquote transformations. @@ -240,14 +241,14 @@ class SmartQuotes(Transform): def get_tokens(self, txtnodes): # A generator that yields ``(texttype, nodetext)`` tuples for a list # of "Text" nodes (interface to ``smartquotes.educate_tokens()``). - - texttype = {True: 'literal', # "literal" text is not changed: - False: 'plain'} - for txtnode in txtnodes: - nodetype = texttype[isinstance(txtnode.parent, - self.literal_nodes)] - yield (nodetype, txtnode.astext()) - + for node in txtnodes: + if (isinstance(node.parent, self.literal_nodes) + or isinstance(node.parent.parent, self.literal_nodes)): + yield ('literal', unicode(node)) + else: + # SmartQuotes uses backslash escapes instead of null-escapes + txt = re.sub('(?<=\x00)([-\\\'".`])', r'\\\1', unicode(node)) + yield ('plain', txt) def apply(self): smart_quotes = self.document.settings.smart_quotes -- cgit v1.2.1