Socket
Socket
Sign inDemoInstall

html-loader

Package Overview
Dependencies
Maintainers
3
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 4.2.0 to 5.0.0

1

dist/cjs.js
"use strict";
const loader = require("./index");
module.exports = loader.default;
module.exports.raw = loader.raw;
module.exports.defaultMinimizerOptions = loader.defaultMinimizerOptions;

16

dist/HtmlSourceError.js

@@ -7,7 +7,5 @@ "use strict";

exports.default = void 0;
function getIndices(value) {
const result = [];
let index = value.indexOf("\n");
while (index !== -1) {

@@ -17,7 +15,5 @@ result.push(index + 1);

}
result.push(value.length + 1);
return result;
}
function offsetToPosition(source, offset) {

@@ -29,8 +25,7 @@ let index = -1;

} = indices;
if (offset < 0) {
return {};
} // eslint-disable-next-line no-plusplus
}
// eslint-disable-next-line no-plusplus
while (++index < length) {

@@ -45,6 +40,4 @@ if (indices[index] > offset) {

}
return {};
}
class HtmlSourceError extends Error {

@@ -60,9 +53,8 @@ constructor(error, startOffset, endOffset, source) {

const endPosition = offsetToPosition(source, this.endOffset);
this.message += ` (From line ${startPosition.line}, column ${startPosition.column}; to line ${endPosition.line}, column ${endPosition.column})`; // We don't need stack
this.message += ` (From line ${startPosition.line}, column ${startPosition.column}; to line ${endPosition.line}, column ${endPosition.column})`;
// We don't need stack
this.stack = false;
}
}
exports.default = HtmlSourceError;

@@ -13,15 +13,9 @@ "use strict";

});
var _plugins = require("./plugins");
var _utils = require("./utils");
var _options = _interopRequireDefault(require("./options.json"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
async function loader(content) {
const rawOptions = this.getOptions(_options.default);
const options = (0, _utils.normalizeOptions)(rawOptions, this);
if (options.preprocessor) {

@@ -31,3 +25,2 @@ // eslint-disable-next-line no-param-reassign

}
const plugins = [];

@@ -37,3 +30,2 @@ const errors = [];

const replacements = [];
if (options.sources) {

@@ -49,3 +41,2 @@ plugins.push((0, _plugins.sourcesPlugin)({

}
if (options.minimize) {

@@ -57,11 +48,8 @@ plugins.push((0, _plugins.minimizerPlugin)({

}
const {
html
} = await (0, _utils.pluginRunner)(plugins).process(content);
for (const error of errors) {
this.emitError(error instanceof Error ? error : new Error(error));
}
const importCode = (0, _utils.getImportCode)(html, this, imports, options);

@@ -68,0 +56,0 @@ const moduleCode = (0, _utils.getModuleCode)(html, replacements, options);

@@ -18,7 +18,4 @@ "use strict";

});
var _sourcesPlugin = _interopRequireDefault(require("./sources-plugin"));
var _minimizerPlugin = _interopRequireDefault(require("./minimizer-plugin"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -7,5 +7,3 @@ "use strict";

exports.default = void 0;
var _htmlMinifierTerser = require("html-minifier-terser");
var _default = options => async function process(html) {

@@ -18,6 +16,4 @@ try {

}
return html;
};
exports.default = _default;

@@ -7,7 +7,4 @@ "use strict";

exports.default = void 0;
var _parse = require("parse5");
var _utils = require("../utils");
var _default = options => function process(html) {

@@ -26,17 +23,12 @@ const sources = [];

} = node;
if (node.nodeName === "#comment") {
const match = node.data.match(_utils.webpackIgnoreCommentRegexp);
if (match) {
needIgnore = match[2] === "true";
}
return;
}
if (!tagName) {
return;
}
if (needIgnore) {

@@ -46,3 +38,2 @@ needIgnore = false;

}
attributes.forEach(attribute => {

@@ -54,17 +45,12 @@ let {

const handlers = new Map([...(options.sources.list.get("*") || new Map()), ...(options.sources.list.get(tagName.toLowerCase()) || new Map())]);
if (handlers.size === 0) {
return;
}
const handler = handlers.get(name.toLowerCase());
if (!handler) {
return;
}
if (handler.filter && !handler.filter(tagName, name, attributes, options.resourcePath)) {
return;
}
const attributeAndValue = html.slice(sourceCodeLocation.attrs[name].startOffset, sourceCodeLocation.attrs[name].endOffset);

@@ -83,3 +69,4 @@ const isValueQuoted = attributeAndValue[attributeAndValue.length - 1] === '"' || attributeAndValue[attributeAndValue.length - 1] === "'";

endOffset: sourceCodeLocation.endTag.endOffset
} : // eslint-disable-next-line no-undefined
} :
// eslint-disable-next-line no-undefined
undefined,

@@ -99,3 +86,2 @@ attributes,

let result;
try {

@@ -106,5 +92,3 @@ result = handler.type(optionsForTypeFn);

}
result = Array.isArray(result) ? result : [result];
for (const source of result) {

@@ -115,4 +99,4 @@ if (!source) {

}
sources.push({ ...source,
sources.push({
...source,
name,

@@ -128,3 +112,2 @@ isValueQuoted

let offset = 0;
for (const source of sources) {

@@ -141,3 +124,2 @@ const {

let request = value;
if (!urlFilter(name, value, options.resourcePath)) {

@@ -147,6 +129,4 @@ // eslint-disable-next-line no-continue

}
let hash;
const indexHash = request.lastIndexOf("#");
if (indexHash >= 0) {

@@ -156,6 +136,4 @@ hash = request.substring(indexHash);

}
request = (0, _utils.requestify)(options.context, request);
let importName = imports.get(request);
if (!importName) {

@@ -170,3 +148,2 @@ importName = `___HTML_LOADER_IMPORT_${imports.size}___`;

}
const replacementKey = JSON.stringify({

@@ -178,3 +155,2 @@ request,

let replacementName = replacements.get(replacementKey);
if (!replacementName) {

@@ -190,12 +166,10 @@ replacementName = `___HTML_LOADER_REPLACEMENT_${replacements.size}___`;

});
} // eslint-disable-next-line no-param-reassign
}
// eslint-disable-next-line no-param-reassign
html = html.slice(0, startOffset + offset) + replacementName + html.slice(endOffset + offset);
offset += startOffset + replacementName.length - endOffset;
}
return html;
};
exports.default = _default;

@@ -8,10 +8,8 @@ "use strict";

}
if (!url) {
return url;
} // eslint-disable-next-line no-underscore-dangle, no-param-reassign
}
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
url = String(url.__esModule ? url.default : url);
if (options.hash) {

@@ -21,8 +19,6 @@ // eslint-disable-next-line no-param-reassign

}
if (options.maybeNeedQuotes && /[\t\n\f\r "'=<>`]/.test(url)) {
return "\"".concat(url, "\"");
}
return url;
};

@@ -22,28 +22,31 @@ "use strict";

exports.webpackIgnoreCommentRegexp = void 0;
var _path = _interopRequireDefault(require("path"));
var _HtmlSourceError = _interopRequireDefault(require("./HtmlSourceError"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function isASCIIWhitespace(character) {
return (// Horizontal tab
character === "\u0009" || // New line
character === "\u000A" || // Form feed
character === "\u000C" || // Carriage return
character === "\u000D" || // Space
return (
// Horizontal tab
character === "\u0009" ||
// New line
character === "\u000A" ||
// Form feed
character === "\u000C" ||
// Carriage return
character === "\u000D" ||
// Space
character === "\u0020"
);
} // (Don't use \s, to avoid matching non-breaking space)
}
// (Don't use \s, to avoid matching non-breaking space)
// eslint-disable-next-line no-control-regex
const regexLeadingSpaces = /^[ \t\n\r\u000c]+/; // eslint-disable-next-line no-control-regex
const regexLeadingCommasOrSpaces = /^[, \t\n\r\u000c]+/; // eslint-disable-next-line no-control-regex
const regexLeadingSpaces = /^[ \t\n\r\u000c]+/;
// eslint-disable-next-line no-control-regex
const regexLeadingCommasOrSpaces = /^[, \t\n\r\u000c]+/;
// eslint-disable-next-line no-control-regex
const regexLeadingNotSpaces = /^[^ \t\n\r\u000c]+/;
const regexTrailingCommas = /[,]+$/;
const regexNonNegativeInteger = /^\d+$/; // ( Positive or negative or unsigned integers or decimals, without or without exponents.
const regexNonNegativeInteger = /^\d+$/;
// ( Positive or negative or unsigned integers or decimals, without or without exponents.
// Must include at least one digit.

@@ -53,5 +56,3 @@ // According to spec tests any decimal point must be followed by a digit.

// https://html.spec.whatwg.org/multipage/infrastructure.html#valid-floating-point-number
const regexFloatingPoint = /^-?(?:[0-9]+|[0-9]*\.[0-9]+)(?:[eE][+-]?[0-9]+)?$/;
function parseSrcset(input) {

@@ -64,12 +65,13 @@ // 1. Let input be the value passed to this algorithm.

let state;
let c; // 2. Let position be a pointer into input, initially pointing at the start
let c;
// 2. Let position be a pointer into input, initially pointing at the start
// of the string.
let position = 0;
let startOffset; // eslint-disable-next-line consistent-return
let startOffset;
// eslint-disable-next-line consistent-return
function collectCharacters(regEx) {
let chars;
const match = regEx.exec(input.substring(position));
if (match) {

@@ -80,41 +82,49 @@ [chars] = match;

}
} // 3. Let candidates be an initially empty source set.
}
// 3. Let candidates be an initially empty source set.
const candidates = [];
const candidates = []; // 4. Splitting loop: Collect a sequence of characters that are space
// 4. Splitting loop: Collect a sequence of characters that are space
// characters or U+002C COMMA characters. If any U+002C COMMA characters
// were collected, that is a parse error.
// eslint-disable-next-line no-constant-condition
while (true) {
collectCharacters(regexLeadingCommasOrSpaces); // 5. If position is past the end of input, return candidates and abort these steps.
collectCharacters(regexLeadingCommasOrSpaces);
// 5. If position is past the end of input, return candidates and abort these steps.
if (position >= inputLength) {
if (candidates.length === 0) {
throw new Error("Must contain one or more image candidate strings");
} // (we're done, this is the sole return path)
}
// (we're done, this is the sole return path)
return candidates;
}
return candidates;
} // 6. Collect a sequence of characters that are not space characters,
// 6. Collect a sequence of characters that are not space characters,
// and let that be url.
startOffset = position;
url = collectCharacters(regexLeadingNotSpaces);
// 7. Let descriptors be a new empty list.
descriptors = [];
startOffset = position;
url = collectCharacters(regexLeadingNotSpaces); // 7. Let descriptors be a new empty list.
descriptors = []; // 8. If url ends with a U+002C COMMA character (,), follow these substeps:
// 8. If url ends with a U+002C COMMA character (,), follow these sub steps:
// (1). Remove all trailing U+002C COMMA characters from url. If this removed
// more than one character, that is a parse error.
if (url.slice(-1) === ",") {
url = url.replace(regexTrailingCommas, ""); // (Jump ahead to step 9 to skip tokenization and just push the candidate).
url = url.replace(regexTrailingCommas, "");
// (Jump ahead to step 9 to skip tokenization and just push the candidate).
parseDescriptors();
} // Otherwise, follow these substeps:
}
// Otherwise, follow these sub steps:
else {
tokenize();
} // 16. Return to the step labeled splitting loop.
}
// 16. Return to the step labeled splitting loop.
}
/**

@@ -124,21 +134,25 @@ * Tokenizes descriptor properties prior to parsing

*/
function tokenize() {
// 8.1. Descriptor tokenizer: Skip whitespace
collectCharacters(regexLeadingSpaces); // 8.2. Let current descriptor be the empty string.
collectCharacters(regexLeadingSpaces);
currentDescriptor = ""; // 8.3. Let state be in descriptor.
// 8.2. Let current descriptor be the empty string.
currentDescriptor = "";
state = "in descriptor"; // eslint-disable-next-line no-constant-condition
// 8.3. Let state be in descriptor.
state = "in descriptor";
// eslint-disable-next-line no-constant-condition
while (true) {
// 8.4. Let c be the character at position.
c = input.charAt(position); // Do the following depending on the value of state.
c = input.charAt(position);
// Do the following depending on the value of state.
// For the purpose of this step, "EOF" is a special character representing
// that position is past the end of input.
// In descriptor
if (state === "in descriptor") {
// Do the following, depending on the value of c:
// Space character

@@ -154,3 +168,4 @@ // If current descriptor is not empty, append current descriptor to

}
} // U+002C COMMA (,)
}
// U+002C COMMA (,)
// Advance position to the next character in input. If current descriptor

@@ -161,10 +176,9 @@ // is not empty, append current descriptor to descriptors. Jump to the step

position += 1;
if (currentDescriptor) {
descriptors.push(currentDescriptor);
}
parseDescriptors();
return;
} // U+0028 LEFT PARENTHESIS (()
}
// U+0028 LEFT PARENTHESIS (()
// Append c to current descriptor. Set state to in parens.

@@ -174,3 +188,4 @@ else if (c === "\u0028") {

state = "in parens";
} // EOF
}
// EOF
// If current descriptor is not empty, append current descriptor to

@@ -182,5 +197,6 @@ // descriptors. Jump to the step labeled descriptor parser.

}
parseDescriptors();
return;
parseDescriptors();
return; // Anything else
// Anything else
// Append c to current descriptor.

@@ -190,3 +206,4 @@ } else {

}
} // In parens
}
// In parens
else if (state === "in parens") {

@@ -198,3 +215,4 @@ // U+0029 RIGHT PARENTHESIS ())

state = "in descriptor";
} // EOF
}
// EOF
// Append current descriptor to descriptors. Jump to the step labeled

@@ -206,3 +224,4 @@ // descriptor parser.

return;
} // Anything else
}
// Anything else
// Append c to current descriptor.

@@ -212,11 +231,15 @@ else {

}
} // After descriptor
}
// After descriptor
else if (state === "after descriptor") {
// Do the following, depending on the value of c:
if (isASCIIWhitespace(c)) {// Space character: Stay in this state.
} // EOF: Jump to the step labeled descriptor parser.
if (isASCIIWhitespace(c)) {
// Space character: Stay in this state.
}
// EOF: Jump to the step labeled descriptor parser.
else if (c === "") {
parseDescriptors();
return;
} // Anything else
}
// Anything else
// Set state to in descriptor. Set position to the previous character in input.

@@ -227,8 +250,9 @@ else {

}
} // Advance position to the next character in input.
}
// Advance position to the next character in input.
position += 1;
}
}
/**

@@ -239,10 +263,9 @@ * Adds descriptor properties to a candidate, pushes to the candidates array

// Declared outside of the while loop so that it's only created once.
function parseDescriptors() {
// 9. Descriptor parser: Let error be no.
let pError = false; // 10. Let width be absent.
let pError = false;
// 10. Let width be absent.
// 11. Let density be absent.
// 12. Let future-compat-h be absent. (We're implementing it now as h)
let w;

@@ -257,5 +280,6 @@ let d;

let intVal;
let floatVal; // 13. For each descriptor in descriptors, run the appropriate set of steps
let floatVal;
// 13. For each descriptor in descriptors, run the appropriate set of steps
// from the following list:
for (i = 0; i < descriptors.length; i++) {

@@ -266,5 +290,6 @@ desc = descriptors[i];

intVal = parseInt(value, 10);
floatVal = parseFloat(value); // If the descriptor consists of a valid non-negative integer followed by
floatVal = parseFloat(value);
// If the descriptor consists of a valid non-negative integer followed by
// a U+0077 LATIN SMALL LETTER W character
if (regexNonNegativeInteger.test(value) && lastChar === "w") {

@@ -274,7 +299,7 @@ // If width and density are not both absent, then let error be yes.

pError = true;
} // Apply the rules for parsing non-negative integers to the descriptor.
}
// Apply the rules for parsing non-negative integers to the descriptor.
// If the result is zero, let error be yes.
// Otherwise, let width be the result.
if (intVal === 0) {

@@ -285,3 +310,4 @@ pError = true;

}
} // If the descriptor consists of a valid floating-point number followed by
}
// If the descriptor consists of a valid floating-point number followed by
// a U+0078 LATIN SMALL LETTER X character

@@ -293,7 +319,7 @@ else if (regexFloatingPoint.test(value) && lastChar === "x") {

pError = true;
} // Apply the rules for parsing floating-point number values to the descriptor.
}
// Apply the rules for parsing floating-point number values to the descriptor.
// If the result is less than zero, let error be yes. Otherwise, let density
// be the result.
if (floatVal < 0) {

@@ -304,3 +330,4 @@ pError = true;

}
} // If the descriptor consists of a valid non-negative integer followed by
}
// If the descriptor consists of a valid non-negative integer followed by
// a U+0068 LATIN SMALL LETTER H character

@@ -311,7 +338,7 @@ else if (regexNonNegativeInteger.test(value) && lastChar === "h") {

pError = true;
} // Apply the rules for parsing non-negative integers to the descriptor.
}
// Apply the rules for parsing non-negative integers to the descriptor.
// If the result is zero, let error be yes. Otherwise, let future-compat-h
// be the result.
if (intVal === 0) {

@@ -321,12 +348,13 @@ pError = true;

h = intVal;
} // Anything else, Let error be yes.
}
// Anything else, Let error be yes.
} else {
pError = true;
}
} // 15. If error is still no, then append a new image source to candidates whose
}
// 15. If error is still no, then append a new image source to candidates whose
// URL is url, associated with a width width if not absent and a pixel
// density density if not absent. Otherwise, there is a parse error.
if (!pError) {

@@ -337,3 +365,2 @@ candidate.source = {

};
if (w) {

@@ -344,3 +371,2 @@ candidate.width = {

}
if (d) {

@@ -351,3 +377,2 @@ candidate.density = {

}
if (h) {

@@ -358,3 +383,2 @@ candidate.height = {

}
candidates.push(candidate);

@@ -366,3 +390,2 @@ } else {

}
function parseSrc(input) {

@@ -372,27 +395,23 @@ if (!input) {

}
let startOffset = 0;
let start = 0;
for (; start < input.length && isASCIIWhitespace(input[start]); start++);
if (start === input.length) {
throw new Error("Must be non-empty");
}
let end = input.length - 1;
for (; end > -1 && isASCIIWhitespace(input[end]); end--);
end += 1;
let value = input;
while (isASCIIWhitespace(value.substring(0, 1))) {
startOffset += 1;
value = value.substring(1, value.length);
if (start !== 0 || end !== value.length) {
value = value.substring(start, end);
if (!value) {
throw new Error("Must be non-empty");
}
}
while (isASCIIWhitespace(value.substring(value.length - 1, value.length))) {
value = value.substring(0, value.length - 1);
}
if (!value) {
throw new Error("Must be non-empty");
}
return {
value,
startOffset
startOffset: start
};
}
const WINDOWS_ABS_PATH_REGEXP = /^[a-zA-Z]:[\\/]|^\\\\/;
function isUrlRequestable(url) {

@@ -402,25 +421,22 @@ // Protocol-relative URLs

return false;
} // `file:` protocol
}
// `file:` protocol
if (/^file:/i.test(url)) {
return true;
} // Absolute URLs
}
// Absolute URLs
if (/^[a-z][a-z0-9+.-]*:/i.test(url) && !WINDOWS_ABS_PATH_REGEXP.test(url)) {
return false;
} // It's some kind of url for a template
}
// It's some kind of url for a template
if (/^[{}[\]#*;,'§$%&(=?`´^°<>]/.test(url)) {
return false;
}
return true;
}
const WINDOWS_PATH_SEPARATOR_REGEXP = /\\/g;
const RELATIVE_PATH_REGEXP = /^\.\.?[/\\]/;
const absoluteToRequest = (context, maybeAbsolutePath) => {

@@ -433,14 +449,10 @@ if (maybeAbsolutePath[0] === "/") {

}
const querySplitPos = maybeAbsolutePath.indexOf("?");
let resource = querySplitPos === -1 ? maybeAbsolutePath : maybeAbsolutePath.slice(0, querySplitPos);
resource = _path.default.posix.relative(context, resource);
if (!resource.startsWith("../")) {
resource = `./${resource}`;
}
return querySplitPos === -1 ? resource : resource + maybeAbsolutePath.slice(querySplitPos);
}
if (WINDOWS_ABS_PATH_REGEXP.test(maybeAbsolutePath)) {

@@ -450,6 +462,4 @@ const querySplitPos = maybeAbsolutePath.indexOf("?");

resource = _path.default.win32.relative(context, resource);
if (!WINDOWS_ABS_PATH_REGEXP.test(resource)) {
resource = resource.replace(WINDOWS_PATH_SEPARATOR_REGEXP, "/");
if (!resource.startsWith("../")) {

@@ -459,44 +469,35 @@ resource = `./${resource}`;

}
return querySplitPos === -1 ? resource : resource + maybeAbsolutePath.slice(querySplitPos);
}
if (!RELATIVE_PATH_REGEXP.test(maybeAbsolutePath)) {
return `./${maybeAbsolutePath.replace(WINDOWS_PATH_SEPARATOR_REGEXP, "/")}`;
} // not an absolute path
}
// not an absolute path
return maybeAbsolutePath;
};
const contextify = (context, request) => request.split("!").map(r => absoluteToRequest(context, r)).join("!");
const MODULE_REQUEST_REGEXP = /^[^?]*~/;
function requestify(context, request) {
const isWindowsAbsolutePath = WINDOWS_ABS_PATH_REGEXP.test(request);
const newRequest = isWindowsAbsolutePath ? decodeURI(request).replace(/[\t\n\r]/g, "") : decodeURI(request).replace(/[\t\n\r]/g, "").replace(/\\/g, "/");
if (isWindowsAbsolutePath || newRequest[0] === "/") {
return newRequest;
}
if (/^file:/i.test(newRequest)) {
return newRequest;
} // A `~` makes the url an module
}
// A `~` makes the url an module
if (MODULE_REQUEST_REGEXP.test(newRequest)) {
return newRequest.replace(MODULE_REQUEST_REGEXP, "");
} // every other url is threaded like a relative url
}
// every other url is threaded like a relative url
return contextify(context, newRequest);
}
function isProductionMode(loaderContext) {
return loaderContext.mode === "production" || !loaderContext.mode;
}
const defaultMinimizerOptions = {
const defaultMinimizerOptions = exports.defaultMinimizerOptions = {
caseSensitive: true,

@@ -516,7 +517,5 @@ // `collapseBooleanAttributes` is not always safe, since this can break CSS attribute selectors and not safe for XHTML

removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true // `useShortDoctype` is not safe for XHTML
removeStyleLinkTypeAttributes: true
// `useShortDoctype` is not safe for XHTML
};
exports.defaultMinimizerOptions = defaultMinimizerOptions;
function getMinimizeOption(rawOptions, loaderContext) {

@@ -526,10 +525,7 @@ if (typeof rawOptions.minimize === "undefined") {

}
if (typeof rawOptions.minimize === "boolean") {
return rawOptions.minimize === true ? defaultMinimizerOptions : false;
}
return rawOptions.minimize;
}
function getAttributeValue(attributes, name) {

@@ -539,66 +535,48 @@ const [result] = attributes.filter(i => i.name.toLowerCase() === name);

}
function scriptSrcFilter(tag, attribute, attributes) {
let type = getAttributeValue(attributes, "type");
if (!type) {
return true;
}
type = type.trim();
if (!type) {
return false;
}
if (type !== "module" && type !== "text/javascript" && type !== "application/javascript") {
return false;
}
return true;
}
function linkHrefFilter(tag, attribute, attributes) {
let rel = getAttributeValue(attributes, "rel");
if (!rel) {
return false;
}
rel = rel.trim();
if (!rel) {
return false;
}
rel = rel.toLowerCase();
const usedRels = rel.split(" ").filter(value => value);
const usedRels = rel.split(" ").filter(Boolean);
const allowedRels = ["stylesheet", "icon", "mask-icon", "apple-touch-icon", "apple-touch-icon-precomposed", "apple-touch-startup-image", "manifest", "prefetch", "preload"];
return allowedRels.filter(value => usedRels.includes(value)).length > 0;
return allowedRels.some(value => usedRels.includes(value));
}
const META = new Map([["name", new Set([// msapplication-TileImage
const META = new Map([["name", new Set([
// msapplication-TileImage
"msapplication-tileimage", "msapplication-square70x70logo", "msapplication-square150x150logo", "msapplication-wide310x150logo", "msapplication-square310x310logo", "msapplication-config", "msapplication-task", "twitter:image"])], ["property", new Set(["og:image", "og:image:url", "og:image:secure_url", "og:audio", "og:audio:secure_url", "og:video", "og:video:secure_url", "vk:image"])], ["itemprop", new Set(["image", "logo", "screenshot", "thumbnailurl", "contenturl", "downloadurl", "duringmedia", "embedurl", "installurl", "layoutimage"])]]);
function linkItempropFilter(tag, attribute, attributes) {
let name = getAttributeValue(attributes, "itemprop");
if (name) {
name = name.trim();
if (!name) {
return false;
}
name = name.toLowerCase();
return META.get("itemprop").has(name);
}
return false;
}
function linkUnionFilter(tag, attribute, attributes) {
return linkHrefFilter(tag, attribute, attributes) || linkItempropFilter(tag, attribute, attributes);
}
function metaContentFilter(tag, attribute, attributes) {

@@ -608,6 +586,4 @@ for (const item of META) {

let name = getAttributeValue(attributes, key);
if (name) {
name = name.trim();
if (!name) {

@@ -617,3 +593,2 @@ // eslint-disable-next-line no-continue

}
name = name.toLowerCase();

@@ -623,9 +598,6 @@ return allowedNames.has(name);

}
return false;
}
function srcType(options) {
let source;
try {

@@ -636,9 +608,10 @@ source = parseSrc(options.value);

}
source = c0ControlCodesExclude(source);
try {
source = c0ControlCodesExclude(source);
} catch (error) {
throw new _HtmlSourceError.default(`Bad value for attribute "${options.attribute}" on element "${options.tag}": ${error.message}`, options.attributeStartOffset, options.attributeEndOffset, options.html);
}
if (!isUrlRequestable(source.value)) {
return [];
}
const startOffset = options.valueStartOffset + source.startOffset;

@@ -652,6 +625,4 @@ const endOffset = startOffset + source.value.length;

}
function srcsetType(options) {
let sourceSet;
try {

@@ -662,3 +633,2 @@ sourceSet = parseSrcset(options.value);

}
const result = [];

@@ -669,8 +639,10 @@ sourceSet.forEach(sourceItem => {

} = sourceItem;
source = c0ControlCodesExclude(source);
try {
source = c0ControlCodesExclude(source);
} catch (error) {
throw new _HtmlSourceError.default(`Bad value for attribute "${options.attribute}" on element "${options.tag}": ${error.message}`, options.attributeStartOffset, options.attributeEndOffset, options.html);
}
if (!isUrlRequestable(source.value)) {
return false;
}
const startOffset = options.valueStartOffset + source.startOffset;

@@ -687,6 +659,4 @@ const endOffset = startOffset + source.value.length;

}
function metaContentType(options) {
const isMsapplicationTask = options.attributes.find(i => i.name.toLowerCase() === "name" && i.value.toLowerCase() === "msapplication-task");
if (isMsapplicationTask) {

@@ -697,6 +667,4 @@ let startOffset = options.valueStartOffset;

const parts = options.value.split(";");
for (const [index, part] of parts.entries()) {
const isLastIteration = index === parts.length - 1;
if (/^icon-uri/i.test(part.trim())) {

@@ -706,3 +674,2 @@ const [name, src] = part.split("=");

let source;
try {

@@ -713,4 +680,7 @@ source = parseSrc(src);

}
source = c0ControlCodesExclude(source);
try {
source = c0ControlCodesExclude(source);
} catch (error) {
throw new _HtmlSourceError.default(`Bad value for attribute "icon-uri" on element "${options.tag}": ${error.message}`, options.attributeStartOffset, options.attributeEndOffset, options.html);
}
({

@@ -722,12 +692,10 @@ value

break;
} // +1 because of ";"
}
// +1 because of ";"
startOffset += part.length + (isLastIteration ? 0 : 1);
}
if (!value) {
return [];
}
return [{

@@ -739,9 +707,10 @@ startOffset,

}
return srcType(options);
}
return srcType(options);
} // function webpackImportType(options) {
// function webpackImportType(options) {
// let source;
//
// try {
// source = parseSrc(options.value);
// source = trimASCIIWhitespace(options.value);
// } catch (error) {

@@ -756,3 +725,12 @@ // throw new HtmlSourceError(

//
// source = c0ControlCodesExclude(source);
// try {
// source = c0ControlCodesExclude(source);
// } catch (error) {
// throw new HtmlSourceError(
// `Bad value for attribute "${options.attribute}" on element "${options.tag}": ${error.message}`,
// options.attributeStartOffset,
// options.attributeEndOffset,
// options.html
// );
// }
//

@@ -781,3 +759,2 @@ // if (!isUrlRequestable(source.value)) {

const defaultSources = new Map([["audio", new Map([["src", {

@@ -807,3 +784,4 @@ type: srcType

filter: scriptSrcFilter
}], // Using href with <script> is described here: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/script
}],
// Using href with <script> is described here: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/script
["href", {

@@ -825,3 +803,4 @@ type: srcType,

type: srcType
}]])], // SVG
}]])],
// SVG
["image", new Map([["xlink:href", {

@@ -835,3 +814,4 @@ type: srcType

type: srcType
}]])] // [
}]])]
// [
// 'webpack-import',

@@ -848,3 +828,2 @@ // new Map([

]);
function normalizeSourcesList(sources) {

@@ -854,24 +833,17 @@ if (typeof sources === "undefined") {

}
const result = new Map();
for (const source of sources) {
if (source === "...") {
for (const [tag, attributes] of defaultSources.entries()) {
let newAttributes;
const existingAttributes = result.get(tag);
if (existingAttributes) {
newAttributes = new Map([...existingAttributes, ...attributes]);
attributes.forEach(([k, v]) => existingAttributes.set(k, v));
} else {
newAttributes = new Map(attributes);
result.set(tag, new Map(attributes));
}
}
result.set(tag, newAttributes);
} // eslint-disable-next-line no-continue
// eslint-disable-next-line no-continue
continue;
}
let {

@@ -883,9 +855,5 @@ tag = "*",

attribute = attribute.toLowerCase();
let typeFn;
if (!result.has(tag)) {
result.set(tag, new Map());
}
let typeFn; // eslint-disable-next-line default-case
// eslint-disable-next-line default-case
switch (source.type) {

@@ -895,3 +863,2 @@ case "src":

break;
case "srcset":

@@ -901,4 +868,8 @@ typeFn = srcsetType;

}
result.get(tag).set(attribute, {
let attrMap = result.get(tag);
if (!attrMap) {
attrMap = new Map();
result.set(tag, attrMap);
}
attrMap.set(attribute, {
type: typeFn,

@@ -908,6 +879,4 @@ filter: source.filter

}
return result;
}
function getSourcesOption(rawOptions) {

@@ -919,3 +888,2 @@ if (typeof rawOptions.sources === "undefined") {

}
if (typeof rawOptions.sources === "boolean") {

@@ -926,3 +894,2 @@ return rawOptions.sources === true ? {

}
const sources = normalizeSourcesList(rawOptions.sources.list);

@@ -935,3 +902,2 @@ return {

}
function normalizeOptions(rawOptions, loaderContext) {

@@ -945,3 +911,2 @@ return {

}
function pluginRunner(plugins) {

@@ -951,3 +916,2 @@ return {

const result = {};
for (const plugin of plugins) {

@@ -957,10 +921,7 @@ // eslint-disable-next-line no-param-reassign, no-await-in-loop

}
result.html = content;
return result;
}
};
}
function getFilter(filter) {

@@ -971,21 +932,16 @@ return (attribute, value, resourcePath) => {

}
return true;
};
}
const GET_SOURCE_FROM_IMPORT_NAME = "___HTML_LOADER_GET_SOURCE_FROM_IMPORT___";
function getImportCode(html, loaderContext, imports, options) {
if (imports.length === 0) {
return "";
} // TODO simpify in the next major release
}
// TODO simplify in the next major release
const getURLRuntime = require.resolve("./runtime/getUrl.js");
const context = loaderContext.context || loaderContext.rootContext;
const fileURLToHelper = typeof loaderContext.utils !== "undefined" && typeof loaderContext.utils.contextify === "function" ? loaderContext.utils.contextify(context, getURLRuntime) : contextify(context, getURLRuntime);
let code = options.esModule ? `import ${GET_SOURCE_FROM_IMPORT_NAME} from "${fileURLToHelper}";\n` : `var ${GET_SOURCE_FROM_IMPORT_NAME} = require("${fileURLToHelper}");\n`;
for (const item of imports) {

@@ -997,3 +953,2 @@ const {

} = item;
switch (format) {

@@ -1003,3 +958,2 @@ case "import":

break;
case "url":

@@ -1010,11 +964,9 @@ default:

}
return `// Imports\n${code}`;
}
function getModuleCode(html, replacements) {
let code = JSON.stringify(html) // Invalid in JavaScript but valid HTML
let code = JSON.stringify(html)
// Invalid in JavaScript but valid HTML
.replace(/[\u2028\u2029]/g, str => str === "\u2029" ? "\\u2029" : "\\u2028");
let replacersCode = "";
for (const item of replacements) {

@@ -1028,3 +980,2 @@ const {

} = item;
if (typeof runtime === "undefined" || runtime === true) {

@@ -1038,9 +989,8 @@ const getUrlOptions = [].concat(hash ? [`hash: ${JSON.stringify(hash)}`] : []).concat(isValueQuoted ? [] : "maybeNeedQuotes: true");

}
} // Replaces "<script>" or "</script>" to "<" + "script>" or "<" + "/script>".
}
// Replaces "<script>" or "</script>" to "<" + "script>" or "<" + "/script>".
code = code.replace(/<(\/?script)/g, (_, s) => `<" + "${s}`);
return `// Module\n${replacersCode}var code = ${code};\n`;
}
function getExportCode(html, options) {

@@ -1050,6 +1000,4 @@ if (options.esModule) {

}
return `// Exports\nmodule.exports = code;`;
}
function isASCIIC0group(character) {

@@ -1060,44 +1008,39 @@ // C0 and &nbsp;

}
function c0ControlCodesExclude(source) {
let {
value,
startOffset
value
} = source;
if (!value) {
throw new Error("Must be non-empty");
}
while (isASCIIC0group(value.substring(0, 1))) {
startOffset += 1;
value = value.substring(1, value.length);
let start = 0;
for (; start < value.length && isASCIIC0group(value[start]); start++);
if (start === value.length) {
throw new Error("Must be non-empty");
}
while (isASCIIC0group(value.substring(value.length - 1, value.length))) {
value = value.substring(0, value.length - 1);
let end = value.length - 1;
for (; end > -1 && isASCIIC0group(value[end]); end--);
end += 1;
if (start !== 0 || end !== value.length) {
value = value.substring(start, end);
if (!value) {
throw new Error("Must be non-empty");
}
}
if (!value) {
throw new Error("Must be non-empty");
}
return {
value,
startOffset
startOffset: source.startOffset + start
};
}
function traverse(root, callback) {
const visit = (node, parent) => {
let res;
if (callback) {
res = callback(node, parent);
}
let {
childNodes
} = node; // in case a <template> tag is in the middle of the HTML: https://github.com/JPeer264/node-rcs-core/issues/58
} = node;
// in case a <template> tag is in the middle of the HTML: https://github.com/JPeer264/node-rcs-core/issues/58
if (node.content && Array.isArray(node.content.childNodes)) {

@@ -1108,3 +1051,2 @@ ({

}
if (res !== false && Array.isArray(childNodes) && childNodes.length >= 0) {

@@ -1116,7 +1058,4 @@ childNodes.forEach(child => {

};
visit(root, null);
}
const webpackIgnoreCommentRegexp = /webpackIgnore:(\s+)?(true|false)/;
exports.webpackIgnoreCommentRegexp = webpackIgnoreCommentRegexp;
const webpackIgnoreCommentRegexp = exports.webpackIgnoreCommentRegexp = /webpackIgnore:(\s+)?(true|false)/;
{
"name": "html-loader",
"version": "4.2.0",
"version": "5.0.0",
"description": "Html loader module for webpack",

@@ -16,3 +16,3 @@ "license": "MIT",

"engines": {
"node": ">= 14.15.0"
"node": ">= 18.12.0"
},

@@ -28,5 +28,9 @@ "scripts": {

"security": "npm audit --production",
"lint:prettier": "prettier --list-different .",
"lint:prettier": "prettier --cache --list-different .",
"lint:js": "eslint --cache .",
"lint:spelling": "cspell --cache --no-must-find-files --quiet \"**/*.*\"",
"lint": "npm-run-all -l -p \"lint:**\"",
"fix:js": "npm run lint:js -- --fix",
"fix:prettier": "npm run lint:prettier -- --write",
"fix": "npm-run-all -l fix:js fix:prettier",
"test:only": "cross-env NODE_ENV=test jest",

@@ -47,33 +51,34 @@ "test:watch": "npm run test:only -- --watch",

"dependencies": {
"html-minifier-terser": "^7.0.0",
"parse5": "^7.0.0"
"html-minifier-terser": "^7.2.0",
"parse5": "^7.1.2"
},
"devDependencies": {
"@babel/cli": "^7.18.10",
"@babel/core": "^7.18.13",
"@babel/preset-env": "^7.18.10",
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
"@babel/cli": "^7.23.4",
"@babel/core": "^7.23.7",
"@babel/preset-env": "^7.23.8",
"@commitlint/cli": "^18.4.4",
"@commitlint/config-conventional": "^18.4.4",
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
"babel-jest": "^29.0.3",
"babel-jest": "^29.7.0",
"cross-env": "^7.0.3",
"del": "^6.1.1",
"del-cli": "^4.0.0",
"es-check": "^7.0.0",
"eslint": "^8.23.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"handlebars": "^4.7.7",
"html-webpack-plugin": "^5.3.2",
"husky": "^8.0.1",
"jest": "^29.0.3",
"lint-staged": "^13.0.3",
"memfs": "^3.4.7",
"cspell": "^8.3.2",
"del": "^7.1.0",
"del-cli": "^5.1.0",
"es-check": "^7.1.1",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"handlebars": "^4.7.8",
"html-webpack-plugin": "^5.6.0",
"husky": "^8.0.3",
"jest": "^29.7.0",
"lint-staged": "^15.2.0",
"memfs": "^4.6.0",
"npm-run-all": "^4.1.5",
"posthtml": "^0.16.6",
"posthtml-webp": "^2.2.0",
"prettier": "^2.7.1",
"prettier": "^3.2.2",
"standard-version": "^9.5.0",
"unescape-unicode": "^0.2.0",
"webpack": "^5.74.0"
"webpack": "^5.89.0"
},

@@ -80,0 +85,0 @@ "keywords": [

@@ -12,3 +12,3 @@ <div align="center">

[![coverage][cover]][cover-url]
[![chat][chat]][chat-url]
[![discussion][discussion]][discussion-url]
[![size][size]][size-url]

@@ -86,3 +86,3 @@

attributes: string,
resourcePath: string
resourcePath: string,
) => boolean;

@@ -93,3 +93,3 @@ }>;

value: string,
resourcePath: string
resourcePath: string,
) => boolean;

@@ -102,3 +102,3 @@ scriptingEnabled?: boolean;

By default every loadable attributes (for example - `<img src="image.png">`) is imported (`const img = require('./image.png')` or `import img from "./image.png""`).
By default every loadable attribute (for example - `<img src="image.png">`) is imported (`const img = require('./image.png')` or `import img from "./image.png""`).
You may need to specify loaders for images in your configuration (recommended [`asset modules`](https://webpack.js.org/guides/asset-modules/)).

@@ -133,3 +133,3 @@

The `true` value enables processing of all default elements and attributes, the `false` disable processing of all attributes.
The `true` value enables the processing of all default elements and attributes, the `false` value disables the processing of all attributes.

@@ -157,3 +157,3 @@ **webpack.config.js**

Allows you to specify which tags and attributes to process, filter them, filter urls and process sources starts with `/`.
Allows you to specify which tags and attributes to process, filter them, filter urls and process sources starting with `/`.

@@ -219,3 +219,3 @@ For example:

attributes: string,
resourcePath: string
resourcePath: string,
) => boolean;

@@ -227,3 +227,3 @@ }>;

Allows to setup which tags and attributes to process and how, and the ability to filter some of them.
Allows to setup which tags and attributes to process and how, as well as the ability to filter some of them.

@@ -422,3 +422,3 @@ Using `...` syntax allows you to extend [default supported tags and attributes](#sources).

value: string,
resourcePath: string
resourcePath: string,
) => boolean;

@@ -430,3 +430,3 @@ ```

Allow to filter urls. All filtered urls will not be resolved (left in the code as they were written).
All non requestable sources (for example `<img src="javascript:void(0)">`) do not handle by default.
Non-requestable sources (for example `<img src="javascript:void(0)">`) are not handled by default.

@@ -505,3 +505,3 @@ ```js

content: string | Buffer,
loaderContext: LoaderContext
loaderContext: LoaderContext,
) => HTMLElement;

@@ -733,3 +733,3 @@ ```

By default, `html-loader` generates JS modules that use the ES modules syntax.
There are some cases in which using ES modules is beneficial, like in the case of [module concatenation](https://webpack.js.org/plugins/module-concatenation-plugin/) and [tree shaking](https://webpack.js.org/guides/tree-shaking/).
There are some cases in which using ES modules is beneficial, such as [module concatenation](https://webpack.js.org/plugins/module-concatenation-plugin/) and [tree shaking](https://webpack.js.org/guides/tree-shaking/).

@@ -760,3 +760,3 @@ You can enable a CommonJS modules syntax using:

With `<!-- webpackIgnore: true -->` comment, can to disable sources handling for next tag.
With `<!-- webpackIgnore: true -->` comment, one can disable sources handling for next tag.

@@ -787,3 +787,3 @@ ```html

With [`resolve.roots`](https://webpack.js.org/configuration/resolve/#resolveroots) can specify a list of directories where requests of server-relative URLs (starting with '/') are resolved.
With [`resolve.roots`](https://webpack.js.org/configuration/resolve/#resolveroots) one can specify a list of directories where requests of server-relative URLs (starting with '/') are resolved.

@@ -893,3 +893,3 @@ **webpack.config.js**

```html
<!DOCTYPE html>
<!doctype html>
<html>

@@ -1041,11 +1041,5 @@ <head>

A very common scenario is exporting the HTML into their own _.html_ file, to
serve them directly instead of injecting with javascript. This can be achieved
with a combination of 2 loaders:
A very common scenario is exporting the HTML into their own _.html_ file, to serve them directly instead of injecting with javascript.
This can be achieved with a combination of html-loader and [`asset modules`](https://webpack.js.org/guides/asset-modules/).
- [extract-loader](https://github.com/peerigon/extract-loader)
- html-loader
and [`asset modules`](https://webpack.js.org/guides/asset-modules/)
The html-loader will parse the URLs, require the images and everything you

@@ -1099,5 +1093,5 @@ expect. The extract loader will parse the javascript back into a proper html

[cover-url]: https://codecov.io/gh/webpack-contrib/html-loader
[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
[chat-url]: https://gitter.im/webpack/webpack
[discussion]: https://img.shields.io/github/discussions/webpack/webpack
[discussion-url]: https://github.com/webpack/webpack/discussions
[size]: https://packagephobia.now.sh/badge?p=html-loader
[size-url]: https://packagephobia.now.sh/result?p=html-loader
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