Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(html): preserve content for element in <pre> correctly #5473

Merged
merged 2 commits into from Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 #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~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<pre>
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -1083,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>