TXT Input: Textile: Rely on smarty pants to handle quotes.

This commit is contained in:
John Schember 2011-03-21 19:12:54 -04:00
parent 2d46e35a6c
commit 15fa4f71c4
3 changed files with 9 additions and 12 deletions

View File

@ -211,16 +211,6 @@ class Textile(object):
(re.compile(r'(\d+\'?\"?)( ?)x( ?)(?=\d+)'), r'\1\2×\3'), # dimension sign
(re.compile(r'(\d+)\'', re.I), r'\1′'), # prime
(re.compile(r'(\d+)\"', re.I), r'\1″'), # prime-double
(re.compile(r'(\')\''), r'\1’'), # single closing - following another
(re.compile(r"(\w)\'(\w)"), r'\1’\2'), # apostrophe's
(re.compile(r'(\s)\'(\d+\w?)\b(?!\')'), r'\1’\2'), # back in '88
(re.compile(r'(\s\[)\''), r'\1‘'), # single opening - following ws+[
(re.compile(r'(\S)\'(?=\s|'+pnct+'|<|$)', re.M), r'\1&#8217;'), # single closing
(re.compile(r'\''), r'&#8216;'), # single opening
(re.compile(r'(\")\"'), r'\1&#8221;'), # double closing - following another
(re.compile(r'(\s\[)\"'), r'\1&#8220;'), # double opening - following whitespace+[
(re.compile(r'(\S)\"(?=\s|'+pnct+'|<|$)', re.M), r'\1&#8221;'), # double closing
(re.compile(r'"'), r'&#8220;'), # double opening
(re.compile(r'\b([A-Z][A-Z0-9]{2,})\b(?:[(]([^)]*)[)])'), r'<acronym title="\2">\1</acronym>'), # 3+ uppercase acronym
(re.compile(r'\b([A-Z][A-Z\'\-]+[A-Z])(?=[\s.,\)>])'), r'<span class="caps">\1</span>'), # 3+ uppercase
(re.compile(r'\b(\s{0,1})?\.{3}'), r'\1&#8230;'), # ellipsis
@ -870,11 +860,11 @@ class Textile(object):
'hello <span class="bob">span <strong>strong</strong> and <b>bold</b></span> goodbye'
"""
qtags = (r'\*\*', r'\*', r'\?\?', r'\-', r'__', r'_', r'%', r'\+', r'~', r'\^')
pnct = ".,\"'?!;:()"
pnct = ".,\"'?!;:"
for qtag in qtags:
pattern = re.compile(r"""
(?:^|(?<=[\s>%(pnct)s])|\[|([\]}]))
(?:^|(?<=[\s>%(pnct)s\(])|\[|([\]}]))
(%(qtag)s)(?!%(qtag)s)
(%(c)s)
(?::(\S+))?

View File

@ -165,6 +165,7 @@ class TXTInput(InputFormatPlugin):
elif options.formatting_type == 'textile':
log.debug('Running text through textile conversion...')
html = convert_textile(txt)
setattr(options, 'smarten_punctuation', True)
else:
log.debug('Running text through basic conversion...')
flow_size = getattr(options, 'flow_size', 0)

View File

@ -584,6 +584,12 @@ def educateQuotes(str):
# <p>He said, "'Quoted' words in a larger quote."</p>
str = re.sub(r""""'(?=\w)""", """&#8220;&#8216;""", str)
str = re.sub(r"""'"(?=\w)""", """&#8216;&#8220;""", str)
str = re.sub(r'''""(?=\w)''', """&#8220;&#8220;""", str)
str = re.sub(r"""''(?=\w)""", """&#8216;&#8216;""", str)
str = re.sub(r'''\"\'''', """&#8221;&#8217;""", str)
str = re.sub(r'''\'\"''', """&#8217;&#8221;""", str)
str = re.sub(r'''""''', """&#8221;&#8221;""", str)
str = re.sub(r"""''""", """&#8217;&#8217;""", str)
# Special case for decade abbreviations (the '80s):
str = re.sub(r"""\b'(?=\d{2}s)""", r"""&#8217;""", str)