Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for custom self-closing tags? #767

Closed
gilbert opened this issue Mar 30, 2021 · 5 comments · Fixed by #785
Closed

Support for custom self-closing tags? #767

gilbert opened this issue Mar 30, 2021 · 5 comments · Fixed by #785

Comments

@gilbert
Copy link

gilbert commented Mar 30, 2021

Hi, would it be possible to provide a way for htmparser2 to expose an option to allow custom tags that auto self close? In other words, an option to extend this record? I'm working on an html-based framework and would like to allow users to write a <page> tag without worrying about whether they need to write </page> or end with />.

Thanks for the great library.

@gilbert
Copy link
Author

gilbert commented Apr 9, 2021

Ok, so I pointed to the wrong thing. Turns out I need to extend voidElements instead.

Here's the commit I'm using to do this. If you'd like a PR, let me know. Or feel free to copy in the code yourself, no attribution needed.

@floratmin
Copy link

I am also trying to parse .svelte files which have custom self-closing tags and on top there can be props in the form prop={javascript code} or prop="{javascript code}". When the first one comes as last prop and there is no space between the slash of the self closing tag, than the slash is added to the property like {javascript code}/ and there is no possibility to close the tag. Actually it would be sufficient for me to have access to the whole tag as a string on onopentag.

@fb55
Copy link
Owner

fb55 commented Apr 19, 2021

@floratmin There is a fork of this project for Svelte: https://github.com/alexprey/htmlparser2

@gilbert How do you feel about having to extend the parser to get this functionality? I'm thinking about moving the check for a self-closing tag to a separate method, which you could override.

@floratmin
Copy link

@fb55 thank you to make me aware of this library, but same problem there. I reported it there.

@gilbert
Copy link
Author

gilbert commented Apr 20, 2021

@fb55 Thats sounds great to me!

fb55 added a commit that referenced this issue Apr 22, 2021
Allows users to override this method and get custom void-element behavior.

Fixes #767
@fb55 fb55 closed this as completed in #785 Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants