fix
Browse filesFiles changed (2)
332 unmodified lines3333343353363373383391 unmodified line341342343344345346347348349350351352353354355356357358359360361362363364365366343344345346347348349367368369370371372373374375376377332 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 line cleaned = remove_code_block(text) files: Dict[str, str] = {} import re as _re # Check if there's content before the first === marker first_marker_match = _re.search(r"^===\s*([^=\n]+?)\s*===", cleaned, _re.MULTILINE) if first_marker_match: # There's content before the first marker first_marker_pos = first_marker_match.start() if first_marker_pos > 0: leading_content = cleaned[:first_marker_pos].strip() # Check if it looks like HTML content if 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 === markers remaining_text = cleaned[first_marker_pos:] if first_marker_pos > 0 else cleaned pattern = _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 present content = _re.sub(r"^```\w*\s*\n|\n```\s*$", "", content) files[name] = content else: # No === markers found, try standard pattern matching pattern = _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 present content = _re.sub(r"^```\w*\s*\n|\n```\s*$", "", content) files[name] = content pattern = _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 present content = _re.sub(r"^```\w*\s*\n|\n```\s*$", "", content) files[name] = content return files
def format_multipage_output(files: Dict[str, str]) -> str:1374 unmodified lines1375137613771378137913801381138213831381138413851386138713881389138513901391139213931374 unmodified lines # Detect whether the HTML output is multi-file (=== filename === blocks) files = {} parse_error = None try: 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: 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 folder if isinstance(files, dict) and files.get('index.html'): if isinstance(files, dict) and len(files) > 0 and files.get('index.html'): import tempfile import os anycoder_app/parsers.py+32-7
anycoder_app/ui.py+7-2