rehypejs / rehype-minify

plugins to minify HTML
https://unifiedjs.com
MIT License
90 stars 16 forks source link

`rehype-minify-enumerated-attribute`: support more complex match conditions? #39

Closed karlhorky closed 3 years ago

karlhorky commented 3 years ago

Subject of the feature

Copied from https://github.com/rehypejs/rehype-minify/issues/36#issuecomment-749496827

Additionally, I wonder if it would make sense to add additional information to address the caveat you noted in your comment for attributes like inputMode (where they only apply to elements with either a) presence of an attribute or b) an attribute set to a certain value):

  inputMode: {
    // In fact only applies to `text`, `search`, and `password`.
    tagNames: 'input',

Eg. either changing tagNames to selectors and allowing a value like ['input[type="text"]', 'input[type="search"]', 'input[type="password"]'], or adding an additional field like tagMatcher, which could allow a more powerful approach like a function ((el) => /text|search|password/.test(el.type)). I suppose the law of least power would suggest something closer to the first approach though.

Problem

Some attributes apply to only elements with some "matching condition" as explained above (eg. the inputMode applies only to some input elements, not all of them)

Expected behavior

This information could be in the data provided.

Alternatives

wooorm commented 3 years ago

Replaced the tagNames with a selector!

karlhorky commented 3 years ago

Nice, thanks! 🙌