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

Self-closing tags #17

Open
dillonkearns opened this issue Mar 4, 2021 · 0 comments
Open

Self-closing tags #17

dillonkearns opened this issue Mar 4, 2021 · 0 comments

Comments

@dillonkearns
Copy link

Hello @hecrj! Thank you for the library. I am using this for a tool to convert raw HTML into code generated for https://github.com/matheus23/elm-tailwind-modules. The main use is to copy-paste examples from Tailwind docs and get valid Elm code generated.

I'm running into parser errors because the examples often use self-closing HTML tags within svg. I'm only parsing the raw nodes and then using those to generate Strings, so I don't actually need any fixes except for handling self-closing tag support for my use case (so this is not a request for any sort of svg support per se).

I would like to contribute this fix and wanted to start with a conversation before making a PR. I was able to make a change to handle self-closing tags like this:

dillonkearns@0e90d84

This seems to be perfectly robust. My main question is whether you want to handle special cases to explicitly disallow self-closing tags in some cases.

The HTML spec is surprisingly strict about disallowing self-closing tags in many cases.

Then, if the element is one of the void elements, or if the element is a foreign element, then there may be a single U+002F SOLIDUS character (/). This character has no effect on void elements, but on foreign elements it marks the start tag as self-closing.

And foreign elements are defined as

Foreign elements
Elements from the MathML namespace and the SVG namespace.

So my question is:

  1. Would you be open to a pull request adding support for self-closing tags?
  2. If so, what should I do about self-closing rules? Is it okay to allow self-closing tags anywhere (more permissive than the spec)? Or should some special care be taken to give a parser error when there is a self-closing tag in a context where it is disallowed by the spec?

If we go the approach of disallowing self-closing tags outside of foreign elements, then it may require more context in the parser to keep track of when it goes into an SVG element. That would mean checking for the SVG namespace

The SVG namespace is "http://www.w3.org/2000/svg".

Thanks again for the package! I'd love to contribute the change if you're open to it, let me know your thoughts.

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

No branches or pull requests

1 participant