Skip to content

Commit 7f042a9

Browse files
committed
Much better markup rendering
1 parent ff5e663 commit 7f042a9

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/custom_widgets/message_widget.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -537,16 +537,11 @@ def set_text(self, text:str=None):
537537
code_block_pattern = re.compile(r'```(\w*)\n(.*?)\n\s*```', re.DOTALL)
538538
no_language_code_block_pattern = re.compile(r'`(\w*)\n(.*?)\n\s*`', re.DOTALL)
539539
table_pattern = re.compile(r'((\r?\n){2}|^)([^\r\n]*\|[^\r\n]*(\r?\n)?)+(?=(\r?\n){2}|$)', re.MULTILINE)
540-
bold_pattern = re.compile(r'\*\*(.*?)\*\*') #"**text**"
541-
code_pattern = re.compile(r'`([^`\n]*?)`') #"`text`"
542-
h1_pattern = re.compile(r'^#\s(.*)$') #"# text"
543-
h2_pattern = re.compile(r'^##\s(.*)$') #"## text"
544540
markup_pattern = re.compile(r'<(b|u|tt|span.*)>(.*?)<\/(b|u|tt|span)>') #heh butt span, I'm so funny
545541
parts = []
546542
pos = 0
547543
# Code blocks
548544
for match in code_block_pattern.finditer(self.text[pos:]):
549-
print(match)
550545
start, end = match.span()
551546
if pos < start:
552547
normal_text = self.text[pos:start]
@@ -583,10 +578,12 @@ def set_text(self, text:str=None):
583578
if part['type'] == 'normal':
584579
text_b = text_block(self.bot)
585580
part['text'] = part['text'].replace("\n* ", "\n• ")
586-
part['text'] = code_pattern.sub(r'<tt>\1</tt>', part['text'])
587-
part['text'] = bold_pattern.sub(r'<b>\1</b>', part['text'])
588-
part['text'] = h1_pattern.sub(r'<span size="x-large">\1</span>', part['text'])
589-
part['text'] = h2_pattern.sub(r'<span size="large">\1</span>', part['text'])
581+
part['text'] = re.sub(r'`([^`\n]*?)`', r'<tt>\1</tt>', part['text'])
582+
part['text'] = re.sub(r'\*\*(.*?)\*\*', r'<b>\1</b>', part['text'], flags=re.MULTILINE)
583+
part['text'] = re.sub(r'^#\s+(.*)', r'<span size="x-large">\1</span>', part['text'], flags=re.MULTILINE)
584+
part['text'] = re.sub(r'^##\s+(.*)', r'<span size="large">\1</span>', part['text'], flags=re.MULTILINE)
585+
part['text'] = re.sub(r'_(\((.*?)\)|\d+)', r'<sub>\2\1</sub>', part['text'], flags=re.MULTILINE)
586+
part['text'] = re.sub(r'\^(\((.*?)\)|\d+)', r'<sup>\2\1</sup>', part['text'], flags=re.MULTILINE)
590587
pos = 0
591588
for match in markup_pattern.finditer(part['text']):
592589
start, end = match.span()

0 commit comments

Comments
 (0)