-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Add escape sequences to SmartyPants quote processing #498
Description
Sphinx's smartypants.py is based on an older version dated Sat, 13 Aug 2005. A later version is available at http://web.chad.org/projects/smartypants.py/ dated 27 Jul 2007. I didn't look at all the differences but the newer version does include this function:
def processEscapes(str):
r"""
Parameter: String.
Returns: The string, with after processing the following backslash
escape sequences. This is useful if you want to force a "dumb"
quote or other character to appear.
Escape Value
------ -----
\\ \
\" "
\' '
\. .
\- -
\` `
"""
str = re.sub(r"""\\\\""", r"""\""", str)
str = re.sub(r'''\\"''', r""""""", str)
str = re.sub(r"""\\'""", r"""'""", str)
str = re.sub(r"""\\\.""", r""".""", str)
str = re.sub(r"""\\-""", r"""-""", str)
str = re.sub(r"""\\`""", r"""`""", str)
return str
Changing the existing sphinx_smarty_pants() in sphinx/util/smartypants.py to:
def sphinx_smarty_pants(t):
t = processEscapes(t)
t = t.replace('"', '"')
t = educateDashesOldSchool(t)
t = educateQuotes(t)
t = t.replace('"', '"')
return t
Lets you say \\' when SmartyPant insists on using the wrong type of single quote. (Note: you have to double the \ to get this to work.)
I'd personally prefer to have \\``be replaced with the left single quote entity ‘ and'` be replaced with the right single quote entity ’. Maybe this behavior could be turned on with a suitable HTML option?
There are probably other improvements in the newer smartypants.py (the whole topic is fraught with special cases), but I didn't investigate them.
- Bitbucket: https://bitbucket.org/birkenfeld/sphinx/issue/498
- Originally reported by: tpowers
- Originally created at: 2010-08-15T03:39:16.548