fix
Browse filesFiles changed (2)
332 unmodified lines3333343353363373381 unmodified line340341342343344345346347348349350351352332 unmodified lines"""Parse multi-page HTML output formatted as repeated "=== filename ===" sections.Returns a mapping of filename → file content. Supports nested paths like assets/css/styles.css."""if not text:return {}1 unmodified linecleaned = remove_code_block(text)files: Dict[str, str] = {}import re as _repattern = _re.compile(r"^===\s*([^=\n]+?)\s*===\s*\n([\s\S]*?)(?=\n===\s*[^=\n]+?\s*===|\Z)", _re.MULTILINE)for m in pattern.finditer(cleaned):name = m.group(1).strip()content = m.group(2).strip()# Remove accidental trailing fences if presentcontent = _re.sub(r"^```\w*\s*\n|\n```\s*$", "", content)files[name] = contentreturn filesdef format_multipage_output(files: Dict[str, str]) -> str:332 unmodified lines3333343353363373383391 unmodified line341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377332 unmodified lines"""Parse multi-page HTML output formatted as repeated "=== filename ===" sections.Returns a mapping of filename → file content. Supports nested paths like assets/css/styles.css.If HTML content appears before the first === marker, it's treated as index.html."""if not text:return {}1 unmodified linecleaned = remove_code_block(text)files: Dict[str, str] = {}import re as _re# Check if there's content before the first === markerfirst_marker_match = _re.search(r"^===\s*([^=\n]+?)\s*===", cleaned, _re.MULTILINE)if first_marker_match:# There's content before the first markerfirst_marker_pos = first_marker_match.start()if first_marker_pos > 0:leading_content = cleaned[:first_marker_pos].strip()# Check if it looks like HTML contentif leading_content and ('<!DOCTYPE' in leading_content or '<html' in leading_content or leading_content.startswith('<')):files['index.html'] = leading_content# Now parse the rest with === markersremaining_text = cleaned[first_marker_pos:] if first_marker_pos > 0 else cleanedpattern = _re.compile(r"^===\s*([^=\n]+?)\s*===\s*\n([\s\S]*?)(?=\n===\s*[^=\n]+?\s*===|\Z)", _re.MULTILINE)for m in pattern.finditer(remaining_text):name = m.group(1).strip()content = m.group(2).strip()# Remove accidental trailing fences if presentcontent = _re.sub(r"^```\w*\s*\n|\n```\s*$", "", content)files[name] = contentelse:# No === markers found, try standard pattern matchingpattern = _re.compile(r"^===\s*([^=\n]+?)\s*===\s*\n([\s\S]*?)(?=\n===\s*[^=\n]+?\s*===|\Z)", _re.MULTILINE)for m in pattern.finditer(cleaned):name = m.group(1).strip()content = m.group(2).strip()# Remove accidental trailing fences if presentcontent = _re.sub(r"^```\w*\s*\n|\n```\s*$", "", content)files[name] = contentreturn filesdef format_multipage_output(files: Dict[str, str]) -> str:
1374 unmodified lines137513761377137813791380138113821383138413851386138713881374 unmodified lines# Detect whether the HTML output is multi-file (=== filename === blocks)files = {}try:files = parse_multipage_html_output(code)files = validate_and_autofix_files(files)except Exception:files = {}# If we have multiple files (or at least a parsed index.html), upload the whole folderif isinstance(files, dict) and files.get('index.html'):import tempfileimport os1374 unmodified lines13751376137713781379138013811382138313841385138613871388138913901391139213931374 unmodified lines# Detect whether the HTML output is multi-file (=== filename === blocks)files = {}parse_error = Nonetry:files = parse_multipage_html_output(code)print(f"[Deploy] Parsed files: {list(files.keys())}")files = validate_and_autofix_files(files)print(f"[Deploy] After validation: {list(files.keys())}")except Exception as e:parse_error = str(e)print(f"[Deploy] Parse error: {parse_error}")files = {}# If we have multiple files (or at least a parsed index.html), upload the whole folderif isinstance(files, dict) and len(files) > 0 and files.get('index.html'):import tempfileimport os
anycoder_app/parsers.py+32-7
anycoder_app/ui.py+7-2