refac
This commit is contained in:
1 parent
c5c4aef7b1
commit
4a55167759
2 files changed
+167
-86
No files matched your search
@@ -0,0 +1,21 @@
|
||||
import re
|
||||
|
||||
|
||||
def strip_markdown_code_fences(code: str) -> str:
|
||||
"""
|
||||
Strip markdown code fences if present.
|
||||
|
||||
This is a defensive, non-breaking change — if the code doesn't
|
||||
contain fences, it passes through unchanged.
|
||||
|
||||
Handles patterns like:
|
||||
- ```python
|
||||
- ```py
|
||||
- ```
|
||||
"""
|
||||
code = code.strip()
|
||||
# Remove opening fence (```python, ```py, ``` etc.)
|
||||
code = re.sub(r"^```\w*\n?", "", code)
|
||||
# Remove closing fence
|
||||
code = re.sub(r"\n?```\s*$", "", code)
|
||||
return code.strip()
|
||||
Reference in new issue
Block a user