Skip to content

Commit

Permalink
perf: slack消息解析优化-mistune升级
Browse files Browse the repository at this point in the history
  • Loading branch information
O-Jiangweidong authored and BaiJiangJie committed Jan 8, 2024
1 parent 9ede367 commit b4c1dd2
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions apps/common/sdk/im/slack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ class URL:
AUTH_TEST = 'https://slack.com/api/auth.test'


class SlackRenderer(mistune.Renderer):
def header(self, text, level, raw=None):
class SlackRenderer(mistune.renderers.HTMLRenderer):
def heading(self, text, level):
return '*' + text + '*\n'

def double_emphasis(self, text):
def strong(self, text):
return '*' + text + '*'

def list(self, body, ordered=True):
lines = body.split('\n')
def list(self, text, **kwargs):
lines = text.split('\n')
for i, line in enumerate(lines):
if not line:
continue
Expand All @@ -41,9 +41,9 @@ def list(self, body, ordered=True):
def block_code(self, code, lang=None):
return f'`{code}`'

def link(self, link, title, content):
if title or content:
label = str(title or content).strip()
def link(self, link, text=None, title=None):
if title or text:
label = str(title or text).strip()
return f'<{link}|{label}>'
return f'<{link}>'

Expand Down

0 comments on commit b4c1dd2

Please sign in to comment.