Skip to content

Commit 76ffa61

Browse files
committed
refactor(#49): check before appending an extra line break
1 parent 683b104 commit 76ffa61

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

mdformat_mkdocs/_postprocess_inline.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,21 @@ def postprocess_list_wrap(
6060
indent_length = MKDOCS_INDENT_COUNT * indent_count
6161
wrapped_length = -1 * wrap_mode
6262
words: list[str] = []
63-
for word in text.split(WRAP_POINT):
63+
split = text.split(WRAP_POINT)
64+
for idx, word in enumerate(split):
6465
next_length = wrapped_length + len(word)
6566
if not words:
6667
words = [filler, word]
6768
wrapped_length = indent_length + len(word)
6869
elif next_length > wrap_mode:
69-
words += [word, newline_filler]
70-
wrapped_length = indent_length + len(word)
70+
if idx < len(split) - 1:
71+
words += [word, newline_filler]
72+
wrapped_length = indent_length + len(word)
73+
else:
74+
words.append(word)
75+
wrapped_length = len(word)
7176
else:
7277
words.append(word)
7378
wrapped_length = next_length + 1
74-
if len(words) and words[-1] == FILLER_CHAR:
75-
words.pop()
7679
return WRAP_POINT.join(_w for _w in words if _w)
7780
return f"{filler}{WRAP_POINT}{text}" if filler else text

0 commit comments

Comments
 (0)