Fixed codeblock detection when it doesn't have a language

This commit is contained in:
jeffser 2024-10-06 22:21:42 -06:00
parent f5845e95e6
commit 06769aba90

View File

@ -485,7 +485,6 @@ class message(Gtk.Overlay):
if text:
self.content_children = []
code_block_pattern = re.compile(r'```(\w*)\n(.*?)\n\s*```', re.DOTALL)
no_lang_code_block_pattern = re.compile(r'`\n(.*?)\n`', re.DOTALL)
table_pattern = re.compile(r'((\r?\n){2}|^)([^\r\n]*\|[^\r\n]*(\r?\n)?)+(?=(\r?\n){2}|$)', re.MULTILINE)
bold_pattern = re.compile(r'\*\*(.*?)\*\*') #"**text**"
code_pattern = re.compile(r'`([^`\n]*?)`') #"`text`"
@ -504,15 +503,6 @@ class message(Gtk.Overlay):
code_text = match.group(2)
parts.append({"type": "code", "text": code_text, "language": 'python3' if language == 'python' else language})
pos = end
# Code blocks (No language)
for match in no_lang_code_block_pattern.finditer(self.text):
start, end = match.span()
if pos < start:
normal_text = self.text[pos:start]
parts.append({"type": "normal", "text": normal_text.strip()})
code_text = match.group(1)
parts.append({"type": "code", "text": code_text, "language": None})
pos = end
# Tables
for match in table_pattern.finditer(self.text):
start, end = match.span()