rehypejs / rehype-minify

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

What plugin removes quotes around attributes? #23

Closed jcayzac closed 6 years ago

jcayzac commented 6 years ago

Hi,

Using this preset, <a href="http://foo"> becomes <a href=http://foo>, which breaks a number of dependencies I'm using. I'm trying to figure out what plugin is responsible, but I couldn't so far.

What plugin should I exclude to get my attributes quoted again?

Thanks.

jcayzac commented 6 years ago

So, I'm very confused. This:

const processor = rehype()
  .use(require('rehype-preset-minify'))

…removes all quotes around attributes, but this:

const processor = rehype()
  .use(require('rehype-minify-attribute-whitespace'))
  .use(require('rehype-minify-css-style'))
  .use(require('rehype-minify-enumerated-attribute'))
  .use(require('rehype-minify-event-handler'))
  .use(require('rehype-minify-javascript-script'))
  .use(require('rehype-minify-javascript-url'))
  .use(require('rehype-minify-json-script'))
  .use(require('rehype-minify-media-attribute'))
  .use(require('rehype-minify-meta-color'))
  .use(require('rehype-minify-meta-content'))
  .use(require('rehype-minify-style-attribute'))
  .use(require('rehype-minify-whitespace'))
  .use(require('rehype-normalize-attribute-value-case'))
  .use(require('rehype-remove-comments'))
  .use(require('rehype-remove-duplicate-attribute-values'))
  .use(require('rehype-remove-empty-attribute'))
  .use(require('rehype-remove-external-script-content'))
  .use(require('rehype-remove-meta-http-equiv'))
  .use(require('rehype-remove-script-type-javascript'))
  .use(require('rehype-remove-style-type-css'))
  .use(require('rehype-sort-attribute-values'))
  .use(require('rehype-sort-attributes'))

…does not. According to the documentation, the two are supposed to be equivalent? 🤔

wooorm commented 6 years ago

which breaks a number of dependencies I'm using

How?

How stuff is compiled to a string is handled by rehype-stringify. The config is set here.

You can overwrite configuration like so:

const processor = rehype()
  .use(require('rehype-preset-minify'))
  .use('settings', {preferUnquoted: false})
jcayzac commented 6 years ago

How?

In my case, an Hexo plugin I rely on uses a regex that expects the quotes (the inline-assets-filter plugin).

Thanks for the explanation about stringify! 👍🏼

jcayzac commented 6 years ago

By the way, this is invalid:

const processor = rehype()
  .use(require('rehype-preset-minify'))
  .use('settings', {preferUnquoted: false}) // Error: Expected usable value, not `settings`

The proper way would be:

const minify = require('rehype-preset-minify')
minify.settings = {preferUnquoted: false}
const processor = rehype().use(minify)
wooorm commented 6 years ago

Sorry, it should’ve been:

  .use({settings: {preferUnquoted: false}})
  // or:
  .data('settings', {preferUnquoted: false})