Socket
Socket
Sign inDemoInstall

html-loader

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-loader - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

33

index.js

@@ -17,3 +17,17 @@ /*

this.cacheable && this.cacheable();
var links = attrParse(content);
var query = loaderUtils.parseQuery(this.query);
var attributes = ["img:src"];
if(query.attrs !== undefined) {
if(typeof query.attrs === "string")
attributes = query.attrs.split(" ");
else if(Array.isArray(query.attrs))
attributes = query.attrs;
else if(query.attrs === false)
attributes = [];
else
throw new Error("Invalid value to query parameter attrs");
}
var links = attrParse(content, function(tag, attr) {
return attributes.indexOf(tag + ":" + attr) >= 0;
});
links.reverse();

@@ -23,3 +37,3 @@ var data = {};

links.forEach(function(link) {
if(/^data:|^(https?:)?\/\//.test(link.value)) return;
if(/^data:|^(https?:)?\/\/|^[\{\}\[\]#*;,'§\$%&\(=?`´\^°<>]/.test(link.value)) return;
do {

@@ -35,3 +49,16 @@ var ident = randomIdent();

content.reverse();
return "module.exports = " + JSON.stringify(content.join("")).replace(/xxxHTMLLINKxxx[0-9\.]+xxx/g, function(match) {
content = content.join("");
if(this.minimize) {
content = htmlMinifier.minify(content, {
removeComment: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeOptionalTags: true
})
}
return "module.exports = " + JSON.stringify(content).replace(/xxxHTMLLINKxxx[0-9\.]+xxx/g, function(match) {
if(!data[match]) return match;

@@ -38,0 +65,0 @@ return '" + require(' + JSON.stringify(urlToRequire(data[match])) + ') + "';

25

lib/attributesParser.js

@@ -7,12 +7,2 @@ /*

var RELEVANT_TAG_ATTRS = [
"img src",
"link href",
"script src",
];
function isRelevantTagAttr(tag, attr) {
return RELEVANT_TAG_ATTRS.indexOf(tag + " " + attr) >= 0;
}
var parser = new Parser({

@@ -34,4 +24,4 @@ outside: {

"(([a-zA-Z\\-]+)\\s*=\\s*\")([^\"]*)\"": function(match, strUntilValue, name, value, index) {
if(!isRelevantTagAttr(this.currentTag, name)) return;
this.links.push({
if(!this.isRelevantTagAttr(this.currentTag, name)) return;
this.results.push({
start: index + strUntilValue.length,

@@ -43,4 +33,4 @@ length: value.length,

"(([a-zA-Z\\-]+)\\s*=\\s*)([^\\s>]+)": function(match, strUntilValue, name, value, index) {
if(!isRelevantTagAttr(this.currentTag, name)) return;
this.links.push({
if(!this.isRelevantTagAttr(this.currentTag, name)) return;
this.results.push({
start: index + strUntilValue.length,

@@ -57,7 +47,8 @@ length: value.length,

module.exports = function parse(html) {
module.exports = function parse(html, isRelevantTagAttr) {
return parser.parse("outside", html, {
currentTag: null,
links: []
}).links;
results: [],
isRelevantTagAttr: isRelevantTagAttr
}).results;
};
{
"name": "html-loader",
"version": "0.1.0",
"version": "0.2.0",
"author": "Tobias Koppers @sokra",

@@ -5,0 +5,0 @@ "description": "html loader module for webpack",

# html loader for webpack
Exports HTML as string. HTML is minimized when the compiler demands.
By default every local `<img src="image.png">` is required (`require("./image.png")`). You may need to specify loaders for images in your configuration (recommended `file-loader` or `url-loader`).
## Examples
With this configuration:
``` javascript
{
module: { loaders: [
{ test: "\.jpg$", loader: "file-loader" },
{ test: "\.png$", loader: "url-loader?mimetype=image/png" }
]},
output: {
publicPath: "http://cdn.example.com/[hash]/"
}
}
```
``` html
<!-- fileA.html -->
<img src="image.jpg" data-src2x="image2x.png" >
```
``` javascript
require("html!./fileA.html");
// => '<img src="http://cdn.example.com/49e...ba9f/a9f...92ca.jpg" data-src2x="image2x.png" >'
require("html?attrs=img:data-src2c!./file.html");
// => '<img src="image.png" data-src2x="data:image/png;base64,..." >'
require("html?attrs=img:src img:data-src2c!./file.html");
require("html?attrs[]=img:src&attrs[]=img:data-src2c!./file.html");
// => '<img src="http://cdn.example.com/49e...ba9f/a9f...92ca.jpg" data-src2x="data:image/png;base64,..." >'
/// minimized
// => '<img src=http://cdn.example.com/49e...ba9f/a9f...92ca.jpg data-src2x=data:image/png;base64,...>'
```
## License
MIT (http://www.opensource.org/licenses/mit-license.php)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc