Skip to content

Commit 1e87380

Browse files
committed
fix: add newlines between listed code
1 parent ef7ae36 commit 1e87380

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

mdformat_mkdocs/_normalize_list.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,25 @@ def _format_new_content(line: LineResult, inc_numbers: bool, is_code: bool) -> s
362362
return new_content
363363

364364

365+
def _insert_newlines(
366+
parsed_lines: list[LineResult],
367+
zipped_lines: list[tuple[str, str]],
368+
) -> list[tuple[str, str]]:
369+
"""Extend zipped_lines with newlines if necessary."""
370+
newline = ("", "")
371+
new_lines: list[tuple[str, str]] = []
372+
for line, zip_line in zip_equal(parsed_lines, zipped_lines):
373+
new_lines.append(zip_line)
374+
if (
375+
line.parsed.syntax == Syntax.EDGE_CODE
376+
and line.parents
377+
and line.parents[-1].syntax in SYNTAX_CODE_LIST
378+
):
379+
new_lines.append(newline)
380+
381+
return new_lines
382+
383+
365384
def parse_text(*, text: str, inc_numbers: bool, use_sem_break: bool) -> ParsedText:
366385
"""Post-processor to normalize lists.
367386
@@ -400,8 +419,9 @@ def parse_text(*, text: str, inc_numbers: bool, use_sem_break: bool) -> ParsedTe
400419
),
401420
]
402421

422+
new_lines = _insert_newlines(lines, [*zip_equal(new_indents, new_contents)])
403423
return ParsedText(
404-
new_lines=[*zip_equal(new_indents, new_contents)],
424+
new_lines=new_lines,
405425
debug_original_lines=lines,
406426
debug_block_indents=block_indents,
407427
)

tests/format/__snapshots__/test_parsed_result.ambr

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,6 +2317,10 @@
23172317
'',
23182318
'',
23192319
),
2320+
tuple(
2321+
'',
2322+
'',
2323+
),
23202324
tuple(
23212325
' ',
23222326
'1. ```bash',
@@ -2341,6 +2345,10 @@
23412345
'',
23422346
'',
23432347
),
2348+
tuple(
2349+
'',
2350+
'',
2351+
),
23442352
tuple(
23452353
' ',
23462354
'- ```powershell',
@@ -2357,10 +2365,18 @@
23572365
'',
23582366
'',
23592367
),
2368+
tuple(
2369+
'',
2370+
'',
2371+
),
23602372
tuple(
23612373
' ',
23622374
'```txt',
23632375
),
2376+
tuple(
2377+
'',
2378+
'',
2379+
),
23642380
tuple(
23652381
' ',
23662382
'- First Line',
@@ -2377,6 +2393,10 @@
23772393
'',
23782394
'',
23792395
),
2396+
tuple(
2397+
'',
2398+
'',
2399+
),
23802400
tuple(
23812401
'',
23822402
'```yaml',

tests/format/fixtures/text.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,9 +1631,9 @@ Support inline bulleted code (https://github.com/KyleKing/mdformat-mkdocs/issues
16311631
done
16321632
```
16331633

1634-
- ```powershell
1635-
iex (new-object net.webclient).DownloadString('https://get.scoop.sh')
1636-
```
1634+
- ```powershell
1635+
iex (new-object net.webclient).DownloadString('https://get.scoop.sh')
1636+
```
16371637
.
16381638
- ```python
16391639
for idx in range(10):

0 commit comments

Comments
 (0)