diff --git a/README.md b/README.md
index 7dc772e0..9fc392c9 100644
--- a/README.md
+++ b/README.md
@@ -270,6 +270,49 @@ module.exports = {
};
```
+If the tag name is not specified it will process all the tags.
+
+> You can use your custom filter to specify html elements to be processed.
+
+For example:
+
+**webpack.config.js**
+
+```js
+module.exports = {
+ module: {
+ rules: [
+ {
+ test: /\.html$/i,
+ loader: 'html-loader',
+ options: {
+ attributes: {
+ list: [
+ {
+ // Attribute name
+ attribute: 'src',
+ // Type of processing, can be `src` or `scrset`
+ type: 'src',
+ // Allow to filter some attributes (optional)
+ filter: (tag, attribute, attributes, resourcePath) => {
+ // The `tag` argument contains a name of the HTML tag.
+ // The `attribute` argument contains a name of the HTML attribute.
+ // The `attributes` argument contains all attributes of the tag.
+ // The `resourcePath` argument contains a path to the loaded HTML file.
+
+ // choose all HTML tags except img tag
+ return tag.toLowerCase() !== 'img';
+ },
+ },
+ ],
+ },
+ },
+ },
+ ],
+ },
+};
+```
+
#### `urlFilter`
Type: `Function`
diff --git a/src/options.json b/src/options.json
index d4ce35df..8291e308 100644
--- a/src/options.json
+++ b/src/options.json
@@ -19,7 +19,7 @@
"instanceof": "Function"
}
},
- "required": ["tag", "attribute", "type"],
+ "required": ["attribute", "type"],
"additionalProperties": false
},
"AttributeList": {
diff --git a/src/plugins/source-plugin.js b/src/plugins/source-plugin.js
index 0ca0955a..78e66dc2 100644
--- a/src/plugins/source-plugin.js
+++ b/src/plugins/source-plugin.js
@@ -495,7 +495,9 @@ export default (options) =>
const getAttribute = (tag, attribute, attributes, resourcePath) => {
return attributeList.find(
(element) =>
- element.tag.toLowerCase() === tag.toLowerCase() &&
+ (typeof element.tag === 'undefined' ||
+ (typeof element.tag !== 'undefined' &&
+ element.tag.toLowerCase() === tag.toLowerCase())) &&
element.attribute.toLowerCase() === attribute.toLowerCase() &&
(element.filter
? element.filter(tag, attribute, attributes, resourcePath)
diff --git a/test/__snapshots__/attributes-option.test.js.snap b/test/__snapshots__/attributes-option.test.js.snap
index 06471f2b..bf491a98 100644
--- a/test/__snapshots__/attributes-option.test.js.snap
+++ b/test/__snapshots__/attributes-option.test.js.snap
@@ -738,6 +738,638 @@ exports[`'attributes' option should handle "src" and "srcset" tags correctly: re
exports[`'attributes' option should handle "src" and "srcset" tags correctly: warnings 1`] = `Array []`;
+exports[`'attributes' option should handle all src attributes in all HTML tags except img (testing filter option) tag is undefined: errors 1`] = `Array []`;
+
+exports[`'attributes' option should handle all src attributes in all HTML tags except img (testing filter option) tag is undefined: module 1`] = `
+"// Imports
+var ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___ = require(\\"../../src/runtime/getUrl.js\\");
+var ___HTML_LOADER_IMPORT_0___ = require(\\"./script.file.js\\");
+var ___HTML_LOADER_IMPORT_1___ = require(\\"./example.ogg\\");
+var ___HTML_LOADER_IMPORT_2___ = require(\\"./example.pdf\\");
+var ___HTML_LOADER_IMPORT_3___ = require(\\"./template.html\\");
+var ___HTML_LOADER_IMPORT_4___ = require(\\"./image.png\\");
+var ___HTML_LOADER_IMPORT_5___ = require(\\"./example.vtt\\");
+var ___HTML_LOADER_IMPORT_6___ = require(\\"./module.file.js\\");
+var ___HTML_LOADER_IMPORT_7___ = require(\\"./fallback.file.js\\");
+// Module
+var ___HTML_LOADER_REPLACER_0___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___);
+var ___HTML_LOADER_REPLACER_1___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_1___);
+var ___HTML_LOADER_REPLACER_2___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_2___);
+var ___HTML_LOADER_REPLACER_3___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_3___);
+var ___HTML_LOADER_REPLACER_4___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_4___);
+var ___HTML_LOADER_REPLACER_5___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_5___);
+var ___HTML_LOADER_REPLACER_6___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_6___);
+var ___HTML_LOADER_REPLACER_7___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_7___);
+var code = \\"\\\\n\\\\n
My First Heading
\\\\nMy first paragraph.
\\\\nAn Unordered HTML List
\\\\n\\\\n\\\\n - Coffee
\\\\n - Tea
\\\\n - Milk
\\\\n
\\\\n\\\\nAn Ordered HTML List
\\\\n\\\\n\\\\n - Coffee
\\\\n - Tea
\\\\n - Milk
\\\\n
\\\\n\\\\n\\\\n\\\\n\\\\n\\\\nFoo
\\\\n\\\\n\\\\nBAR
\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n
\\\\n
\\\\n
\\\\n
\\\\n
\\\\n
\\\\n
\\\\n
\\\\n
\\\\n
\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n
\\\\n\\\\n\\\\n\\\\n
\\\\n
\\\\n
\\\\n
\\\\n
\\\\n
\\\\n
\\\\n
\\\\n
\\\\n
\\\\n
\\\\n
\\\\n
\\\\n\\\\n\\\\n \\\\n \\\\n
\\\\n\\\\n\\\\n\\\\n\\\\n