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

Improve convert_openai_markdown_to_slack code #50

Open
kelyacf opened this issue May 21, 2024 · 0 comments
Open

Improve convert_openai_markdown_to_slack code #50

kelyacf opened this issue May 21, 2024 · 0 comments

Comments

@kelyacf
Copy link
Collaborator

kelyacf commented May 21, 2024

as a example (from chat GPT)

import re

def convert_markdown_to_mrkdwn(markdown_text):
# Convert headers
markdown_text = re.sub(r'(^|\n)### (.)', r'\1 \2*\n', markdown_text)
markdown_text = re.sub(r'(^|\n)## (.)', r'\1** \2**\n', markdown_text)
markdown_text = re.sub(r'(^|\n)# (.
)', r'\1*** \2***\n', markdown_text)

# Convert bold and italic text
markdown_text = re.sub(r'\*\*\*(.*?)\*\*\*', r'*\1*', markdown_text)
markdown_text = re.sub(r'\*\*(.*?)\*\*', r'*\1*', markdown_text)
markdown_text = re.sub(r'\*(.*?)\*', r'_\1_', markdown_text)

# Convert links
markdown_text = re.sub(r'\[(.*?)\]\((.*?)\)', r'<\2|\1>', markdown_text)

# Convert inline code
markdown_text = re.sub(r'`(.*?)`', r'`\1`', markdown_text)

# Convert code blocks
markdown_text = re.sub(r'```(.*?)```', r'```\1```', markdown_text, flags=re.DOTALL)

return markdown_text

Example usage

markdown_text = """

Header 1

Header 2

Header 3

Bold text

Italic text

Bold and Italic text

Link

Inline code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant