]>
git.scottworley.com Git - paperdoorknob/blob - htmlfilter.py
1 # paperdoorknob: Print glowfic
3 # This program is free software: you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License as published by the
5 # Free Software Foundation, version 3.
10 from typing
import Callable
, List
, Tuple
13 HTMLFilters
: List
[Tuple
[str, Callable
[[bytes], bytes]]] = [
14 ("NoNBSP", lambda x
: re
.sub(b
"( |\xc2\xa0)", b
" ", x
)),
18 class HTMLFilterError(Exception):
22 def ApplyHTMLFilters(filter_list
: str, data
: bytes) -> bytes:
23 for filter_name
in filter_list
.split(','):
24 filters
= [f
for (name
, f
) in HTMLFilters
if name
== filter_name
]
26 raise HTMLFilterError(f
"Unknown HTML filter: {filter_name}")
28 raise HTMLFilterError(
29 f
"Multiple HTML filters with the same name!?: {filter_name}")
30 data
= filters
[0](data
)