From 2b48f393598dad13787a297a2a58b72792ff396b Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 17 Mar 2012 11:10:56 -0400 Subject: [PATCH] Fixes for smartypants from http://www.mobileread.com/forums/showthread.php?t=171920 submitted by Leigh Parry. --- src/calibre/utils/smartypants.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/calibre/utils/smartypants.py b/src/calibre/utils/smartypants.py index 8763a313fc..fa3119bf53 100644 --- a/src/calibre/utils/smartypants.py +++ b/src/calibre/utils/smartypants.py @@ -591,6 +591,21 @@ def educateQuotes(str): str = re.sub(r'''""''', """””""", str) str = re.sub(r"""''""", """’’""", str) + # Special case for Quotes at inside of other entities, e.g.: + #

A double quote--"within dashes"--would be nice.

+ str = re.sub(r"""(?<=\W)"(?=\w)""", r"""“""", str) + str = re.sub(r"""(?<=\W)'(?=\w)""", r"""‘""", str) + str = re.sub(r"""(?<=\w)"(?=\W)""", r"""”""", str) + str = re.sub(r"""(?<=\w)'(?=\W)""", r"""’""", str) + + # Special case for Quotes at end of line with a preceeding space (may change just to end of line) + str = re.sub(r"""(?<=\s)"$""", r"""”""", str) + str = re.sub(r"""(?<=\s)'$""", r"""’""", str) + + # Special case for Quotes at beginning of line with a space - multiparagraph quoted text: + str = re.sub(r"""^"(?=\s)""", r"""“""", str) + str = re.sub(r"""^'(?=\s)""", r"""‘""", str) + # Special case for decade abbreviations (the '80s): str = re.sub(r"""\b'(?=\d{2}s)""", r"""’""", str)