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

[FEATURE] collapseBooleanAttributes doesn't work with custom attributes #55

Open
unbiased-dev opened this issue Mar 11, 2021 · 2 comments

Comments

@unbiased-dev
Copy link

const minify = require("html-minifier-terser").minify;

console.log(
  minify(
    '<a href="#" router="true" another="another" variant=variant test=true>Test</a>',
    {
      collapseBooleanAttributes: true
    }
  )
);

result

<a href="#" router="true" another="another" variant="variant" test="true">Test</a>

expected result

<a href="#" router another variant test>Test</a>

Are my expectations incorrect?

@unbiased-dev
Copy link
Author

Reading the source it looks like it only checks if the attribute is one of predefined attributes.

var isSimpleBoolean = createMapFromString('allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,default,defaultchecked,defaultmuted,defaultselected,defer,disabled,enabled,formnovalidate,hidden,indeterminate,inert,ismap,itemscope,loop,multiple,muted,nohref,noresize,noshade,novalidate,nowrap,open,pauseonexit,readonly,required,reversed,scoped,seamless,selected,sortable,truespeed,typemustmatch,visible');
var isBooleanValue = createMapFromString('true,false');

Would adding support for collapsing custom boolean attributes be supported? Something like customAttrBooleanCollapse?

@unbiased-dev unbiased-dev changed the title [BUG] collapseBooleanAttributes doesn't seem to work at all [FEATURE] collapseBooleanAttributes doesn't seem to work at all Mar 11, 2021
@unbiased-dev unbiased-dev changed the title [FEATURE] collapseBooleanAttributes doesn't seem to work at all [FEATURE] collapseBooleanAttributes doesn't work with custom attributes Mar 11, 2021
@KartikSoneji
Copy link
Contributor

In HTML5, all custom attributes must have the data- prefix.
The only exception seems to be custom elements, which can have any attributes.

Given that <a href="#" router="true" another="another" variant=variant test=true>Test</a> is not valid HTML5, I don't think it makes sense to allow collapsing custom attributes.
Also, deciding which attributes are boolean is another issue altogether.

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

2 participants