forked from sveltejs/svelte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…tejs#6990) Fixes sveltejs#6437 Fixes sveltejs#4731 Closes sveltejs#4737 Whitespace is now untouched inside <pre> tag and other tags if preserveWhitespace is true
- Loading branch information
Showing
15 changed files
with
361 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
export default { | ||
test({ assert, target }) { | ||
// Test for <pre> tag | ||
const elementPre = target.querySelector('#pre'); | ||
// Test for non <pre> tag | ||
const elementDiv = target.querySelector('#div'); | ||
// Test for <pre> tag in non <pre> tag | ||
const elementDivWithPre = target.querySelector('#div-with-pre'); | ||
|
||
// There is a slight difference in innerHTML because there is a difference in HTML optimization (in jsdom) | ||
// depending on how the innerHTML is set. | ||
// (There is no difference in the display.) | ||
// Reassign innerHTML to add the same optimizations to innerHTML. | ||
|
||
// eslint-disable-next-line no-self-assign | ||
elementPre.innerHTML = elementPre.innerHTML; | ||
// eslint-disable-next-line no-self-assign | ||
elementDiv.innerHTML = elementDiv.innerHTML; | ||
// eslint-disable-next-line no-self-assign | ||
elementDivWithPre.innerHTML = elementDivWithPre.innerHTML; | ||
|
||
assert.equal( | ||
elementPre.innerHTML, | ||
` | ||
A | ||
B | ||
<span> | ||
C | ||
D | ||
</span> | ||
E | ||
F | ||
` | ||
); | ||
assert.equal( | ||
elementDiv.innerHTML, | ||
`A | ||
B | ||
<span>C | ||
D</span> | ||
E | ||
F` | ||
); | ||
assert.equal( | ||
elementDivWithPre.innerHTML, | ||
`<pre> A | ||
B | ||
<span> | ||
C | ||
D | ||
</span> | ||
E | ||
F | ||
</pre>` | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<pre id="pre"> | ||
A | ||
B | ||
<span> | ||
C | ||
D | ||
</span> | ||
E | ||
F | ||
</pre> | ||
|
||
<div id="div"> | ||
A | ||
B | ||
<span> | ||
C | ||
D | ||
</span> | ||
E | ||
F | ||
</div> | ||
|
||
<div id="div-with-pre"> | ||
<pre> | ||
A | ||
B | ||
<span> | ||
C | ||
D | ||
</span> | ||
E | ||
F | ||
</pre> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
export default { | ||
compileOptions: { | ||
preserveWhitespace: true | ||
}, | ||
test({ assert, target }) { | ||
// Test for <pre> tag | ||
const elementPre = target.querySelector('#pre'); | ||
// Test for non <pre> tag | ||
const elementDiv = target.querySelector('#div'); | ||
// Test for <pre> tag in non <pre> tag | ||
const elementDivWithPre = target.querySelector('#div-with-pre'); | ||
|
||
// There is a slight difference in innerHTML because there is a difference in HTML optimization (in jsdom) | ||
// depending on how the innerHTML is set. | ||
// (There is no difference in the display.) | ||
// Reassign innerHTML to add the same optimizations to innerHTML. | ||
|
||
// eslint-disable-next-line no-self-assign | ||
elementPre.innerHTML = elementPre.innerHTML; | ||
// eslint-disable-next-line no-self-assign | ||
elementDiv.innerHTML = elementDiv.innerHTML; | ||
// eslint-disable-next-line no-self-assign | ||
elementDivWithPre.innerHTML = elementDivWithPre.innerHTML; | ||
|
||
assert.equal( | ||
elementPre.innerHTML, | ||
` | ||
A | ||
B | ||
<span> | ||
C | ||
D | ||
</span> | ||
E | ||
F | ||
` | ||
); | ||
assert.equal( | ||
elementDiv.innerHTML, | ||
` | ||
A | ||
B | ||
<span> | ||
C | ||
D | ||
</span> | ||
E | ||
F | ||
` | ||
); | ||
assert.equal( | ||
elementDivWithPre.innerHTML, | ||
` | ||
<pre> A | ||
B | ||
<span> | ||
C | ||
D | ||
</span> | ||
E | ||
F | ||
</pre> | ||
` | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<pre id="pre"> | ||
A | ||
B | ||
<span> | ||
C | ||
D | ||
</span> | ||
E | ||
F | ||
</pre> | ||
|
||
<div id="div"> | ||
A | ||
B | ||
<span> | ||
C | ||
D | ||
</span> | ||
E | ||
F | ||
</div> | ||
|
||
<div id="div-with-pre"> | ||
<pre> | ||
A | ||
B | ||
<span> | ||
C | ||
D | ||
</span> | ||
E | ||
F | ||
</pre> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
withoutNormalizeHtml: true | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<pre> | ||
A | ||
B | ||
<span> | ||
C | ||
D | ||
</span> | ||
E | ||
F | ||
</pre> | ||
|
||
<div>A | ||
B | ||
<span>C | ||
D | ||
</span> | ||
E | ||
F | ||
</div> | ||
|
||
<div><pre> | ||
A | ||
B | ||
<span> | ||
C | ||
D | ||
</span> | ||
E | ||
F | ||
</pre></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<pre> | ||
A | ||
B | ||
<span> | ||
C | ||
D | ||
</span> | ||
E | ||
F | ||
</pre> | ||
|
||
<div> | ||
A | ||
B | ||
<span> | ||
C | ||
D | ||
</span> | ||
E | ||
F | ||
</div> | ||
|
||
<div> | ||
<pre> | ||
A | ||
B | ||
<span> | ||
C | ||
D | ||
</span> | ||
E | ||
F | ||
</pre> | ||
</div> |
6 changes: 6 additions & 0 deletions
6
test/server-side-rendering/samples/preserve-whitespaces/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
withoutNormalizeHtml: true, | ||
compileOptions: { | ||
preserveWhitespace: true | ||
} | ||
}; |
34 changes: 34 additions & 0 deletions
34
test/server-side-rendering/samples/preserve-whitespaces/_expected.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<pre> | ||
A | ||
B | ||
<span> | ||
C | ||
D | ||
</span> | ||
E | ||
F | ||
</pre> | ||
|
||
<div> | ||
A | ||
B | ||
<span> | ||
C | ||
D | ||
</span> | ||
E | ||
F | ||
</div> | ||
|
||
<div> | ||
<pre> | ||
A | ||
B | ||
<span> | ||
C | ||
D | ||
</span> | ||
E | ||
F | ||
</pre> | ||
</div> |
Oops, something went wrong.