Menu

#241 Support custom HtmlElement

2.24
pending
nobody
None
1
2017-01-11
2017-01-10
Mark Fulton
No

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?

Discussion

  • Ahmed Ashour

    Ahmed Ashour - 2017-01-11
    • status: open --> pending
     
  • Ahmed Ashour

    Ahmed Ashour - 2017-01-11

    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.

     
  • Mark Fulton

    Mark Fulton - 2017-01-11

    Consider the following HTML:

    <div class="register-switch">
        <input type="radio" name="someFlag" value="Y" id="ans1_Y" class="register-switch-input">
        <label for="ans1_Y" class="register-switch-label">Yes</label>
        <input type="radio" name="someFlag" value="N" id="ans1_N" class="register-switch-input">
        <label for="ans1_N" class="register-switch-label">No</label>
    </div>
    

    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 called RegisterSwitch 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 different ElementFactory so that I can create an HtmlRegisterSwitch which extends HtmlElement. 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 meaninful HtmlElement subclasses for working with menus, tabs, etc.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.