Comments (8)
I think I have managed to solve it by using a different library:
var gulp = require('gulp'),
minifyHtml = require('gulp-htmlmin');
gulp.task('optimise.html', function () {
'use strict';
return gulp.src('src/**/*.html')
.pipe(minifyHtml({
collapseWhitespace: true,
ignoreCustomFragments: [ (/\{\%[^\%]*?\%\}/g) ]
}))
.pipe(gulp.dest('www'));
});
from minimize.
Where in the html do those template directives lives? E.g. inside an element as text or inside a parameter?
from minimize.
with django you can use them wherever you want, I was using them as an attribute:
{% if bg %}style="background-image: url('{{ bg }}')"{% endif %}
from minimize.
Hmm yeah, I suspect surrounding html/code is probably causing the change. If I run the CLI script directly with the above supplied snippet it seems to work fine ./bin/minimize "{% if bg %}style=\"background-image: url('{{ bg }}')\"{% endif %}"
. Note that minimize only supports parsing of HTML though, e.g. excluding template directives. You'll have to inspect what the parsed element looks like of htmlparser2 to get a solid understanding of what is going wrong.
from minimize.
It seems to work with:
./bin/minimize "{% if bg %}style=\"background-image: url('{{ bg }}')\"{% endif %}"
// outputs
{% if bg %}style="background-image: url('{{ bg }}')"{% endif %}
but not with:
./bin/minimize "<a {% if bg %}style=\"background-image: url('{{ bg }}')\"{% endif %}> hey </a>"
// outputs
<a {% if bg %} style="background-image: url('{{ bg }}')" endif>hey</a>
from minimize.
Hmm yeah, little I can do about that. Htmlparser2 probably detects the {% if bg %} as part of the param, as a param can start with 'any' character. But always closes with
"or space, and detects that before the closing
{% endif %}`. Anyways, minimize is not designed to work with templates, it parser html. The only way to accommodate for this is by providing a custom parser which understands handlebar templates.
from minimize.
Ya I can't see an option in htmlparser2 to support custom templating language. I guess what I would need is an option to switch htmlparser2 out for another parser such as swig:
http://paularmstrong.github.io/swig/
But by then it might be better to just use another minification library altogether! It's a shame because I use minimize for the static html, would be useful to use it for the dynamic templates too!
from minimize.
htmlparser2 perfectly supports a custom parser and so does minimize, however it requires development. Another option would be to do minification after the template was processed, e.g. only HTML remains
from minimize.
Related Issues (20)
- An in-range update of cli-color is breaking the build 🚨 HOT 1
- An in-range update of uuid is breaking the build 🚨 HOT 1
- HTML Attribute Contenteditable Removed By Minimize
- HTML minification eats up spaces between inline elements HOT 3
- Maximum call stack size exceeded HOT 1
- Empty attributes are assigned blank values HOT 4
- This is beyond the scope of this project. NO, IT'S NOT HOT 3
- html tags are autoclosed within a single html file HOT 2
- Keep case HOT 1
- Empty space in attribute HOT 1
- Stripping off extra HTML tags HOT 4
- Minify inline JS - Package link broken? HOT 7
- minifying all HTML files recursively in folder HOT 1
- SSI only supports #includes
- Attribut draggable is no redundant attribute HOT 1
- Feat: remove development code
- Track elements are not considered void elements
- Version 10 of node.js has been released
- An in-range update of htmlparser2 is breaking the build 🚨 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minimize.