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

Useless re.sub in format_markdown? #132

Open
99991 opened this issue Jan 8, 2025 · 0 comments
Open

Useless re.sub in format_markdown? #132

99991 opened this issue Jan 8, 2025 · 0 comments

Comments

@99991
Copy link

99991 commented Jan 8, 2025

Is the second re.sub in format_markdown doing anything useful?

def format_markdown(text: str) -> str:
"""Format markdown text by removing markdown and code blocks"""
formatted_markdown = re.sub(Patterns.MATCH_MARKDOWN_BLOCKS, r"\1", text)
formatted_markdown = re.sub(Patterns.MATCH_CODE_BLOCKS, r"\1", formatted_markdown)

MATCH_MARKDOWN_BLOCKS = r"^```[a-z]*\n([\s\S]*?)\n```$"
MATCH_CODE_BLOCKS = r"^```\n([\s\S]*?)\n```$"

MATCH_MARKDOWN_BLOCKS matches any markdown blocks with an optional language specifier after the first three backticks, while MATCH_CODE_BLOCKS only matches markdown blocks without language specifier, so the later should allready be included in the former, or am I missing something?

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