Fix #772267 (TXT to EPUB: Underlined words (following quotes?) fail to become italics) and fix bug when killing threaded jobs

This commit is contained in:
Kovid Goyal 2011-04-28 08:11:35 -06:00
commit df074821c4
2 changed files with 22 additions and 22 deletions

View File

@ -156,17 +156,17 @@ class HeuristicProcessor(object):
] ]
ITALICIZE_STYLE_PATS = [ ITALICIZE_STYLE_PATS = [
r'(?msu)(?<=[\s>])_(?P<words>[^_]+)_', ur'(?msu)(?<=[\s>"\'])_(?P<words>[^_]+)_',
r'(?msu)(?<=[\s>])/(?P<words>[^/\*>]+)/', ur'(?msu)(?<=[\s>"\'])/(?P<words>[^/\*>]+)/',
r'(?msu)(?<=[\s>])~~(?P<words>[^~]+)~~', ur'(?msu)(?<=[\s>"\'])~~(?P<words>[^~]+)~~',
r'(?msu)(?<=[\s>])\*(?P<words>[^\*]+)\*', ur'(?msu)(?<=[\s>"\'])\*(?P<words>[^\*]+)\*',
r'(?msu)(?<=[\s>])~(?P<words>[^~]+)~', ur'(?msu)(?<=[\s>"\'])~(?P<words>[^~]+)~',
r'(?msu)(?<=[\s>])_/(?P<words>[^/_]+)/_', ur'(?msu)(?<=[\s>"\'])_/(?P<words>[^/_]+)/_',
r'(?msu)(?<=[\s>])_\*(?P<words>[^\*_]+)\*_', ur'(?msu)(?<=[\s>"\'])_\*(?P<words>[^\*_]+)\*_',
r'(?msu)(?<=[\s>])\*/(?P<words>[^/\*]+)/\*', ur'(?msu)(?<=[\s>"\'])\*/(?P<words>[^/\*]+)/\*',
r'(?msu)(?<=[\s>])_\*/(?P<words>[^\*_]+)/\*_', ur'(?msu)(?<=[\s>"\'])_\*/(?P<words>[^\*_]+)/\*_',
r'(?msu)(?<=[\s>])/:(?P<words>[^:/]+):/', ur'(?msu)(?<=[\s>"\'])/:(?P<words>[^:/]+):/',
r'(?msu)(?<=[\s>])\|:(?P<words>[^:\|]+):\|', ur'(?msu)(?<=[\s>"\'])\|:(?P<words>[^:\|]+):\|',
] ]
for word in ITALICIZE_WORDS: for word in ITALICIZE_WORDS:
@ -518,13 +518,13 @@ class HeuristicProcessor(object):
if re.findall('(<|>)', replacement_break): if re.findall('(<|>)', replacement_break):
if re.match('^<hr', replacement_break): if re.match('^<hr', replacement_break):
if replacement_break.find('width') != -1: if replacement_break.find('width') != -1:
width = int(re.sub('.*?width(:|=)(?P<wnum>\d+).*', '\g<wnum>', replacement_break)) width = int(re.sub('.*?width(:|=)(?P<wnum>\d+).*', '\g<wnum>', replacement_break))
replacement_break = re.sub('(?i)(width=\d+\%?|width:\s*\d+(\%|px|pt|em)?;?)', '', replacement_break) replacement_break = re.sub('(?i)(width=\d+\%?|width:\s*\d+(\%|px|pt|em)?;?)', '', replacement_break)
divpercent = (100 - width) / 2 divpercent = (100 - width) / 2
hr_open = re.sub('45', str(divpercent), hr_open) hr_open = re.sub('45', str(divpercent), hr_open)
scene_break = hr_open+replacement_break+'</div>' scene_break = hr_open+replacement_break+'</div>'
else: else:
scene_break = hr_open+'<hr style="height: 3px; background:#505050" /></div>' scene_break = hr_open+'<hr style="height: 3px; background:#505050" /></div>'
elif re.match('^<img', replacement_break): elif re.match('^<img', replacement_break):
scene_break = self.scene_break_open+replacement_break+'</p>' scene_break = self.scene_break_open+replacement_break+'</p>'
else: else:
@ -584,10 +584,10 @@ class HeuristicProcessor(object):
#print "styles for this line are: "+str(styles) #print "styles for this line are: "+str(styles)
split_styles = [] split_styles = []
for style in styles: for style in styles:
#print "style is: "+str(style) #print "style is: "+str(style)
newstyle = style.split(':') newstyle = style.split(':')
#print "newstyle is: "+str(newstyle) #print "newstyle is: "+str(newstyle)
split_styles.append(newstyle) split_styles.append(newstyle)
styles = split_styles styles = split_styles
for style, setting in styles: for style, setting in styles:
if style == 'text-align' and setting != 'left': if style == 'text-align' and setting != 'left':

View File

@ -112,7 +112,7 @@ class ThreadedJob(BaseJob):
self.start_time = time.time() self.start_time = time.time()
self.duration = 0.0001 self.duration = 0.0001
else: else:
self.duration = time.time() - self.start_time() self.duration = time.time() - self.start_time
self.abort.set() self.abort.set()
self.log('Aborted job:', self.description) self.log('Aborted job:', self.description)