From 2ef7b823044742f965ed28f55bb7a52d05bf7c2a Mon Sep 17 00:00:00 2001 From: mrf0rtuna4 Date: Tue, 3 Sep 2024 15:28:08 +0300 Subject: [PATCH] fix(MarkdownProcessor): markdown widgets issue fix --- core/app/markdown_processor.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/app/markdown_processor.py b/core/app/markdown_processor.py index c87f390..1a9e5de 100644 --- a/core/app/markdown_processor.py +++ b/core/app/markdown_processor.py @@ -32,7 +32,8 @@ def __init__(self): self.placeholder_map = { "_BL0CK": [], "_L1NK": [], - "_HTML": [] + "_HTML": [], + "_MD_WDGT": [] } @staticmethod @@ -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") @@ -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