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! # (regex, repl) tuple list: order matters!
_render_regex_src = [ _render_regex_src = [
('<(head|HEAD).*?>.*?<\\/(head|HEAD)>', ''), ('<(head|HEAD)(\s+[^>]*)?>.*?<\\/(head|HEAD)>', ''),
('<(script|SCRIPT).*?>.*?<\\/(script|SCRIPT)>', ''), ('<(script|SCRIPT)(\s+[^>]*)?>.*?<\\/(script|SCRIPT)>', ''),
('<(style|STYLE).*?>.*?<\\/(style|STYLE)>', ''), ('<(style|STYLE)(\s+[^>]*)?>.*?<\\/(style|STYLE)>', ''),
('<(audio|AUDIO).*?>.*?<\\/(audio|AUDIO)>', ''), ('<(audio|AUDIO)(\s+[^>]*)?>.*?<\\/(audio|AUDIO)>', ''),
('<(video|VIDEO).*?>.*?<\\/(video|VIDEO)>', ''), ('<(video|VIDEO)(\s+[^>]*)?>.*?<\\/(video|VIDEO)>', ''),
('<(object|OBJECT).*?>.*?<\\/(object|OBJECT)>', ''), ('<(object|OBJECT)(\s+[^>]*)?>.*?<\\/(object|OBJECT)>', ''),
('<(canvas|CANVAS).*?>.*?<\\/(canvas|CANVAS)>', ''), ('<(canvas|CANVAS)(\s+[^>]*)?>.*?<\\/(canvas|CANVAS)>', ''),
('<!-- (decktext_begin|DECKTEXT_BEGIN) -->', _start_boundary), ('<!-- (decktext_begin|DECKTEXT_BEGIN) -->', _start_boundary),
('<!-- (decktext_end|DECKTEXT_END) -->', _end_boundary), ('<!-- (decktext_end|DECKTEXT_END) -->', _end_boundary),
('<img.*?>', _replace_img_with_alt), ('<img(\s+[^>]*)?>', _replace_img_with_alt),
('<a\\ .*?href="(.+?)".*?>(.+?)<\\/a>', _link_repl), ('<a\\ .*?href="(.+?)".*?>(.+?)<\\/a>', _link_repl),
('<(hr|HR).*?>', f'\n{_page_boundary}\n'), ('<(hr|HR)(\s+[^>]*)?>', f'\n{_page_boundary}\n'),
('<(b|B|strong|STRONG).*?>', '**'), ('<(b|B|strong|STRONG)(\s+[^>]*)?>', '**'),
('<\\/(b|B|strong|STRONG)>', '**'), ('<\\/(b|B|strong|STRONG)>', '**'),
('<(i|I|em|EM).*?>', '_'), ('<(i|I|em|EM)(\s+[^>]*)?>', '_'),
('<\\/(i|I|em|EM)>', '_'), ('<\\/(i|I|em|EM)>', '_'),
('<(tt|TT|code|CODE).*?>', '`'), ('<(tt|TT|code|CODE)(\s+[^>]*)?>', '`'),
('<\\/(tt|TT|code|CODE)>', '`'), ('<\\/(tt|TT|code|CODE)>', '`'),
('<(s|S|del|DEL).*?>', '~~'), ('<(s|S|del|DEL)(\s+[^>]*)?>', '~~'),
('<\\/(s|S|del|DEL)>', '~~'), ('<\\/(s|S|del|DEL)>', '~~'),
('<(pre|PRE|xmp|XMP).*?>', '\n```\n'), ('<(pre|PRE|xmp|XMP)(\s+[^>]*)?>', '\n```\n'),
('<\\/(pre|PRE|xmp|XMP)>', '\n```\n'), ('<\\/(pre|PRE|xmp|XMP)>', '\n```\n'),
('<(blockquote|BLOCKQUOTE).*?>', '\n>> '), ('<(blockquote|BLOCKQUOTE)(\s+[^>]*)?>', '\n>> '),
('<\\/(blockquote|BLOCKQUOTE)>', '\n'), ('<\\/(blockquote|BLOCKQUOTE)>', '\n'),
('<(li|LI).*?>', '* '), ('<(li|LI)(\s+[^>]*)?>', '* '),
('<\\/(li|LI)>', '\n'), ('<\\/(li|LI)>', '\n'),
('<.+?>', ''), ('<.+?>', ''),
('&lt;', '<'), ('&lt;', '<'),