import os import json def get_html_template(title, manifest_data, node_id, standalone=False): # 1. Normalize Data if isinstance(manifest_data, list): manifest_data = {"items": manifest_data, "meta": {"model": "", "positive": "", "negative": ""}} # Indent JSON for readability json_str = json.dumps(manifest_data, indent=2) # The manifest is inlined inside a " would # end it early (page break / script injection). "<\/" is an equivalent JSON escape, so # JSON.parse (web/dashboard.js's incremental refresh) still reads the original text. json_str = json_str.replace("Error: Resource files not found.

{e}

" # 3. Inject Data wrapped_json = f"/*__JSON_START__*/\nlet fullManifest = {json_str};\n/*__JSON_END__*/" # 4. Final Replacements final_html = html_template \ .replace("__TITLE__", str(title)) \ .replace("__NODE_ID__", str(node_id)) \ .replace("__STANDALONE_FLAG__", "true" if standalone else "false") \ .replace("let fullManifest = __JSON_DATA__;", wrapped_json) \ .replace("__CSS_CONTENT__", css_content) \ .replace("__JS_CONTENT__", js_content) return final_html