The problem
html5lib and bleach allowed some level of pipelining multiple transformations via filters.
While something as generic as filters would be cool, I also understand that it would eliminate a lot of the efficiency gains, so I'm perfectly happy to manually operate on the parsed nodes when necessary.
However there are still functions in turbohtml that could feasibly be pipelined. But currently you're forced to just call them in sequence. Which causes the document to be parsed and serialized multiple times.
The solution you'd like
I'm not sure how functions like turbohtml.clean.sanitize and turbohtml.clean.linkify and turbohtml.clean.minify are implemented in detail and whether they're modifying the nodes while streaming the parsed tokens, without ever building a full tree prior to serialization, or whether they all operate in three separate parse, transform, serialize stages.
If it's the latter, it would seem useful to provide a version of these functions that accept a Document and return a Document, so you only need to parse and serialize once, instead of for each transformation step.
If it's the former it might still be worth providing a way to chain the various operations in the clean module and/or ask for a Document to be returned, instead of a serialized string.
Prior art
html5lib's filters
Alternatives you've tried
Running e.g. linkify/sanitize/minify in sequence. In some cases even re-parsing the output again at the end and traversing the tree.
The problem
html5libandbleachallowed some level of pipelining multiple transformations viafilters.While something as generic as
filterswould be cool, I also understand that it would eliminate a lot of the efficiency gains, so I'm perfectly happy to manually operate on the parsed nodes when necessary.However there are still functions in
turbohtmlthat could feasibly be pipelined. But currently you're forced to just call them in sequence. Which causes the document to be parsed and serialized multiple times.The solution you'd like
I'm not sure how functions like
turbohtml.clean.sanitizeandturbohtml.clean.linkifyandturbohtml.clean.minifyare implemented in detail and whether they're modifying the nodes while streaming the parsed tokens, without ever building a full tree prior to serialization, or whether they all operate in three separate parse, transform, serialize stages.If it's the latter, it would seem useful to provide a version of these functions that accept a
Documentand return aDocument, so you only need to parse and serialize once, instead of for each transformation step.If it's the former it might still be worth providing a way to chain the various operations in the
cleanmodule and/or ask for aDocumentto be returned, instead of a serialized string.Prior art
html5lib's filters
Alternatives you've tried
Running e.g.
linkify/sanitize/minifyin sequence. In some cases even re-parsing the output again at the end and traversing the tree.