Skip to content

Commit

Permalink
fix(html): preserve content for element in <pre> correctly (#5473)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatyang committed Nov 15, 2018
1 parent d86f39c commit c00dcb9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/language-html/printer-html.js
Expand Up @@ -476,15 +476,17 @@ function printChildren(path, options, print) {
group(printOpeningTag(childPath, options, print)),
replaceNewlines(
options.originalText.slice(
child.startSourceSpan.end.offset -
child.startSourceSpan.end.offset +
(child.firstChild &&
needsToBorrowParentOpeningTagEndMarker(child.firstChild)
? printOpeningTagEndMarker(child).length
? -printOpeningTagEndMarker(child).length
: 0),
child.endSourceSpan.start.offset +
(child.lastChild &&
needsToBorrowParentClosingTagStartMarker(child.lastChild)
? printClosingTagStartMarker(child).length
: needsToBorrowLastChildClosingTagEndMarker(child)
? -printClosingTagEndMarker(child.lastChild).length
: 0)
),
literalline
Expand Down
20 changes: 20 additions & 0 deletions tests/html_tags/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -647,6 +647,8 @@ ___________________________
</div>
</div>
<pre></pre>

<pre><code #foo></code></pre>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<pre>
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -735,6 +737,8 @@ ___________________________
</div>
<pre></pre>

<pre><code #foo></code></pre>

`;

exports[`pre.html - html-verify 2`] = `
Expand Down Expand Up @@ -816,6 +820,8 @@ ___________________________
</div>
</div>
<pre></pre>

<pre><code #foo></code></pre>
~
<pre>
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -924,6 +930,8 @@ ___________________________
</div>
<pre></pre>

<pre><code #foo></code></pre>

`;

exports[`pre.html - html-verify 3`] = `
Expand Down Expand Up @@ -1005,6 +1013,8 @@ ___________________________
</div>
</div>
<pre></pre>

<pre><code #foo></code></pre>
~~~~~~~~~~~~~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6 +1093,8 @@ ___________________________
</div>
<pre></pre>

<pre><code #foo></code></pre>

`;

exports[`pre.html - html-verify 4`] = `
Expand Down Expand Up @@ -1164,6 +1176,8 @@ ___________________________
</div>
</div>
<pre></pre>

<pre><code #foo></code></pre>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<pre>
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -1252,6 +1266,8 @@ ___________________________
</div>
<pre></pre>

<pre><code #foo></code></pre>

`;

exports[`pre.html - html-verify 5`] = `
Expand Down Expand Up @@ -1333,6 +1349,8 @@ ___________________________
</div>
</div>
<pre></pre>

<pre><code #foo></code></pre>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<pre>
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -1421,6 +1439,8 @@ ___________________________
</div>
<pre></pre>

<pre><code #foo></code></pre>

`;

exports[`tags.html - html-verify 1`] = `
Expand Down
2 changes: 2 additions & 0 deletions tests/html_tags/pre.html
Expand Up @@ -76,3 +76,5 @@
</div>
</div>
<pre></pre>

<pre><code #foo></code></pre>

0 comments on commit c00dcb9

Please sign in to comment.