anseki / htmlclean Goto Github PK
View Code? Open in Web Editor NEWSimple and safety HTML/SVG cleaner to minify without changing its structure.
License: MIT License
Simple and safety HTML/SVG cleaner to minify without changing its structure.
License: MIT License
Hi, when I want to use htmlclean in new angular app
import * as htmlclean from 'htmlclean';
And then htmlclean(someCode)
it gives me error:
ERROR in ./node_modules/htmlclean/lib/htmlclean.js
Module not found: Error: Can't resolve './pathdata' in '...\node_modules\htmlclean\lib'
@ ./node_modules/htmlclean/lib/htmlclean.js 23:13-34
...
ERROR in ./node_modules/htmlclean/lib/htmlclean.js
Module not found: Error: Can't resolve './phrasing-elements' in '...\node_modules\htmlclean\lib'
@ ./node_modules/htmlclean/lib/htmlclean.js 21:24-54
...
Hi,
htmlclean tampers attribute values when it contains >
sign. It's probably considering that >
is closing the tag declaration when it's not. It's quite dangerous.
Here is a reproductible example.
Input:
$ cat test.html
<tag attr="var > 1">
Output:
$ cat test.min.html
<tag attr="var> 1">%
^ Notice the space was dropped here
SVG 1.1 SE or SVG 2 have text
, tspan
, altGlyph
, etc.
It states in one of your comments that this removes new lines ... but that seems not to be the case. After running it either before or after minification (precompiled handlebars templates in this case) there still seem to '\n' characters in there.
Can you confirm that it is the case or invalidate it, please?
Thanks.
Hello,
Maybe it is worth mentioning, I thought I had a bug.
I am using grunt-htmlclean 2.7.11 (which uses htmlclean 3.0.2) and had the following:
Input:
<div class="aaa"><div>The <div class="bbb"><span class="xxx">Blabla</span></div></div>
Output:
<div class="aaa"><div>The<div class="bbb"><span class="xxx">Blabla</span></div></div>
I thought it was a bug and believed the whitespace after The
should have been be preserved. But then I guessed the div tag
did not behave like the span tag which were the case, so after replacing my inline-block div by space, it worked.
Adding a not about this in the README could be great.
Hi,
This following command htmlclean src -o public
only considers src/*.html files:
Would it possible to take care of src/**/*.html
and recreate directory tree?
In header.
I'm a Grunt user. I find also 2 plugins for HTML minify:
Why I need use grunt-htmlclean, not these plugins? Any advantages, arguments, tests?
grunt-minify-html description:
This differs from grunt-contrib-htmlmin in that it uses a proper HTML-parser instead of a bunch of fragile regexes.
Thanks.
This is all fine with htmlclean 2.0.0 and broke in htmlclean 2.0.1. Typical html5 boilerplate looks like this
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>title</title>
<!-- TODO: remove when published -->
<meta name="robots" content="noindex,nofollow">
</head>
<body>
</body>
</html>
htmlclean 2.0.1 removes meta charset, title and other things up-to the <meta name="robots"..
Hi, I assumed that running htmlclean would remove the following <!-- <button class="mute">MUTE</button> -->
but it doesn’t. Is there any way to make it remove commented out code?
I have noticed recently when compressing my templates with optimised inline SVGs within them it will edit them and break the SVG icon.
Instead of me wrapping every inline SVG instance in <!--[htmlclean-protect]-->
would it be possible to add in a param to leave SVG optimisations out?
As an example I have an arrow SVG
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 31.494 31.494">
<path d="M10.273 5.009a1.112 1.112 0 011.587 0 1.12 1.12 0 010 1.571l-8.047 8.047h26.554c.619 0 1.127.492 1.127 1.111s-.508 1.127-1.127 1.127H3.813l8.047 8.032c.429.444.429 1.159 0 1.587a1.112 1.112 0 01-1.587 0L.321 16.532a1.12 1.12 0 010-1.571l9.952-9.952z"/>
</svg>
It would output this as
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 31.494 31.494">
<path d="M10.273 5.009a1.112 1.112 0 11.587 0 1.12 1.12 0 10 1.571l-8.047 8.047h26.554c.619 0 1.127.492 1.127 1.111s-.508 1.127-1.127 1.127H3.813l8.047 8.032c.429.444.429 1.159 0 1.587a1.112 1.112 0 1-1.587 0L.321 16.532a1.12 1.12 0 10-1.571l9.952-9.952z"></path>
</svg>
Running htmlclean 2.7.7 on:
<div><a></a>x<span></span></div>
results in:
<div><a></a>x<span></span></div>
but running it on:
<div>
<a></a>x<span></span></div>
results in:
<div><a></a> x<span></span></div>
It looks like the "CR+LF" after <div>
is translated into a space after </a>
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.