Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix github not support html img #198

Merged
merged 4 commits into from
Feb 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading