Skip to content

Improve support for pipelining tree transforms #791

Description

@Daverball

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions