Skip to content

Commit

Permalink
Merge pull request #198 from ConnectAI-E/fix-0202
Browse files Browse the repository at this point in the history
Fix github not support html img
  • Loading branch information
lloydzhou authored Feb 2, 2024
2 parents 4fab4ca + 755522d commit 4c9b44c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions server/tasks/lark/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,31 @@ def gen_issue_card_by_issue(bot, issue, repo_url, team, maunal=False):
def replace_images_with_keys(text, bot):
"""
replace image URL to image_key.
![](url) to ![](image_key)
Markdown: ![](url) -> ![](image_key)
HTML: <img src="url"> -> ![](image_key)
Args:
text (str): original text
bot: bot instance
Returns:
str: replaced text
"""
pattern = r"!\[.*?\]\((.*?)\)"
# Replace Markdown image syntax
markdown_pattern = r"!\[.*?\]\((.*?)\)"
replaced_text = re.sub(
pattern,
markdown_pattern,
lambda match: f"![]({upload_image(match.group(1), bot)})",
text,
)

# Replace HTML image syntax
html_pattern = r"<img.*?src=\"(.*?)\".*?>"
replaced_text = re.sub(
html_pattern,
lambda match: f"![]({upload_image(match.group(1), bot)})",
replaced_text,
)

return replaced_text.replace("![]()", "(请确认图片是否上传成功)")


Expand Down

0 comments on commit 4c9b44c

Please sign in to comment.