Skip to content

Commit

Permalink
Fix consecutive wrap_points
Browse files Browse the repository at this point in the history
  • Loading branch information
hukkin committed Nov 13, 2024
1 parent 9cea27f commit 67abc56
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/mdformat/renderer/_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
RE_PRESERVE_CHAR = re.compile(re.escape(PRESERVE_CHAR))

RE_UNICODE_WS_OR_WRAP_POINT = re.compile(
rf"[{re.escape(''.join(codepoints.UNICODE_WHITESPACE))}{re.escape(WRAP_POINT)}]"
rf"[{re.escape(''.join(codepoints.UNICODE_WHITESPACE))}]"
"|"
rf"{re.escape(WRAP_POINT)}+"
)


Expand Down Expand Up @@ -364,11 +366,10 @@ def _prepare_wrap(text: str) -> tuple[str, list[str]]:
replacements = []

def replacer(match: re.Match[str]) -> str:
c = match.group()
i = match.start()
if c == WRAP_POINT:
return " " if i == 0 or text[i - 1] != " " else ""
replacements.append(c)
first_char = match.group()[0]
if first_char == WRAP_POINT:
return " "
replacements.append(first_char)
return PRESERVE_CHAR

result = RE_UNICODE_WS_OR_WRAP_POINT.sub(replacer, text)
Expand Down

0 comments on commit 67abc56

Please sign in to comment.