mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Simplify search and replace.
This commit is contained in:
commit
ade8f7a797
@ -453,27 +453,14 @@ class HTMLPreProcessor(object):
|
||||
if not getattr(self.extra_opts, 'keep_ligatures', False):
|
||||
html = _ligpat.sub(lambda m:LIGATURES[m.group()], html)
|
||||
|
||||
if getattr(self.extra_opts, 'sr3_search', None):
|
||||
for search, replace in [['sr3_search', 'sr3_replace'], ['sr2_search', 'sr2_replace'], ['sr1_search', 'sr1_replace']]:
|
||||
search_pattern = getattr(self.extra_opts, search, '')
|
||||
if search_pattern:
|
||||
try:
|
||||
rules.insert(0, (re.compile(self.extra_opts.sr3_search), self.extra_opts.sr3_replace))
|
||||
except:
|
||||
import traceback
|
||||
print 'Failed to parse sr3-search regexp'
|
||||
traceback.print_exc()
|
||||
if getattr(self.extra_opts, 'sr2_search', None):
|
||||
try:
|
||||
rules.insert(0, (re.compile(self.extra_opts.sr2_search), self.extra_opts.sr2_replace))
|
||||
except:
|
||||
import traceback
|
||||
print 'Failed to parse sr2-search regexp'
|
||||
traceback.print_exc()
|
||||
if getattr(self.extra_opts, 'sr1_search', None):
|
||||
try:
|
||||
rules.insert(0, (re.compile(self.extra_opts.sr1_search), self.extra_opts.sr1_replace))
|
||||
except:
|
||||
import traceback
|
||||
print 'Failed to parse sr1-search regexp'
|
||||
traceback.print_exc()
|
||||
search_re = re.compile(search_pattern)
|
||||
rules.insert(0, (search_re, getattr(self.extra_opts, replace, '')))
|
||||
except Exception as e:
|
||||
self.log.error('Failed to parse %s regexp because %s' % (search, e))
|
||||
|
||||
end_rules = []
|
||||
# delete soft hyphens - moved here so it's executed after header/footer removal
|
||||
|
Loading…
x
Reference in New Issue
Block a user