This commit is contained in:
Timothy Jaeryang Baek
2026-03-17 17:58:01 -05:00
parent fcf7208352
commit de3317e26b
220 changed files with 17200 additions and 22836 deletions
+4 -6
View File
@@ -2,9 +2,7 @@ import re
# ANSI escape code pattern - matches all common ANSI sequences
# This includes color codes, cursor movement, and other terminal control sequences
ANSI_ESCAPE_PATTERN = re.compile(
r"\x1b\[[0-9;]*[A-Za-z]|\x1b\([AB]|\x1b[PX^_].*?\x1b\\|\x1b\].*?(?:\x07|\x1b\\)"
)
ANSI_ESCAPE_PATTERN = re.compile(r'\x1b\[[0-9;]*[A-Za-z]|\x1b\([AB]|\x1b[PX^_].*?\x1b\\|\x1b\].*?(?:\x07|\x1b\\)')
def strip_ansi_codes(text: str) -> str:
@@ -20,7 +18,7 @@ def strip_ansi_codes(text: str) -> str:
- Reset codes: \x1b[0m, \x1b[39m
- Cursor movement: \x1b[1A, \x1b[2J, etc.
"""
return ANSI_ESCAPE_PATTERN.sub("", text)
return ANSI_ESCAPE_PATTERN.sub('', text)
def strip_markdown_code_fences(code: str) -> str:
@@ -37,9 +35,9 @@ def strip_markdown_code_fences(code: str) -> str:
"""
code = code.strip()
# Remove opening fence (```python, ```py, ``` etc.)
code = re.sub(r"^```\w*\n?", "", code)
code = re.sub(r'^```\w*\n?', '', code)
# Remove closing fence
code = re.sub(r"\n?```\s*$", "", code)
code = re.sub(r'\n?```\s*$', '', code)
return code.strip()