Skip to content

Commit

Permalink
Fixes #8 Unnecessary whitespace when removing classes that do not mat…
Browse files Browse the repository at this point in the history
…ch those defined in stylesheet (#9)
  • Loading branch information
mir3z authored and simonlc committed Jun 6, 2019
1 parent abb2015 commit 885c173
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/index.js
Expand Up @@ -56,6 +56,7 @@ class MinifyClassnames {
return this.classMap[value] || '';
}
})
.filter(Boolean)
.join(' ')
.trim();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "posthtml-minify-classnames",
"version": "0.2.1",
"version": "0.2.2",
"description": "PostHTML plugin for minifying classnames",
"main": "index.js",
"author": "Simon Laroche <hi@simon.lc> (https://simon.lc)",
Expand Down
39 changes: 39 additions & 0 deletions test/plugin.js
Expand Up @@ -684,3 +684,42 @@ test('works with no options', t => {
t.is(result.html, expected);
});
});

test('strips unnecessary whitespaces when removing classes that do not match any in our CSS #8', t => {
const html = `
<html>
<style>
.intro {
color: blue;
}
.big {
font-size: 600px;
}
</style>
<body>
<h1 class="intro non-existing-class big">Look!</h1>
</body>
</html>
`;

const expected = `
<html>
<style>
.a {
color: blue;
}
.b {
font-size: 600px;
}
</style>
<body>
<h1 class="a b">Look!</h1>
</body>
</html>
`;

return posthtml().use(plugin()).process(html)
.then(result => {
t.is(result.html, expected);
});
});

0 comments on commit 885c173

Please sign in to comment.