Markdown: fix HTML formatting broken if the beginning tag start… (#7181)

* fix markdown formatting broken if the beginning html tag starts after a list item

* add test for beginning-tag-after-a-list-item in markdown_html

* add changelog_unreleased of pr-7181

* fix test of ast breaking for beginning-tag-after-a-list-item

* update changelog_unreleased pr-7181

* fix changelog_unreleased

* fix beginning tag starts after a list item in markdown

* add test case for beginning-tag-after-a-list-item

* update changelog_unreleased
This commit is contained in:
Daiki Ihara authored and Lipis committed 2020-01-02 14:02:17 +02:00
1 parent cffdd1d4f9
commit 47ece13d78
4 files changed
+117 -1

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
#### fix HTML formatting broken if the beginning tag starts after a list item ([#7181](https://github.com/prettier/prettier/pull/7181) by [@sasurau4](https://github.com/sasurau4))
Previously, when Prettier format the html tag that starts after a list item, it would insert indent and break the relationship of open and close tag. Now, Prettier no longer change anything.
<!-- prettier-ignore -->
```md
<!-- Input -->
- A list item.
<details><summary>Summary</summary>
<p>
- A list item.
</p>
</details>
<!-- Prettier stable -->
- A list item.
<details><summary>Summary</summary>
<p>
- A list item.
</p>
</details>
<!-- Prettier master -->
- A list item.
<details><summary>Summary</summary>
<p>
- A list item.
</p>
</details>
```
+22 -1
View File
@@ -254,6 +254,19 @@ function genericPrint(path, options, print) {
return printChildren(path, options, print, {
processor: (childPath, index) => {
const prefix = getPrefix();
const childNode = childPath.getValue();
if (
childNode.children.length === 2 &&
childNode.children[1].type === "html" &&
childNode.children[1].position.indent.every(indent => indent === 1)
) {
return concat([
prefix,
printListItem(childPath, options, print, prefix)
]);
}
return concat([
prefix,
align(
@@ -794,13 +807,21 @@ function shouldPrePrintDoubleHardline(node, data) {
data.prevNode.type === "html" &&
data.prevNode.position.end.line + 1 === node.position.start.line;
const isHtmlDirectAfterListItem =
node.type === "html" &&
data.parentNode.type === "listItem" &&
data.prevNode &&
data.prevNode.type === "paragraph" &&
data.prevNode.position.end.line + 1 === node.position.start.line;
return (
isPrevNodeLooseListItem ||
!(
isSiblingNode ||
isInTightListItem ||
isPrevNodePrettierIgnore ||
isBlockHtmlWithoutBlankLineBetweenPrevHtml
isBlockHtmlWithoutBlankLineBetweenPrevHtml ||
isHtmlDirectAfterListItem
)
);
}
@@ -1,5 +1,48 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`beginning-tag-after-a-list-item.md 1`] = `
====================================options=====================================
parsers: ["markdown"]
printWidth: 80
proseWrap: "always"
| printWidth
=====================================input======================================
- A list item.
<details><summary>Summary</summary>
<p>
- A list item.
</p>
</details>
- A list item.
<blockquote>
<p>quoted sentence1<br>
quoted sentence2</p>
</blockquote>
=====================================output=====================================
- A list item.
<details><summary>Summary</summary>
<p>
- A list item.
</p>
</details>
- A list item.
<blockquote>
<p>quoted sentence1<br>
quoted sentence2</p>
</blockquote>
================================================================================
`;
exports[`blank-line-between-htmls.md 1`] = `
====================================options=====================================
parsers: ["markdown"]
@@ -0,0 +1,15 @@
- A list item.
<details><summary>Summary</summary>
<p>
- A list item.
</p>
</details>
- A list item.
<blockquote>
<p>quoted sentence1<br>
quoted sentence2</p>
</blockquote>