I see that there is a public ElementFactory
interface but I don't see any way to register an instance of such with HTMLParser
, etc.
Can a way be added to register custom HtmlElement implementations so that I can use my own concrete classes instead of HtmlUnknownElement
?
This is one area which is not meant to be changed by the user.
What is missing in HtmlUnknownElement that you would like to see?
It can be committed, if it is useful for others.
Consider the following HTML:
My site uses a custom web component/element (okay, not an official HTML5.1 custom element but you get the idea). Sometimes these "register switches" have two options, sometimes three, etc. I have a class that implements
org.w3c.dom.Element
calledRegisterSwitch
to wrap the logic for querying input values, label texts, etc. It would be nice if I could simply register something that says any node matching some criteria (e.g. css selector ".register-switch") should use a differentElementFactory
so that I can create anHtmlRegisterSwitch
which extendsHtmlElement
. The child nodes will still get parsed normally but then instead of having to "re-parse" the tree to lay my custom elements on top of it I can back them right in. Does that make sense? I also have, for example, a custom checkbox control, this could also be used for WAI-ARIA markup too to parse more meaninfulHtmlElement
subclasses for working with menus, tabs, etc.