optimize decktext algo a bit

This commit is contained in:
Luxferre
2025-12-31 13:41:38 +02:00
parent 66000bdd3a
commit 4e5cf7728f
+16 -16
View File
@@ -29,31 +29,31 @@ def _replace_img_with_alt(match):
# (regex, repl) tuple list: order matters!
_render_regex_src = [
('<(head|HEAD).*?>.*?<\\/(head|HEAD)>', ''),
('<(script|SCRIPT).*?>.*?<\\/(script|SCRIPT)>', ''),
('<(style|STYLE).*?>.*?<\\/(style|STYLE)>', ''),
('<(audio|AUDIO).*?>.*?<\\/(audio|AUDIO)>', ''),
('<(video|VIDEO).*?>.*?<\\/(video|VIDEO)>', ''),
('<(object|OBJECT).*?>.*?<\\/(object|OBJECT)>', ''),
('<(canvas|CANVAS).*?>.*?<\\/(canvas|CANVAS)>', ''),
('<(head|HEAD)(\s+[^>]*)?>.*?<\\/(head|HEAD)>', ''),
('<(script|SCRIPT)(\s+[^>]*)?>.*?<\\/(script|SCRIPT)>', ''),
('<(style|STYLE)(\s+[^>]*)?>.*?<\\/(style|STYLE)>', ''),
('<(audio|AUDIO)(\s+[^>]*)?>.*?<\\/(audio|AUDIO)>', ''),
('<(video|VIDEO)(\s+[^>]*)?>.*?<\\/(video|VIDEO)>', ''),
('<(object|OBJECT)(\s+[^>]*)?>.*?<\\/(object|OBJECT)>', ''),
('<(canvas|CANVAS)(\s+[^>]*)?>.*?<\\/(canvas|CANVAS)>', ''),
('<!-- (decktext_begin|DECKTEXT_BEGIN) -->', _start_boundary),
('<!-- (decktext_end|DECKTEXT_END) -->', _end_boundary),
('<img.*?>', _replace_img_with_alt),
('<img(\s+[^>]*)?>', _replace_img_with_alt),
('<a\\ .*?href="(.+?)".*?>(.+?)<\\/a>', _link_repl),
('<(hr|HR).*?>', f'\n{_page_boundary}\n'),
('<(b|B|strong|STRONG).*?>', '**'),
('<(hr|HR)(\s+[^>]*)?>', f'\n{_page_boundary}\n'),
('<(b|B|strong|STRONG)(\s+[^>]*)?>', '**'),
('<\\/(b|B|strong|STRONG)>', '**'),
('<(i|I|em|EM).*?>', '_'),
('<(i|I|em|EM)(\s+[^>]*)?>', '_'),
('<\\/(i|I|em|EM)>', '_'),
('<(tt|TT|code|CODE).*?>', '`'),
('<(tt|TT|code|CODE)(\s+[^>]*)?>', '`'),
('<\\/(tt|TT|code|CODE)>', '`'),
('<(s|S|del|DEL).*?>', '~~'),
('<(s|S|del|DEL)(\s+[^>]*)?>', '~~'),
('<\\/(s|S|del|DEL)>', '~~'),
('<(pre|PRE|xmp|XMP).*?>', '\n```\n'),
('<(pre|PRE|xmp|XMP)(\s+[^>]*)?>', '\n```\n'),
('<\\/(pre|PRE|xmp|XMP)>', '\n```\n'),
('<(blockquote|BLOCKQUOTE).*?>', '\n>> '),
('<(blockquote|BLOCKQUOTE)(\s+[^>]*)?>', '\n>> '),
('<\\/(blockquote|BLOCKQUOTE)>', '\n'),
('<(li|LI).*?>', '* '),
('<(li|LI)(\s+[^>]*)?>', '* '),
('<\\/(li|LI)>', '\n'),
('<.+?>', ''),
('&lt;', '<'),