mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
A performance improvement for the HTML syntax highlighter
This commit is contained in:
parent
f52f6e4147
commit
3c0a6499a3
@ -21,7 +21,7 @@ from html5lib.constants import cdataElements, rcdataElements
|
|||||||
cdata_tags = cdataElements | rcdataElements
|
cdata_tags = cdataElements | rcdataElements
|
||||||
bold_tags = {'b', 'strong'} | {'h%d' % d for d in range(1, 7)}
|
bold_tags = {'b', 'strong'} | {'h%d' % d for d in range(1, 7)}
|
||||||
italic_tags = {'i', 'em'}
|
italic_tags = {'i', 'em'}
|
||||||
normal_pat = re.compile(r'[^<>&]')
|
normal_pat = re.compile(r'[^<>&]+')
|
||||||
entity_pat = re.compile(r'&#{0,1}[a-zA-Z0-9]{1,8};')
|
entity_pat = re.compile(r'&#{0,1}[a-zA-Z0-9]{1,8};')
|
||||||
tag_name_pat = re.compile(r'/{0,1}[a-zA-Z0-9:]+')
|
tag_name_pat = re.compile(r'/{0,1}[a-zA-Z0-9:]+')
|
||||||
space_chars = ' \t\r\n\u000c'
|
space_chars = ' \t\r\n\u000c'
|
||||||
@ -132,6 +132,7 @@ def mark_nbsp(state, text, nbsp_format):
|
|||||||
last = 0
|
last = 0
|
||||||
for m in nbsp_pat.finditer(text):
|
for m in nbsp_pat.finditer(text):
|
||||||
ans.extend([(m.start() - last, fmt), (m.end() - m.start(), nbsp_format)])
|
ans.extend([(m.start() - last, fmt), (m.end() - m.start(), nbsp_format)])
|
||||||
|
last = m.end()
|
||||||
if not ans:
|
if not ans:
|
||||||
ans = [(len(text), fmt)]
|
ans = [(len(text), fmt)]
|
||||||
return ans
|
return ans
|
||||||
|
Loading…
x
Reference in New Issue
Block a user