Skip to content

Commit

Permalink
fix(MarkdownProcessor): markdown widgets issue fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mrf0rtuna4 committed Sep 3, 2024
1 parent aacdc9a commit 2ef7b82
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/app/markdown_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def __init__(self):
self.placeholder_map = {
"_BL0CK": [],
"_L1NK": [],
"_HTML": []
"_HTML": [],
"_MD_WDGT": []
}

@staticmethod
Expand All @@ -53,6 +54,13 @@ def _sanitize_placeholders(self, text):
(unique_placeholder, code_block))
text = text.replace(code_block, unique_placeholder, 1)

markdown_widgets = re.findall(r"!\[[^\]]*\]\([^\)]+\)", text)
for widget in markdown_widgets:
unique_placeholder = self._generate_placeholder("_MD_WDGT")
self.placeholder_map["_MD_WDGT"].append(
(unique_placeholder, widget))
text = text.replace(widget, unique_placeholder, 1)

links = re.findall(r"\[([^]]+)]\(([^)]+)\)", text)
for link in links:
unique_placeholder = self._generate_placeholder("_L1NK")
Expand All @@ -78,6 +86,8 @@ def _restore_placeholders(self, text):
for unique_placeholder, original in mappings:
if placeholder_type == "_L1NK":
original = f"[{original[0]}]({original[1]})"
elif placeholder_type == "_MD_WDGT":
original = original
text = text.replace(unique_placeholder, original, 1)
return text

Expand Down

0 comments on commit 2ef7b82

Please sign in to comment.