Skip to content

Commit b94811f

Browse files
authored
Fix stripTrailingHardline (#16347)
1 parent 5906441 commit b94811f

File tree

4 files changed

+115
-1
lines changed

4 files changed

+115
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#### Preserve empty lines in front matter (#16347 by @fisker)
2+
3+
<!-- prettier-ignore -->
4+
```markdown
5+
<!-- Input -->
6+
---
7+
foo:
8+
- bar1
9+
10+
- bar2
11+
12+
- bar3
13+
---
14+
Markdown
15+
16+
<!-- Prettier stable -->
17+
18+
---
19+
foo:
20+
- bar1
21+
- bar2
22+
- bar3
23+
---
24+
25+
Markdown
26+
27+
28+
<!-- Prettier main -->
29+
---
30+
foo:
31+
- bar1
32+
33+
- bar2
34+
35+
- bar3
36+
---
37+
38+
Markdown
39+
```

src/document/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ function stripTrailingHardlineFromParts(parts) {
212212

213213
function stripTrailingHardlineFromDoc(doc) {
214214
switch (getDocType(doc)) {
215-
case DOC_TYPE_ALIGN:
216215
case DOC_TYPE_INDENT:
217216
case DOC_TYPE_INDENT_IF_BREAK:
218217
case DOC_TYPE_GROUP:
@@ -238,6 +237,7 @@ function stripTrailingHardlineFromDoc(doc) {
238237
case DOC_TYPE_STRING:
239238
return doc.replace(/[\n\r]*$/, "");
240239

240+
case DOC_TYPE_ALIGN:
241241
case DOC_TYPE_CURSOR:
242242
case DOC_TYPE_TRIM:
243243
case DOC_TYPE_LINE_SUFFIX_BOUNDARY:

tests/format/misc/embedded_language_formatting/in-markdown/__snapshots__/format.test.js.snap

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,71 @@ Hello world!
106106
================================================================================
107107
`;
108108

109+
exports[`issue-16342.md - {"embeddedLanguageFormatting":"off"} format 1`] = `
110+
====================================options=====================================
111+
embeddedLanguageFormatting: "off"
112+
parsers: ["markdown"]
113+
printWidth: 80
114+
| printWidth
115+
=====================================input======================================
116+
---
117+
foo:
118+
- bar1
119+
120+
- bar2
121+
122+
- bar3
123+
---
124+
125+
Markdown
126+
127+
=====================================output=====================================
128+
---
129+
foo:
130+
- bar1
131+
132+
- bar2
133+
134+
- bar3
135+
---
136+
137+
Markdown
138+
139+
================================================================================
140+
`;
141+
142+
exports[`issue-16342.md format 1`] = `
143+
====================================options=====================================
144+
parsers: ["markdown"]
145+
printWidth: 80
146+
| printWidth
147+
=====================================input======================================
148+
---
149+
foo:
150+
- bar1
151+
152+
- bar2
153+
154+
- bar3
155+
---
156+
157+
Markdown
158+
159+
=====================================output=====================================
160+
---
161+
foo:
162+
- bar1
163+
164+
- bar2
165+
166+
- bar3
167+
---
168+
169+
Markdown
170+
171+
================================================================================
172+
`;
173+
109174
exports[`test.md - {"embeddedLanguageFormatting":"off"} format 1`] = `
110175
====================================options=====================================
111176
embeddedLanguageFormatting: "off"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
foo:
3+
- bar1
4+
5+
- bar2
6+
7+
- bar3
8+
---
9+
10+
Markdown

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy