mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
fix(formatter_markdown): keep blank line between HTML and nested list (#27112)
Otherwise, output is not idempotent.
This commit is contained in:
1 parent
611e4ed894
commit
7bcb807eaf
4 files changed
+169
-2
No files matched your search
@@ -211,6 +211,37 @@ though no type 7 block can interrupt a paragraph on a regular line.
|
||||
Printed with the container's prefix the line is no longer lazy, so a blank line keeps the block apart;
|
||||
Prettier prints it adjacent, and the next parse reads it as part of the paragraph.
|
||||
|
||||
## list-after-html-block
|
||||
|
||||
- Why: semantics (prettier/prettier#17690)
|
||||
- Pin: `tests/fixtures/markdown/list-after-html-block.md`
|
||||
|
||||
```markdown
|
||||
<!-- input -->
|
||||
- a
|
||||
|
||||
<div>
|
||||
|
||||
- b
|
||||
|
||||
<!-- ours -->
|
||||
- a
|
||||
|
||||
<div>
|
||||
|
||||
- b
|
||||
|
||||
<!-- prettier (the list item becomes html, one per pass) -->
|
||||
- a
|
||||
|
||||
<div>
|
||||
- b
|
||||
```
|
||||
|
||||
A nested list after a type 6 / 7 HTML block keeps its blank line: only a blank line ends such a block.
|
||||
Prettier joins any list in a list item to the previous block, and the next parse reads the first list line as part of the html.
|
||||
Types 1 to 5 end at their end marker, so a list after them is printed adjacent as Prettier does.
|
||||
|
||||
## list-marker-after-ignored-list
|
||||
|
||||
- Why: semantics
|
||||
|
||||
@@ -113,10 +113,12 @@ fn double_gap(
|
||||
return !after_definition && !multi_line;
|
||||
}
|
||||
|
||||
// A nested list after a paragraph / code keeps its blank line (prettier#17746)
|
||||
// A nested list after a paragraph / code keeps its blank line, and after a type 6 / 7 HTML block,
|
||||
// which only a blank line ends (DIVERGENCES.md#list-after-html-block)
|
||||
if matches!(node, Block::List(_))
|
||||
&& matches!(parent, Parent::ListItem { .. })
|
||||
&& matches!(previous, Block::CodeBlock(_) | Block::Paragraph(_))
|
||||
&& (matches!(previous, Block::CodeBlock(_) | Block::Paragraph(_))
|
||||
|| matches!(previous, Block::HtmlBlock(h) if h.kind >= 6))
|
||||
&& !adjacent
|
||||
{
|
||||
return true;
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
- list
|
||||
|
||||
<details><summary></summary>
|
||||
|
||||
1. item
|
||||
|
||||
2. item
|
||||
|
||||
</details>
|
||||
|
||||
- list
|
||||
|
||||
<div>
|
||||
|
||||
- item
|
||||
- item
|
||||
|
||||
</div>
|
||||
|
||||
- list
|
||||
|
||||
<custom-tag>
|
||||
|
||||
- item
|
||||
|
||||
- list
|
||||
|
||||
<!-- closed by its end marker -->
|
||||
|
||||
- item
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
---
|
||||
source: crates/oxc_formatter_markdown/tests/fixtures/mod.rs
|
||||
assertion_line: 50
|
||||
---
|
||||
==================== Input ====================
|
||||
- list
|
||||
|
||||
<details><summary></summary>
|
||||
|
||||
1. item
|
||||
|
||||
2. item
|
||||
|
||||
</details>
|
||||
|
||||
- list
|
||||
|
||||
<div>
|
||||
|
||||
- item
|
||||
- item
|
||||
|
||||
</div>
|
||||
|
||||
- list
|
||||
|
||||
<custom-tag>
|
||||
|
||||
- item
|
||||
|
||||
- list
|
||||
|
||||
<!-- closed by its end marker -->
|
||||
|
||||
- item
|
||||
|
||||
==================== Output ====================
|
||||
------------------
|
||||
{ printWidth: 80 }
|
||||
------------------
|
||||
- list
|
||||
|
||||
<details><summary></summary>
|
||||
|
||||
1. item
|
||||
|
||||
2. item
|
||||
|
||||
</details>
|
||||
|
||||
- list
|
||||
|
||||
<div>
|
||||
|
||||
- item
|
||||
- item
|
||||
|
||||
</div>
|
||||
|
||||
- list
|
||||
|
||||
<custom-tag>
|
||||
|
||||
- item
|
||||
|
||||
- list
|
||||
|
||||
<!-- closed by its end marker -->
|
||||
- item
|
||||
|
||||
-------------------
|
||||
{ printWidth: 100 }
|
||||
-------------------
|
||||
- list
|
||||
|
||||
<details><summary></summary>
|
||||
|
||||
1. item
|
||||
|
||||
2. item
|
||||
|
||||
</details>
|
||||
|
||||
- list
|
||||
|
||||
<div>
|
||||
|
||||
- item
|
||||
- item
|
||||
|
||||
</div>
|
||||
|
||||
- list
|
||||
|
||||
<custom-tag>
|
||||
|
||||
- item
|
||||
|
||||
- list
|
||||
|
||||
<!-- closed by its end marker -->
|
||||
- item
|
||||
|
||||
===================== End =====================
|
||||
Reference in new issue
Block a user