use a proper markdown parser
This commit is contained in:
parent
30688bf5b0
commit
d864b0cc44
3 changed files with 4 additions and 17 deletions
|
@ -1,4 +1,5 @@
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from misc import dict_cls
|
from misc import dict_cls
|
||||||
|
|
||||||
CDN_URL = "https://cdn.discordapp.com"
|
CDN_URL = "https://cdn.discordapp.com"
|
||||||
|
|
|
@ -7,6 +7,7 @@ import sys
|
||||||
import threading
|
import threading
|
||||||
from typing import Dict, List, Tuple
|
from typing import Dict, List, Tuple
|
||||||
|
|
||||||
|
import markdown
|
||||||
import urllib3
|
import urllib3
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
@ -281,23 +282,7 @@ In reply to</a><a href="https://matrix.to/#/{event.sender}">\
|
||||||
return content
|
return content
|
||||||
|
|
||||||
def get_fmt(self, message: str, emotes: dict) -> str:
|
def get_fmt(self, message: str, emotes: dict) -> str:
|
||||||
replace = [
|
message = markdown.markdown(message)
|
||||||
# Bold.
|
|
||||||
("**", "<strong>", "</strong>"),
|
|
||||||
# Code blocks.
|
|
||||||
("```", "<pre><code>", "</code></pre>"),
|
|
||||||
# Spoilers.
|
|
||||||
("||", "<span data-mx-spoiler>", "</span>"),
|
|
||||||
# Strikethrough.
|
|
||||||
("~~", "<del>", "</del>"),
|
|
||||||
]
|
|
||||||
|
|
||||||
for replace_ in replace:
|
|
||||||
for i in range(1, message.count(replace_[0]) + 1):
|
|
||||||
if i % 2:
|
|
||||||
message = message.replace(replace_[0], replace_[1], 1)
|
|
||||||
else:
|
|
||||||
message = message.replace(replace_[0], replace_[2], 1)
|
|
||||||
|
|
||||||
# Upload emotes in multiple threads so that we don't
|
# Upload emotes in multiple threads so that we don't
|
||||||
# block the Discord bot for too long.
|
# block the Discord bot for too long.
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
bottle
|
bottle
|
||||||
|
markdown
|
||||||
urllib3
|
urllib3
|
||||||
websockets
|
websockets
|
||||||
|
|
Loading…
Reference in a new issue