terser / html-minifier-terser

actively maintained fork of html-minifier - minify HTML, CSS and JS code using terser - supports ES6 code
https://terser.org/html-minifier-terser
MIT License
376 stars 30 forks source link

using `maxLineLength` can introduce newlines that might create bugs in links underline #84

Closed lucamattiazzi closed 2 years ago

lucamattiazzi commented 3 years ago

when using maxLineLength the newline added after an a tag, if added right before the closing tag, will generate a link where the underline is longer than the text itself.

e.g.

const express = require('express')
const { minify } = require('html-minifier-terser') 
const app = express()

const html = `
  Ehi! This is an example for github! <a href="https://website.com">https://website.com/home</a> ain't this nice?
`

app.get('/', (req, res) => {
  res.send(html)
})

app.get('/mini', (req, res) => {
  minify(html, {
      maxLineLength: 10,
    }).then(m => {
      res.send(m)
    })
})

app.listen(5000)

http://localhost:5000

image

http://localhost:5000/mini

image

EDIT:

The same thing happens when the element has similar text-decorations like underline. I propose to avoid adding newlines before any closing tag.