fix
Browse files- anycoder_app/parsers.py +32 -7
- anycoder_app/ui.py +7 -2
anycoder_app/parsers.py
CHANGED
|
@@ -333,6 +333,7 @@ def parse_multipage_html_output(text: str) -> Dict[str, str]:
|
|
| 333 |
"""Parse multi-page HTML output formatted as repeated "=== filename ===" sections.
|
| 334 |
|
| 335 |
Returns a mapping of filename → file content. Supports nested paths like assets/css/styles.css.
|
|
|
|
| 336 |
"""
|
| 337 |
if not text:
|
| 338 |
return {}
|
|
@@ -340,13 +341,37 @@ def parse_multipage_html_output(text: str) -> Dict[str, str]:
|
|
| 340 |
cleaned = remove_code_block(text)
|
| 341 |
files: Dict[str, str] = {}
|
| 342 |
import re as _re
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
#
|
| 348 |
-
|
| 349 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
return files
|
| 351 |
|
| 352 |
def format_multipage_output(files: Dict[str, str]) -> str:
|
|
|
|
| 333 |
"""Parse multi-page HTML output formatted as repeated "=== filename ===" sections.
|
| 334 |
|
| 335 |
Returns a mapping of filename → file content. Supports nested paths like assets/css/styles.css.
|
| 336 |
+
If HTML content appears before the first === marker, it's treated as index.html.
|
| 337 |
"""
|
| 338 |
if not text:
|
| 339 |
return {}
|
|
|
|
| 341 |
cleaned = remove_code_block(text)
|
| 342 |
files: Dict[str, str] = {}
|
| 343 |
import re as _re
|
| 344 |
+
|
| 345 |
+
# Check if there's content before the first === marker
|
| 346 |
+
first_marker_match = _re.search(r"^===\s*([^=\n]+?)\s*===", cleaned, _re.MULTILINE)
|
| 347 |
+
if first_marker_match:
|
| 348 |
+
# There's content before the first marker
|
| 349 |
+
first_marker_pos = first_marker_match.start()
|
| 350 |
+
if first_marker_pos > 0:
|
| 351 |
+
leading_content = cleaned[:first_marker_pos].strip()
|
| 352 |
+
# Check if it looks like HTML content
|
| 353 |
+
if leading_content and ('<!DOCTYPE' in leading_content or '<html' in leading_content or leading_content.startswith('<')):
|
| 354 |
+
files['index.html'] = leading_content
|
| 355 |
+
|
| 356 |
+
# Now parse the rest with === markers
|
| 357 |
+
remaining_text = cleaned[first_marker_pos:] if first_marker_pos > 0 else cleaned
|
| 358 |
+
pattern = _re.compile(r"^===\s*([^=\n]+?)\s*===\s*\n([\s\S]*?)(?=\n===\s*[^=\n]+?\s*===|\Z)", _re.MULTILINE)
|
| 359 |
+
for m in pattern.finditer(remaining_text):
|
| 360 |
+
name = m.group(1).strip()
|
| 361 |
+
content = m.group(2).strip()
|
| 362 |
+
# Remove accidental trailing fences if present
|
| 363 |
+
content = _re.sub(r"^```\w*\s*\n|\n```\s*$", "", content)
|
| 364 |
+
files[name] = content
|
| 365 |
+
else:
|
| 366 |
+
# No === markers found, try standard pattern matching
|
| 367 |
+
pattern = _re.compile(r"^===\s*([^=\n]+?)\s*===\s*\n([\s\S]*?)(?=\n===\s*[^=\n]+?\s*===|\Z)", _re.MULTILINE)
|
| 368 |
+
for m in pattern.finditer(cleaned):
|
| 369 |
+
name = m.group(1).strip()
|
| 370 |
+
content = m.group(2).strip()
|
| 371 |
+
# Remove accidental trailing fences if present
|
| 372 |
+
content = _re.sub(r"^```\w*\s*\n|\n```\s*$", "", content)
|
| 373 |
+
files[name] = content
|
| 374 |
+
|
| 375 |
return files
|
| 376 |
|
| 377 |
def format_multipage_output(files: Dict[str, str]) -> str:
|
anycoder_app/ui.py
CHANGED
|
@@ -1375,14 +1375,19 @@ with gr.Blocks(
|
|
| 1375 |
|
| 1376 |
# Detect whether the HTML output is multi-file (=== filename === blocks)
|
| 1377 |
files = {}
|
|
|
|
| 1378 |
try:
|
| 1379 |
files = parse_multipage_html_output(code)
|
|
|
|
| 1380 |
files = validate_and_autofix_files(files)
|
| 1381 |
-
|
|
|
|
|
|
|
|
|
|
| 1382 |
files = {}
|
| 1383 |
|
| 1384 |
# If we have multiple files (or at least a parsed index.html), upload the whole folder
|
| 1385 |
-
if isinstance(files, dict) and files.get('index.html'):
|
| 1386 |
import tempfile
|
| 1387 |
import os
|
| 1388 |
|
|
|
|
| 1375 |
|
| 1376 |
# Detect whether the HTML output is multi-file (=== filename === blocks)
|
| 1377 |
files = {}
|
| 1378 |
+
parse_error = None
|
| 1379 |
try:
|
| 1380 |
files = parse_multipage_html_output(code)
|
| 1381 |
+
print(f"[Deploy] Parsed files: {list(files.keys())}")
|
| 1382 |
files = validate_and_autofix_files(files)
|
| 1383 |
+
print(f"[Deploy] After validation: {list(files.keys())}")
|
| 1384 |
+
except Exception as e:
|
| 1385 |
+
parse_error = str(e)
|
| 1386 |
+
print(f"[Deploy] Parse error: {parse_error}")
|
| 1387 |
files = {}
|
| 1388 |
|
| 1389 |
# If we have multiple files (or at least a parsed index.html), upload the whole folder
|
| 1390 |
+
if isinstance(files, dict) and len(files) > 0 and files.get('index.html'):
|
| 1391 |
import tempfile
|
| 1392 |
import os
|
| 1393 |
|