Skip to content

Commit 227310c

Browse files
authored
Merge pull request #8 from kushtrimh/thymeleaf-keep-original-attributes
Add support to remove or keep original attributes when using Thymelea…
2 parents 68ac11c + 17b83c0 commit 227310c

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ Adding the plugin for `thymeleaf` in this case, would change the `HTML` as follo
5555
|`addLeadingSlash`|`Boolean`|`false`|Adds a leading slash to the attribute if its missing. <br /> _static/image.png_ becomes _/static/image.png_|
5656
|`removeLeadingSlash`|`Boolean`|`false`|Removes a leading slash from the attribute if its present. <br /> _/static/image.png_ becomes _static/image.png_|
5757
|`removeDotSegments`|`Boolean`|`false`|Removes dot-segments from the attribute. <br /> _../../static/image.png_ becomes _static/image.png_ <br /> _./static/image.png_ becomes _static/image.png_ <br /> _.static/iamges.png_ becomes _static/images.png_|
58+
|`removeOriginalAttributes`|`Boolean`|`true`|Removes the original `src` and `href` attributes. Only valid when using `thymeleaf` engine.|

engines/thymeleaf.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ class ThymeleafEngine {
33
apply(assetTags, options) {
44
assetTags.scripts.forEach(script => {
55
script.attributes['th:src'] = '@{' + script.attributes.src + '}';
6-
delete script.attributes['src'];
6+
if (options.removeOriginalAttributes) {
7+
delete script.attributes['src'];
8+
}
79
});
810

911
assetTags.styles.forEach(style => {
1012
style.attributes['th:href'] = '@{' + style.attributes.href + '}';
11-
delete style.attributes['href'];
13+
if (options.removeOriginalAttributes) {
14+
delete style.attributes['href'];
15+
}
1216
});
1317
}
1418
}

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ class JavaTemplateEngineWebpackPlugin {
88
this.options = Object.assign({
99
removeLeadingSlash: false,
1010
addLeadingSlash: false,
11-
removeDotSegments: false
11+
removeDotSegments: false,
12+
removeOriginalAttributes: true,
1213
}, options);
1314
this.htmlWebpackPlugin = plugin;
1415
}

0 commit comments

Comments
 (0)