diff options
| author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2019-07-24 10:52:23 +0000 |
|---|---|---|
| committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2019-07-24 10:52:23 +0000 |
| commit | 0bc7f09b946223ff23f3874483f5e292daf60d85 (patch) | |
| tree | fac06e59c4c0aba7496a1cb6f98c5a7810202dbb /docutils/transforms/universal.py | |
| parent | d9158c87de7ce467a442aec892e3dbc8fdc06588 (diff) | |
| download | docutils-0bc7f09b946223ff23f3874483f5e292daf60d85.tar.gz | |
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
Diffstat (limited to 'docutils/transforms/universal.py')
| -rw-r--r-- | docutils/transforms/universal.py | 21 |
1 files changed, 11 insertions, 10 deletions
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 |
