Giter Club home page Giter Club logo

Comments (5)

Swaagie avatar Swaagie commented on July 20, 2024

The underlying issue here is that the way minimize outputs the processed HTML again. Hopefully htmlparser2 shows if an element is self closing, otherwise this is a hard fix

Not closing a tag based on the premise of an element not being regular HTML is not possible as that would create ambiguous output.

from minimize.

Swaagie avatar Swaagie commented on July 20, 2024

Just checked it, there is no flag on the parsed elements that indicates whether an element is inline or not. You could try to open an issue at https://github.com/fb55/htmlparser2, but frankly I think this is beyond the scope of both projects. As the aim is to parse/minify HTML and not custom elements implemented by a higher level module/library.

A possible solution would be to create a custom angular parser that is derived from the https://github.com/fb55/domhandler, as that is what htmlparser2 (and thus minimize) use by default. It wouldn't mind to build in optional support for custom handlers and special flags. I do not however have the time to write a custom angular parser (haven't checked if that exists already) myself, so community input would be welcome here.

from minimize.

jlas avatar jlas commented on July 20, 2024

This is not only an issue for custom tags, but some official HTML tags are also "self closing" (see https://developer.mozilla.org/en-US/docs/Glossary/empty_element)

from minimize.

Swaagie avatar Swaagie commented on July 20, 2024

@jlas as far as I'm aware these are correctly parsed and outputted (code reference), this issue was specifically about custom elements that are not part of the inline list. However, if you have encountered a specific problem I'd like to known.

Also since this issue got revisited, this could potential be solved with a custom plugin, since minimize supports plugins now.

from minimize.

jlas avatar jlas commented on July 20, 2024

@Swaagie here is an example I was having trouble with:

var M = require('minimize');
var snippet = ('<button><input type="hidden"/></button>');
m = new M();
m.parse(snippet, function (err, data) { console.log(data); });

This outputs:

<button></button><input type=hidden>

Now, as far as I know, <button> should allow <input> as a child element, according to MDN. But it seems like htmlparser2 is not allowing that (I think here)...

Anyway I created a PR (#43) which allows passing options to htmlparser2. In my case passing the xmlMode: true option gets my example above to work. Either way feel free to reject it as I have found another fix, which is to enclose the <input> in a <div> instead of <button>...

from minimize.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.