53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
|
|
import re
|
||
|
|
|
||
|
|
EMOJI_MAP = {
|
||
|
|
":smile:": "😀",
|
||
|
|
":laughing:": "😆",
|
||
|
|
":blush:": "😊",
|
||
|
|
":heart:": "❤️",
|
||
|
|
":thumbsup:": "👍",
|
||
|
|
":thumbsdown:": "👎",
|
||
|
|
":clap:": "👏",
|
||
|
|
":fire:": "🔥",
|
||
|
|
":rocket:": "🚀",
|
||
|
|
":check:": "✅",
|
||
|
|
":x:": "❌",
|
||
|
|
":warning:": "⚠️",
|
||
|
|
":bulb:": "💡",
|
||
|
|
":pushpin:": "📌",
|
||
|
|
":link:": "🔗",
|
||
|
|
":star:": "⭐",
|
||
|
|
":tada:": "🎉",
|
||
|
|
":thinking:": "🤔",
|
||
|
|
":eyes:": "👀",
|
||
|
|
":pray:": "🙏",
|
||
|
|
":100:": "💯",
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
def convert_emoji_shortcodes(text: str) -> str:
|
||
|
|
result = text
|
||
|
|
for shortcode, unicode_char in EMOJI_MAP.items():
|
||
|
|
result = result.replace(shortcode, unicode_char)
|
||
|
|
return result
|
||
|
|
|
||
|
|
|
||
|
|
def sanitize_for_clickup(text: str) -> str:
|
||
|
|
text = convert_emoji_shortcodes(text)
|
||
|
|
if len(text) > 40000:
|
||
|
|
text = text[:39997] + "..."
|
||
|
|
return text
|
||
|
|
|
||
|
|
|
||
|
|
def extract_plain_text(markdown_text: str) -> str:
|
||
|
|
text = markdown_text
|
||
|
|
text = re.sub(r"~~(.*?)~~", r"\1", text)
|
||
|
|
text = re.sub(r"\*\*(.*?)\*\*", r"\1", text)
|
||
|
|
text = re.sub(r"\*(.*?)\*", r"\1", text)
|
||
|
|
text = re.sub(r"`{1,3}[^`]*`{1,3}", "", text)
|
||
|
|
text = re.sub(r"\[([^\]]+)\]\([^\)]+\)", r"\1", text)
|
||
|
|
text = re.sub(r">\s?", "", text)
|
||
|
|
text = re.sub(r"[-*]\s", "", text)
|
||
|
|
text = re.sub(r"\d+\.\s", "", text)
|
||
|
|
return text.strip()
|