Spaces:
Running
Running
update
Browse files
app.py
CHANGED
|
@@ -312,6 +312,9 @@ def remove_code_block(text):
|
|
| 312 |
match = re.search(pattern, text, re.DOTALL)
|
| 313 |
if match:
|
| 314 |
extracted = match.group(1).strip()
|
|
|
|
|
|
|
|
|
|
| 315 |
return extracted
|
| 316 |
# If no code block is found, check if the entire text is HTML
|
| 317 |
if text.strip().startswith('<!DOCTYPE html>') or text.strip().startswith('<html') or text.strip().startswith('<'):
|
|
@@ -319,6 +322,10 @@ def remove_code_block(text):
|
|
| 319 |
# Special handling for python: remove python marker
|
| 320 |
if text.strip().startswith('```python'):
|
| 321 |
return text.strip()[9:-3].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
return text.strip()
|
| 323 |
|
| 324 |
def history_render(history: History):
|
|
|
|
| 312 |
match = re.search(pattern, text, re.DOTALL)
|
| 313 |
if match:
|
| 314 |
extracted = match.group(1).strip()
|
| 315 |
+
# Remove a leading language marker line (e.g., 'python') if present
|
| 316 |
+
if extracted.split('\n', 1)[0].strip().lower() in ['python', 'html', 'css', 'javascript', 'json', 'c', 'cpp', 'markdown', 'latex', 'jinja2', 'typescript', 'yaml', 'dockerfile', 'shell', 'r', 'sql', 'sql-mssql', 'sql-mysql', 'sql-mariadb', 'sql-sqlite', 'sql-cassandra', 'sql-plsql', 'sql-hive', 'sql-pgsql', 'sql-gql', 'sql-gpsql', 'sql-sparksql', 'sql-esper']:
|
| 317 |
+
return extracted.split('\n', 1)[1] if '\n' in extracted else ''
|
| 318 |
return extracted
|
| 319 |
# If no code block is found, check if the entire text is HTML
|
| 320 |
if text.strip().startswith('<!DOCTYPE html>') or text.strip().startswith('<html') or text.strip().startswith('<'):
|
|
|
|
| 322 |
# Special handling for python: remove python marker
|
| 323 |
if text.strip().startswith('```python'):
|
| 324 |
return text.strip()[9:-3].strip()
|
| 325 |
+
# Remove a leading language marker line if present (fallback)
|
| 326 |
+
lines = text.strip().split('\n', 1)
|
| 327 |
+
if lines[0].strip().lower() in ['python', 'html', 'css', 'javascript', 'json', 'c', 'cpp', 'markdown', 'latex', 'jinja2', 'typescript', 'yaml', 'dockerfile', 'shell', 'r', 'sql', 'sql-mssql', 'sql-mysql', 'sql-mariadb', 'sql-sqlite', 'sql-cassandra', 'sql-plsql', 'sql-hive', 'sql-pgsql', 'sql-gql', 'sql-gpsql', 'sql-sparksql', 'sql-esper']:
|
| 328 |
+
return lines[1] if len(lines) > 1 else ''
|
| 329 |
return text.strip()
|
| 330 |
|
| 331 |
def history_render(history: History):
|