posthtml / posthtml-parser

Parse HTML/XML to PostHTMLTree

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Empty Value Attribute Handling

NiklasPor opened this issue Β· comments

Hi all, great package, love it so far πŸš€

I'm currently struggling with one problem tho: The HTML attributes that have no specific value, actually automatically get transformed to have a value of their own key.

I think this transformation is kinda weird, especially since the current HTML standard is specifying that the value of an empty attribute is actually an empty string, not a string that matches the name of the attribute:

image
https://html.spec.whatwg.org/multipage/syntax.html#attributes-2

Additionally, it breaks the behavior of some JS / HTML frameworks, which is a pity. Here's a quick example without any plugins installed:

Input

<div a b c="c"></div>

Expected

<div a b c="c"></div>

Output

<div c="c" a="a" b="b" other="other"></div>

I'd also be open to contributing and fixing this if it would be appreciated.

Kind regards
Niklas

I'd also be open to contributing and fixing this if it would be appreciated.

@NiklasPor Hello, we appreciate any contribution that benefits the package, feel free to do so.

This task is more likely to be posthtml-render (I will transfer the task to this package) i.e. it is there that it is necessary to enumerate a list of single attributes and set the corresponding values.

@Scrum Hm, when I debugged this I also received {a: 'a'} as the attribute object for a tag like this <div a></div>.

So I think this is mainly part of the parser, but also requires change inside the renderer.