Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files628 unmodified lines6296306316326336346354 unmodified lines640641642643644645646647648649650651652653654655656657658659628 unmodified linesdef _sanitize_code_tags(text: str) -> str:import reif re.search(r"<code>.*?</code>", text, flags=re.DOTALL | re.IGNORECASE):def _clean_html_block(match):inner = match.group(1)inner = re.sub(r"```(?:py|python)?\s*\n?", "", inner, flags=re.IGNORECASE)4 unmodified linesreturn re.sub(r"<code>(.*?)</code>",_clean_html_block,text,flags=re.DOTALL | re.IGNORECASE,)def _clean_md_block(match):inner = re.sub(r"</?code[^>]*>", "", match.group(1), flags=re.IGNORECASE)return f"```py\n{inner.strip()}\n```"return re.sub(r"```(?:py|python)?\s*\n(.*?)```",_clean_md_block,text,flags=re.DOTALL | re.IGNORECASE,)@classmethoddef _validate_message(cls, msg):628 unmodified lines6296306316326336346356366376384 unmodified lines643644645646647648649650651652653654655656657658659660661662663628 unmodified linesdef _sanitize_code_tags(text: str) -> str:import recleaned_text = re.sub(r"</?code[^>]*>\s*```", "```", text, flags=re.IGNORECASE)cleaned_text = re.sub(r"```\s*</?code[^>]*>", "```", cleaned_text, flags=re.IGNORECASE)if re.search(r"<code>.*?</code>", cleaned_text, flags=re.DOTALL | re.IGNORECASE):def _clean_html_block(match):inner = match.group(1)inner = re.sub(r"```(?:py|python)?\s*\n?", "", inner, flags=re.IGNORECASE)4 unmodified linesreturn re.sub(r"<code>(.*?)</code>",_clean_html_block,cleaned_text,flags=re.DOTALL | re.IGNORECASE,)md_match = re.search(r"```(?:py|python)?\s*\n(.*?)```",cleaned_text,flags=re.DOTALL | re.IGNORECASE,)if md_match:inner = re.sub(r"</?code[^>]*>", "", md_match.group(1), flags=re.IGNORECASE).strip()prefix = cleaned_text[: md_match.start()].strip()return f"{prefix}\n<code>\n{inner}\n</code>" if prefix else f"<code>\n{inner}\n</code>"return cleaned_text@classmethoddef _validate_message(cls, msg):
app.py+13-9