From 0d57e05104013d91893666905805cd4b8b10181e Mon Sep 17 00:00:00 2001 From: milde Date: Sat, 10 Dec 2016 17:50:59 +0000 Subject: [PATCH] Apply patch by Neil Schemenauer to fix bad string escapes (http://permalink.gmane.org/gmane.text.docutils.devel/7521). git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@7995 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/io.py | 2 +- docutils/parsers/rst/__init__.py | 2 +- docutils/transforms/peps.py | 2 +- docutils/utils/math/latex2mathml.py | 4 ++-- docutils/utils/math/math2html.py | 2 +- docutils/writers/_html_base.py | 2 +- docutils/writers/latex2e/__init__.py | 16 ++++++++-------- docutils/writers/manpage.py | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docutils/io.py b/docutils/io.py index 83a40c963..6dd63c261 100644 --- a/docutils/io.py +++ b/docutils/io.py @@ -122,7 +122,7 @@ class Input(TransformSpec): '%s.\n(%s)' % (', '.join([repr(enc) for enc in encodings]), ErrorString(error))) - coding_slug = re.compile(b("coding[:=]\s*([-\w.]+)")) + coding_slug = re.compile(b(r"coding[:=]\s*([-\w.]+)")) """Encoding declaration pattern.""" byte_order_marks = ((codecs.BOM_UTF8, 'utf-8'), # 'utf-8-sig' new in v2.5 diff --git a/docutils/parsers/rst/__init__.py b/docutils/parsers/rst/__init__.py index 7636411eb..b72af6b8f 100644 --- a/docutils/parsers/rst/__init__.py +++ b/docutils/parsers/rst/__init__.py @@ -145,7 +145,7 @@ class Parser(docutils.parsers.Parser): ('Inline markup recognized at word boundaries only ' '(adjacent to punctuation or whitespace). ' 'Force character-level inline markup recognition with ' - '"\ " (backslash + space). Default.', + '"\\ " (backslash + space). Default.', ['--word-level-inline-markup'], {'action': 'store_false', 'dest': 'character_level_inline_markup'}), ('Inline markup recognized anywhere, regardless of surrounding ' diff --git a/docutils/transforms/peps.py b/docutils/transforms/peps.py index b89cf41c7..9babf3cc5 100644 --- a/docutils/transforms/peps.py +++ b/docutils/transforms/peps.py @@ -113,7 +113,7 @@ class Headers(Transform): elif name in ('replaces', 'replaced-by', 'requires'): newbody = [] space = nodes.Text(' ') - for refpep in re.split(',?\s+', body.astext()): + for refpep in re.split(r',?\s+', body.astext()): pepno = int(refpep) newbody.append(nodes.reference( refpep, refpep, diff --git a/docutils/utils/math/latex2mathml.py b/docutils/utils/math/latex2mathml.py index c0f233178..661e6770e 100644 --- a/docutils/utils/math/latex2mathml.py +++ b/docutils/utils/math/latex2mathml.py @@ -151,8 +151,8 @@ mathscr = { } negatables = {'=': u'\u2260', - '\in': u'\u2209', - '\equiv': u'\u2262'} + r'\in': u'\u2209', + r'\equiv': u'\u2262'} # LaTeX to MathML translation stuff: class math: diff --git a/docutils/utils/math/math2html.py b/docutils/utils/math/math2html.py index c65485b63..6a335196d 100644 --- a/docutils/utils/math/math2html.py +++ b/docutils/utils/math/math2html.py @@ -4101,7 +4101,7 @@ class FormulaCommand(FormulaBit): def emptycommand(self, pos): """Check for an empty command: look for command disguised as ending. - Special case against '{ \{ \} }' situation.""" + Special case against '{ \\{ \\} }' situation.""" command = '' if not pos.isout(): ending = pos.nextending() diff --git a/docutils/writers/_html_base.py b/docutils/writers/_html_base.py index e00fc1778..6d4938d03 100644 --- a/docutils/writers/_html_base.py +++ b/docutils/writers/_html_base.py @@ -1032,7 +1032,7 @@ class HTMLTranslator(nodes.NodeVisitor): wrappers = {# math_mode: (inline, block) 'mathml': ('$%s$', u'\\begin{%s}\n%s\n\\end{%s}'), 'html': ('$%s$', u'\\begin{%s}\n%s\n\\end{%s}'), - 'mathjax': ('\(%s\)', u'\\begin{%s}\n%s\n\\end{%s}'), + 'mathjax': (r'\(%s\)', u'\\begin{%s}\n%s\n\\end{%s}'), 'latex': (None, None), } wrapper = wrappers[self.math_output][math_env != ''] diff --git a/docutils/writers/latex2e/__init__.py b/docutils/writers/latex2e/__init__.py index e41438d32..f91d3963a 100644 --- a/docutils/writers/latex2e/__init__.py +++ b/docutils/writers/latex2e/__init__.py @@ -1194,7 +1194,7 @@ class LaTeXTranslator(nodes.NodeVisitor): (none, self.literal_block_env, self.literal_block_options, - none ) = re.split('(\w+)(.*)', settings.literal_block_env) + none ) = re.split(r'(\w+)(.*)', settings.literal_block_env) elif settings.use_verbatim_when_possible: self.literal_block_env = 'verbatim' # @@ -1462,7 +1462,7 @@ class LaTeXTranslator(nodes.NodeVisitor): def encode(self, text): """Return text with 'problematic' characters escaped. - * Escape the special printing characters ``# $ % & ~ _ ^ \ { }``, + * Escape the special printing characters ``# $ % & ~ _ ^ \\ { }``, square brackets ``[ ]``, double quotes and (in OT1) ``< | >``. * Translate non-supported Unicode characters. * Separate ``-`` (and more in literal text) to prevent input ligatures. @@ -1561,7 +1561,7 @@ class LaTeXTranslator(nodes.NodeVisitor): def ids_to_labels(self, node, set_anchor=True): """Return list of label definitions for all ids of `node` - If `set_anchor` is True, an anchor is set with \phantomsection. + If `set_anchor` is True, an anchor is set with \\phantomsection. """ labels = ['\\label{%s}' % id for id in node.get('ids', [])] if set_anchor and labels: @@ -1919,7 +1919,7 @@ class LaTeXTranslator(nodes.NodeVisitor): self.titledata.append('%%% Title Data') # \title (empty \title prevents error with \maketitle) if self.title: - self.title.insert(0, '\phantomsection%\n ') + self.title.insert(0, '\\phantomsection%\n ') title = [''.join(self.title)] + self.title_labels if self.subtitle: title += [r'\\ % subtitle', @@ -2266,7 +2266,7 @@ class LaTeXTranslator(nodes.NodeVisitor): if pxunit is not None: sys.stderr.write('deprecation warning: LaTeXTranslator.to_latex_length()' ' option `pxunit` will be removed.') - match = re.match('(\d*\.?\d*)\s*(\S*)', length_str) + match = re.match(r'(\d*\.?\d*)\s*(\S*)', length_str) if not match: return length_str value, unit = match.groups()[:2] @@ -2378,7 +2378,7 @@ class LaTeXTranslator(nodes.NodeVisitor): self.out.append('\\end{DUlegend}\n') def visit_line(self, node): - self.out.append('\item[] ') + self.out.append(r'\item[] ') def depart_line(self, node): self.out.append('\n') @@ -2522,7 +2522,7 @@ class LaTeXTranslator(nodes.NodeVisitor): math_code = '\n'.join([math_code] + self.ids_to_labels(node)) if math_env == '$': if self.alltt: - wrapper = u'\(%s\)' + wrapper = ur'\(%s\)' else: wrapper = u'$%s$' else: @@ -2801,7 +2801,7 @@ class LaTeXTranslator(nodes.NodeVisitor): line = ', line~%s' % node['line'] except KeyError: line = '' - self.out.append('\n\n{\color{red}%s/%s} in \\texttt{%s}%s\n' % + self.out.append('\n\n{\\color{red}%s/%s} in \\texttt{%s}%s\n' % (node['type'], node['level'], self.encode(node['source']), line)) if len(node['backrefs']) == 1: diff --git a/docutils/writers/manpage.py b/docutils/writers/manpage.py index 3ea996116..ef570137d 100644 --- a/docutils/writers/manpage.py +++ b/docutils/writers/manpage.py @@ -368,7 +368,7 @@ class Translator(nodes.NodeVisitor): tmpl = (".TH %(title_upper)s %(manual_section)s" " \"%(date)s\" \"%(version)s\" \"%(manual_group)s\"\n" ".SH NAME\n" - "%(title)s \- %(subtitle)s\n") + "%(title)s \\- %(subtitle)s\n") return tmpl % self._docinfo def append_header(self): -- 2.11.4.GIT