23 lines
560 B
Python
23 lines
560 B
Python
|
|
import re
|
||
|
|
|
||
|
|
|
||
|
|
def markdown_to_native(md_text: str) -> str:
|
||
|
|
text = md_text
|
||
|
|
|
||
|
|
text = re.sub(r"!\[[^\]]*\]\([^)]*\)", "", text)
|
||
|
|
|
||
|
|
text = re.sub(r"^#{1,6}\s+(.+)$", r"*\1*", text, flags=re.MULTILINE)
|
||
|
|
|
||
|
|
text = re.sub(r"\[([^\]]+)\]\(([^)]+)\)", r"\1 (\2)", text)
|
||
|
|
|
||
|
|
return text.strip()
|
||
|
|
|
||
|
|
|
||
|
|
def native_to_markdown(native_content: dict | str) -> str:
|
||
|
|
if isinstance(native_content, dict):
|
||
|
|
return native_content.get("text", "")
|
||
|
|
return str(native_content)
|
||
|
|
|
||
|
|
|
||
|
|
def markdown_to_whatsapp(md_text: str) -> str:
|
||
|
|
return markdown_to_native(md_text)
|