Skip to content

Commit 46526b4

Browse files
Add missing blank line around code block (#17675)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent a04ec11 commit 46526b4

File tree

4 files changed

+297
-4
lines changed

4 files changed

+297
-4
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#### Add missing blank line around code block (#17675 by @fisker)
2+
3+
<!-- prettier-ignore -->
4+
````md
5+
<!-- Input -->
6+
1. Some text, and code block below, with newline after code block
7+
8+
```yaml
9+
---
10+
foo: bar
11+
```
12+
13+
1. Another
14+
2. List
15+
16+
<!-- Prettier stable -->
17+
1. Some text, and code block below, with newline after code block
18+
19+
```yaml
20+
---
21+
foo: bar
22+
```
23+
1. Another
24+
2. List
25+
26+
<!-- Prettier main -->
27+
1. Some text, and code block below, with newline after code block
28+
29+
```yaml
30+
---
31+
foo: bar
32+
```
33+
34+
1. Another
35+
2. List
36+
````

src/language-markdown/printer-markdown.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -674,9 +674,12 @@ function isLooseListItem(node, options) {
674674
}
675675

676676
function shouldPrePrintDoubleHardline({ node, previous, parent }, options) {
677-
const isPrevNodeLooseListItem = isLooseListItem(previous, options);
678-
679-
if (isPrevNodeLooseListItem) {
677+
if (
678+
isLooseListItem(previous, options) ||
679+
(node.type === "list" &&
680+
parent.type === "listItem" &&
681+
previous.type === "code")
682+
) {
680683
return true;
681684
}
682685

tests/format/markdown/list/__snapshots__/format.test.js.snap

Lines changed: 232 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`align.md - {"proseWrap":"always","tabWidth":0} format 1`] = `
44
====================================options=====================================
@@ -2295,6 +2295,237 @@ proseWrap: "always"
22952295
================================================================================
22962296
`;
22972297

2298+
exports[`issue-17652.md - {"proseWrap":"always","tabWidth":0} format 1`] = `
2299+
====================================options=====================================
2300+
parsers: ["markdown"]
2301+
printWidth: 80
2302+
proseWrap: "always"
2303+
tabWidth: 0
2304+
| printWidth
2305+
=====================================input======================================
2306+
1. Some text, and code block below, with newline after code block
2307+
2308+
\`\`\`yaml
2309+
---
2310+
foo: bar
2311+
\`\`\`
2312+
2313+
1. Another
2314+
2. List
2315+
2316+
1. Some text, and code block below, with newline after code block
2317+
2318+
1. Another
2319+
2. List
2320+
2321+
2322+
\`\`\`yaml
2323+
---
2324+
foo: bar
2325+
\`\`\`
2326+
2327+
1. Another
2328+
2. List
2329+
2330+
=====================================output=====================================
2331+
1. Some text, and code block below, with newline after code block
2332+
2333+
\`\`\`yaml
2334+
---
2335+
foo: bar
2336+
\`\`\`
2337+
2338+
1. Another
2339+
2. List
2340+
2341+
1. Some text, and code block below, with newline after code block
2342+
1. Another
2343+
2. List
2344+
2345+
\`\`\`yaml
2346+
---
2347+
foo: bar
2348+
\`\`\`
2349+
2350+
1. Another
2351+
2. List
2352+
2353+
================================================================================
2354+
`;
2355+
2356+
exports[`issue-17652.md - {"proseWrap":"always","tabWidth":4} format 1`] = `
2357+
====================================options=====================================
2358+
parsers: ["markdown"]
2359+
printWidth: 80
2360+
proseWrap: "always"
2361+
tabWidth: 4
2362+
| printWidth
2363+
=====================================input======================================
2364+
1. Some text, and code block below, with newline after code block
2365+
2366+
\`\`\`yaml
2367+
---
2368+
foo: bar
2369+
\`\`\`
2370+
2371+
1. Another
2372+
2. List
2373+
2374+
1. Some text, and code block below, with newline after code block
2375+
2376+
1. Another
2377+
2. List
2378+
2379+
2380+
\`\`\`yaml
2381+
---
2382+
foo: bar
2383+
\`\`\`
2384+
2385+
1. Another
2386+
2. List
2387+
2388+
=====================================output=====================================
2389+
1. Some text, and code block below, with newline after code block
2390+
2391+
\`\`\`yaml
2392+
---
2393+
foo: bar
2394+
\`\`\`
2395+
2396+
1. Another
2397+
2. List
2398+
2399+
1. Some text, and code block below, with newline after code block
2400+
1. Another
2401+
2. List
2402+
2403+
\`\`\`yaml
2404+
---
2405+
foo: bar
2406+
\`\`\`
2407+
2408+
1. Another
2409+
2. List
2410+
2411+
================================================================================
2412+
`;
2413+
2414+
exports[`issue-17652.md - {"proseWrap":"always","tabWidth":999} format 1`] = `
2415+
====================================options=====================================
2416+
parsers: ["markdown"]
2417+
printWidth: 80
2418+
proseWrap: "always"
2419+
tabWidth: 999
2420+
| printWidth
2421+
=====================================input======================================
2422+
1. Some text, and code block below, with newline after code block
2423+
2424+
\`\`\`yaml
2425+
---
2426+
foo: bar
2427+
\`\`\`
2428+
2429+
1. Another
2430+
2. List
2431+
2432+
1. Some text, and code block below, with newline after code block
2433+
2434+
1. Another
2435+
2. List
2436+
2437+
2438+
\`\`\`yaml
2439+
---
2440+
foo: bar
2441+
\`\`\`
2442+
2443+
1. Another
2444+
2. List
2445+
2446+
=====================================output=====================================
2447+
1. Some text, and code block below, with newline after code block
2448+
2449+
\`\`\`yaml
2450+
---
2451+
foo: bar
2452+
\`\`\`
2453+
2454+
1. Another
2455+
2. List
2456+
2457+
1. Some text, and code block below, with newline after code block
2458+
1. Another
2459+
2. List
2460+
2461+
\`\`\`yaml
2462+
---
2463+
foo: bar
2464+
\`\`\`
2465+
2466+
1. Another
2467+
2. List
2468+
2469+
================================================================================
2470+
`;
2471+
2472+
exports[`issue-17652.md - {"proseWrap":"always"} format 1`] = `
2473+
====================================options=====================================
2474+
parsers: ["markdown"]
2475+
printWidth: 80
2476+
proseWrap: "always"
2477+
| printWidth
2478+
=====================================input======================================
2479+
1. Some text, and code block below, with newline after code block
2480+
2481+
\`\`\`yaml
2482+
---
2483+
foo: bar
2484+
\`\`\`
2485+
2486+
1. Another
2487+
2. List
2488+
2489+
1. Some text, and code block below, with newline after code block
2490+
2491+
1. Another
2492+
2. List
2493+
2494+
2495+
\`\`\`yaml
2496+
---
2497+
foo: bar
2498+
\`\`\`
2499+
2500+
1. Another
2501+
2. List
2502+
2503+
=====================================output=====================================
2504+
1. Some text, and code block below, with newline after code block
2505+
2506+
\`\`\`yaml
2507+
---
2508+
foo: bar
2509+
\`\`\`
2510+
2511+
1. Another
2512+
2. List
2513+
2514+
1. Some text, and code block below, with newline after code block
2515+
1. Another
2516+
2. List
2517+
2518+
\`\`\`yaml
2519+
---
2520+
foo: bar
2521+
\`\`\`
2522+
2523+
1. Another
2524+
2. List
2525+
2526+
================================================================================
2527+
`;
2528+
22982529
exports[`long-paragraph.md - {"proseWrap":"always","tabWidth":0} format 1`] = `
22992530
====================================options=====================================
23002531
parsers: ["markdown"]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
1. Some text, and code block below, with newline after code block
2+
3+
```yaml
4+
---
5+
foo: bar
6+
```
7+
8+
1. Another
9+
2. List
10+
11+
1. Some text, and code block below, with newline after code block
12+
13+
1. Another
14+
2. List
15+
16+
17+
```yaml
18+
---
19+
foo: bar
20+
```
21+
22+
1. Another
23+
2. List

0 commit comments

Comments
 (0)