fix
Browse filesFiles changed (2)
- backend_api.py+30-3
- backend_parsers.py+12-9
519 unmodified lines520521522523523524525526527525526528529530531532533534535536537538539540541542543544545546547548549550551552553554555556519 unmodified lines try: original_code = code # Special handling for transformers.js - preserve === markers # Special handling for transformers.js - extract only the === sections if language == "transformers.js": # Find the first === marker first_marker = code.find('===') if first_marker == -1: # Don't clean transformers.js code - it needs the === markers return code # No markers found, return as-is return code # Find the last code section end (after the last ===) # Look for the last === marker last_marker_start = code.rfind('===') if last_marker_start == -1: return code # Find the end of the last code section # This is typically followed by explanatory text starting with --- or multiple newlines code_after_last_marker = code[last_marker_start:] # Find where the actual code section ends (look for --- or excessive explanatory text) end_markers = ['---', '\n\n\nThis ', '\n\n\n✨', '\n\n\n🎨', '\n\n\n🚀'] code_end = len(code) for end_marker in end_markers: pos = code.find(end_marker, last_marker_start) if pos != -1 and pos < code_end: code_end = pos # Extract from first === to end of code cleaned_code = code[first_marker:code_end].strip() return cleaned_code # Special handling for ComfyUI JSON if language == "comfyui":17 unmodified lines18192021212223242526232425282627282999 unmodified lines12913013113413513613213313413513613713813914014114217 unmodified lines print(f"[Parser] Received code length: {len(code)} characters") print(f"[Parser] First 200 chars: {code[:200]}") # Auto-fix: If code doesn't start with === index.html ===, add it # Check if code has === markers code_stripped = code.strip() if not code_stripped.startswith('==='): print("[Parser] Auto-fixing: Adding missing === index.html === marker") code = '=== index.html ===\n' + code code_stripped = code.strip() if '===' in code_stripped: print("[Parser] Code contains === markers, proceeding with parsing") else: print("[Parser] Code starts with === marker, proceeding normally") print("[Parser] WARNING: No === markers found in code") # Check if code starts with HTML instead of markers (common LLM mistake) if code_stripped.startswith('<!DOCTYPE') or code_stripped.startswith('<html'):99 unmodified lines if not (files['index.html'] and files['index.js'] and files['style.css']): # Use regex to extract sections - match === markers with optional whitespace and newlines # Fixed lookahead to allow any whitespace (not just \n) before next === marker html_fallback = re.search(r'===\s*index\.html\s*===\s*[\r\n]*([\s\S]+?)(?=\s*===\s*index\.js\s*===|$)', code, re.IGNORECASE) js_fallback = re.search(r'===\s*index\.js\s*===\s*[\r\n]*([\s\S]+?)(?=\s*===\s*style\.css\s*===|$)', code, re.IGNORECASE) css_fallback = re.search(r'===\s*style\.css\s*===\s*[\r\n]*([\s\S]+?)$', code, re.IGNORECASE) # Also support alternative names: styles.css or style.css, app.js or index.js html_fallback = re.search(r'===\s*index\.html\s*===\s*[\r\n]*([\s\S]+?)(?=\s*===|$)', code, re.IGNORECASE) # Try both index.js and app.js js_fallback = re.search(r'===\s*(?:index\.js|app\.js)\s*===\s*[\r\n]*([\s\S]+?)(?=\s*===|$)', code, re.IGNORECASE) # Try both style.css and styles.css css_fallback = re.search(r'===\s*(?:style\.css|styles\.css)\s*===\s*[\r\n]*([\s\S]+?)$', code, re.IGNORECASE) print(f"[Parser] Fallback extraction - HTML found: {bool(html_fallback)}, JS found: {bool(js_fallback)}, CSS found: {bool(css_fallback)}") backend_api.py+30-3
backend_parsers.py+12-9