Fixed codeblock detection when it doesn't have a language
This commit is contained in:
parent
f5845e95e6
commit
06769aba90
@ -485,7 +485,6 @@ class message(Gtk.Overlay):
|
|||||||
if text:
|
if text:
|
||||||
self.content_children = []
|
self.content_children = []
|
||||||
code_block_pattern = re.compile(r'```(\w*)\n(.*?)\n\s*```', re.DOTALL)
|
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)
|
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**"
|
bold_pattern = re.compile(r'\*\*(.*?)\*\*') #"**text**"
|
||||||
code_pattern = re.compile(r'`([^`\n]*?)`') #"`text`"
|
code_pattern = re.compile(r'`([^`\n]*?)`') #"`text`"
|
||||||
@ -504,15 +503,6 @@ class message(Gtk.Overlay):
|
|||||||
code_text = match.group(2)
|
code_text = match.group(2)
|
||||||
parts.append({"type": "code", "text": code_text, "language": 'python3' if language == 'python' else language})
|
parts.append({"type": "code", "text": code_text, "language": 'python3' if language == 'python' else language})
|
||||||
pos = end
|
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
|
# Tables
|
||||||
for match in table_pattern.finditer(self.text):
|
for match in table_pattern.finditer(self.text):
|
||||||
start, end = match.span()
|
start, end = match.span()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user