Coder Social home page Coder Social logo

anseki / htmlclean Goto Github PK

View Code? Open in Web Editor NEW
61.0 5.0 12.0 212 KB

Simple and safety HTML/SVG cleaner to minify without changing its structure.

License: MIT License

JavaScript 100.00%
html svg clean whitespace linebreak comment minify compress lightweight svg-source

htmlclean's People

Contributors

anseki avatar hemanth avatar sugarshin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

htmlclean's Issues

'Module not found' error when using in angular app

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
...

Dangerous tampering of attribute value when it contains `>` sign

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

New lines are not removed {\n}

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.

Improving documentation

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.

Recreate directory tree

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?

IE conditional directives from html5 boilerplate cause invalid output

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"..

Remove commented out code?

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?

Add in a param to leave SVGs alone, as compression breaks already optimised SVGs

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>

extra space inserted after <div> followed by new line

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>.

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.