Skip to content

Commit 9d4242a

Browse files
committed
Revert "refactor: attempt to preserve soft breaks around mdformat"
This reverts commit ffb6f4b.
1 parent ffb6f4b commit 9d4242a

File tree

1 file changed

+5
-39
lines changed

1 file changed

+5
-39
lines changed

mdformat_mkdocs/_postprocess_inline.py

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import annotations
44

5-
import re
65
from typing import TYPE_CHECKING
76

87
from ._helpers import FILLER_CHAR, MKDOCS_INDENT_COUNT, get_conf, rstrip_result
@@ -13,32 +12,6 @@
1312
FILLER = FILLER_CHAR * (MKDOCS_INDENT_COUNT - 2) # `mdformat` default is two spaces
1413
"""A spacer that is inserted and then removed to ensure proper word wrap."""
1514

16-
# Pattern to match HTML entities like  
17-
_HTML_ENTITY_PATTERN = re.compile(r"&[a-zA-Z]+;")
18-
19-
20-
def _preserve_html_entities(text: str) -> tuple[str, list[tuple[str, str]]]:
21-
"""Replace HTML entities with placeholders and return a list of replacements."""
22-
replacements = []
23-
counter = 0
24-
25-
def replace_entity(match: re.Match) -> str:
26-
nonlocal counter
27-
placeholder = f"__HTML_ENTITY_{counter}__"
28-
counter += 1
29-
replacements.append((placeholder, match.group(0)))
30-
return placeholder
31-
32-
text = _HTML_ENTITY_PATTERN.sub(replace_entity, text)
33-
return text, replacements
34-
35-
36-
def _restore_html_entities(text: str, replacements: list[tuple[str, str]]) -> str:
37-
"""Restore HTML entities from their placeholders."""
38-
for placeholder, entity in replacements:
39-
text = text.replace(placeholder, entity)
40-
return text
41-
4215

4316
@rstrip_result
4417
def postprocess_list_wrap(
@@ -71,9 +44,6 @@ def postprocess_list_wrap(
7144
):
7245
return text
7346

74-
# Preserve HTML entities before wrapping
75-
text_with_placeholders, replacements = _preserve_html_entities(text)
76-
7747
counter_ = -1
7848
parent = node.parent
7949
while parent and parent.type == "paragraph":
@@ -82,14 +52,14 @@ def postprocess_list_wrap(
8252
indent_count = max(counter_, 0)
8353

8454
soft_break = "\x00"
85-
text_with_placeholders = text_with_placeholders.lstrip(soft_break).lstrip()
55+
text = text.lstrip(soft_break).lstrip()
8656
filler = (FILLER * indent_count)[:-1] if indent_count else ""
8757
newline_filler = filler + FILLER if indent_count else FILLER[:-1]
88-
if len(text_with_placeholders) > wrap_mode:
58+
if len(text) > wrap_mode:
8959
indent_length = MKDOCS_INDENT_COUNT * indent_count
9060
wrapped_length = -123
9161
words: list[str] = []
92-
for word in text_with_placeholders.split(soft_break):
62+
for word in text.split(soft_break):
9363
next_length = wrapped_length + len(word)
9464
if not words:
9565
words = [filler, word]
@@ -100,9 +70,5 @@ def postprocess_list_wrap(
10070
else:
10171
words.append(word)
10272
wrapped_length = next_length + 1
103-
text_with_placeholders = soft_break.join(_w for _w in words if _w)
104-
else:
105-
text_with_placeholders = f"{filler}{soft_break}{text_with_placeholders}" if filler else text_with_placeholders
106-
107-
# Restore HTML entities after wrapping
108-
return _restore_html_entities(text_with_placeholders, replacements)
73+
return soft_break.join(_w for _w in words if _w)
74+
return f"{filler}{soft_break}{text}" if filler else text

0 commit comments

Comments
 (0)