Skip to content

Commit 9c735fe

Browse files
authored
Merge pull request #15 from dmnsgn/master
fix: handle classIgnore for img with no class attribute
2 parents e1248b4 + 314d9f0 commit 9c735fe

3 files changed

Lines changed: 3 additions & 1 deletion

File tree

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = function (options) {
2020
return function posthtmlWebp (tree) {
2121
tree.match([{ tag: 'img' }, { tag: 'amp-img' }], function (imgNode) {
2222
if (imgNode.skip) return imgNode
23-
var classes = imgNode.attrs && imgNode.attrs.class && (imgNode.attrs.class.split(' ') || [])
23+
var classes = (imgNode.attrs && imgNode.attrs.class && imgNode.attrs.class.split(' ')) || []
2424
var extension = imgNode.attrs.src.split('.').pop()
2525
var isIgnoredByClass = options.classIgnore.filter(className => classes.includes(className)).length > 0
2626
var isIgnoredByExtension = options.extensionIgnore.filter(fileExtension => fileExtension === extension).length > 0

test/fixtures/ignore.expected.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
<html>
33
<body>
44
<img class="ignore-class" srcset="photo-lg.jpg 1000w, photo-md.jpg 500w, photo-sm.jpg 250w" src="photo.png">
5+
<picture><source type="image/webp" srcset="photo.png.webp"><img src="photo.png"></picture>
56
</body>
67
</html>

test/fixtures/ignore.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
<html>
33
<body>
44
<img class="ignore-class" srcset="photo-lg.jpg 1000w, photo-md.jpg 500w, photo-sm.jpg 250w" src="photo.png">
5+
<img src="photo.png">
56
</body>
67
</html>

0 commit comments

Comments
 (0)