[Python-checkins] r62693 - in doctools/trunk/sphinx: latexwriter.py util/smartypants.py
georg.brandl
python-checkins at python.org
Sun May 4 10:24:25 CEST 2008
Author: georg.brandl
Date: Sun May 4 10:24:25 2008
New Revision: 62693
Log:
Educate quotes in the LaTeX writer.
Modified:
doctools/trunk/sphinx/latexwriter.py
doctools/trunk/sphinx/util/smartypants.py
Modified: doctools/trunk/sphinx/latexwriter.py
==============================================================================
--- doctools/trunk/sphinx/latexwriter.py (original)
+++ doctools/trunk/sphinx/latexwriter.py Sun May 4 10:24:25 2008
@@ -21,6 +21,7 @@
from sphinx import addnodes
from sphinx import highlighting
+from sphinx.util.smartypants import educateQuotesLatex
# XXX: Move to a template?
HEADER = r'''%% Generated by Sphinx.
@@ -899,7 +900,8 @@
if self.verbatim is not None:
self.verbatim += node.astext()
else:
- self.body.append(self.encode(node.astext()))
+ text = self.encode(node.astext())
+ self.body.append(educateQuotesLatex(text))
def depart_Text(self, node):
pass
Modified: doctools/trunk/sphinx/util/smartypants.py
==============================================================================
--- doctools/trunk/sphinx/util/smartypants.py (original)
+++ doctools/trunk/sphinx/util/smartypants.py Sun May 4 10:24:25 2008
@@ -189,6 +189,48 @@
return s.replace('"', "“")
+def educateQuotesLatex(s):
+ """
+ Parameter: String.
+
+ Returns: The string, with double quotes corrected to LaTeX quotes.
+
+ Example input: "Isn't this fun?"
+ Example output: ``Isn't this fun?'';
+ """
+
+ # Special case if the very first character is a quote
+ # followed by punctuation at a non-word-break. Close the quotes by brute force:
+ s = single_quote_start_re.sub("\x04", s)
+ s = double_quote_start_re.sub("\x02", s)
+
+ # Special case for double sets of quotes, e.g.:
+ # <p>He said, "'Quoted' words in a larger quote."</p>
+ s = double_quote_sets_re.sub("\x01\x03", s)
+ s = single_quote_sets_re.sub("\x03\x01", s)
+
+ # Special case for decade abbreviations (the '80s):
+ s = decade_abbr_re.sub("\x04", s)
+
+ s = opening_single_quotes_regex.sub("\\1\x03", s)
+ s = closing_single_quotes_regex.sub("\\1\x04", s)
+ s = closing_single_quotes_regex_2.sub("\\1\x04\\2", s)
+
+ # Any remaining single quotes should be opening ones:
+ s = s.replace("'", "\x03")
+
+ s = opening_double_quotes_regex.sub("\\1\x01", s)
+ s = closing_double_quotes_regex.sub("\x02", s)
+ s = closing_double_quotes_regex_2.sub("\\1\x02", s)
+
+ # Any remaining quotes should be opening ones.
+ s = s.replace('"', "\x01")
+
+ # Finally, replace all helpers with quotes.
+ return s.replace("\x01", "``").replace("\x02", "''").\
+ replace("\x03", "`").replace("\x04", "'")
+
+
def educateBackticks(s):
"""
Parameter: String.
More information about the Python-checkins
mailing list