fix(markdown): respect blank line between block htmls (#4609)

Fixes #4605 

The AST here is actually two `html`s and it did follow the [CommonMark spec](https://spec.commonmark.org/0.28/#html-blocks), so I ended up with respecting the blank line between block `html`s.
master
Ika 2018-06-01 00:33:37 +08:00 committed by GitHub
parent a9b21a01e2
commit e74e6565b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 3 deletions

View File

@ -705,9 +705,20 @@ function shouldPrePrintDoubleHardline(node, data) {
const isPrevNodePrettierIgnore = isPrettierIgnore(data.prevNode) === "next";
const isBlockHtmlWithoutBlankLineBetweenPrevHtml =
node.type === "html" &&
data.prevNode &&
data.prevNode.type === "html" &&
data.prevNode.position.end.line + 1 === node.position.start.line;
return (
isPrevNodeLooseListItem ||
!(isSiblingNode || isInTightListItem || isPrevNodePrettierIgnore)
!(
isSiblingNode ||
isInTightListItem ||
isPrevNodePrettierIgnore ||
isBlockHtmlWithoutBlankLineBetweenPrevHtml
)
);
}

View File

@ -1,5 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`blank-line-between-htmls.md 1`] = `
<!--lint disable no-html-->
<p align="center"><img src="logo/vertical.png" alt="labelify" height="150px"></p>
<!--lint enable no-html-->
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<!--lint disable no-html-->
<p align="center"><img src="logo/vertical.png" alt="labelify" height="150px"></p>
<!--lint enable no-html-->
`;
exports[`multiline.md 1`] = `
1. Some test text, the goal is to have the html table below nested within this number. When formating on save Prettier will continue to add an indent each time pushing the table further and further out of sync.

View File

@ -0,0 +1,3 @@
<!--lint disable no-html-->
<p align="center"><img src="logo/vertical.png" alt="labelify" height="150px"></p>
<!--lint enable no-html-->

View File

@ -63,7 +63,6 @@ exports[`top-level-range.md 1`] = `
<!-- prettier-ignore-end -->
> <!-- prettier-ignore-start -->
>
> <!-- some tool start (this shouldn't be ignored) -->
>
> | some | table |
@ -72,7 +71,6 @@ exports[`top-level-range.md 1`] = `
> | 2 | b |
>
> <!-- some tool end -->
>
> <!-- prettier-ignore-end -->
`;