Skip to content

Commit 30120ca

Browse files
committed
fix: node content handling in style tags
1 parent f3bafaa commit 30120ca

11 files changed

Lines changed: 6632 additions & 5635 deletions

lib/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@ module.exports = (options = {}) => tree => {
5252

5353
const process = node => {
5454
if (node.tag === 'style' && node.content) {
55+
const content = Array.isArray(node.content) ? node.content.join('') : node.content
56+
5557
node.content = postcss([
5658
postcssSafeCSS({
5759
replacements: options.replacements
5860
})
5961
])
60-
.process(node.content.join('').trim())
62+
.process(content)
6163
.css
6264
}
6365

package-lock.json

Lines changed: 6595 additions & 5616 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/expected/custom.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<style>.foo-w-2_5 {
4+
<style>
5+
.foo-w-2_5 {
56
width: .625rem;
6-
}</style>
7+
}
8+
</style>
79
</head>
810
<body>
911
<div class="foo-w-2_5">

test/expected/empty-style.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<style></style>
4+
<style> </style>
55
</head>
66
<body>
77
</body>

test/expected/font-face.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<style>.foo-w-3-5 {
4+
<style>
5+
.foo-w-3-5 {
56
width: 60%;
67
}
78
@font-face {
@@ -12,7 +13,8 @@
1213
}
1314
.foo-italic {
1415
font-style: italic;
15-
}</style>
16+
}
17+
</style>
1618
</head>
1719
<body>
1820
<div class="foo foo-open-sans foo-w-3-5">

test/expected/media-queries.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<style>.foo {
4+
<style>
5+
.foo {
56
font-style: normal;
67
}
78
@media (max-width: 600px) {
@@ -17,7 +18,8 @@
1718
.sm-w-2_5 {
1819
width: .625rem;
1920
}
20-
}</style>
21+
}
22+
</style>
2123
</head>
2224
<body>
2325
<div class="foo sm-italic sm-w-3-5 sm-w-50pc sm-w-2_5">

test/expected/multiple-style.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<style>.foo-italic {
4+
<style>
5+
.foo-italic {
56
font-style: italic;
67
}
78
.foo-w-3-5 {
89
width: 60%;
9-
}</style>
10-
<style>.foo-w-50pc {
10+
}
11+
</style>
12+
<style>
13+
.foo-w-50pc {
1114
width: 50%;
1215
}
1316
.foo-w-2_5 {
1417
width: .625rem;
15-
}</style>
18+
}
19+
</style>
1620
</head>
1721
<body>
1822
<div class="foo foo-italic foo-w-3-5 foo-w-50pc foo-w-2_5">

test/expected/override.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<style>.foo__italic {
4+
<style>
5+
.foo__italic {
56
font-style: italic;
67
}
78
.foo__w-3-5 {
@@ -12,7 +13,8 @@
1213
}
1314
.foo__w-2_5 {
1415
width: .625rem;
15-
}</style>
16+
}
17+
</style>
1618
</head>
1719
<body>
1820
<div class="foo foo__italic foo__w-3-5 foo__w-50pc foo__w-2_5">

test/expected/sanity.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<style>/* A comment that includes a <tag> inside */
4+
<style>
5+
/* A comment that includes a <tag> inside */
56
.foo-italic {
67
font-style: italic; /* 1 */
78
}
@@ -28,7 +29,8 @@
2829
}
2930
.foo-mt--40px {
3031
margin-top: -40px;
31-
}</style>
32+
}
33+
</style>
3234
</head>
3335
<body>
3436
<div class="foo foo-italic foo-w-3-5 foo-w-50pc foo-w-2_5 foo-w-600px">

test/expected/style-only.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<style>.foo-italic {
4+
<style>
5+
.foo-italic {
56
font-style: italic;
67
}
78
.foo-w-3-5 {
@@ -12,7 +13,8 @@
1213
}
1314
.foo-w-2_5 {
1415
width: .625rem;
15-
}</style>
16+
}
17+
</style>
1618
</head>
1719
<body>
1820
</body>

0 commit comments

Comments
 (0)