import json, os HERE=os.path.dirname(os.path.abspath(__file__)) def strip_exports(src): """Drop ES-module `export` lines so the body loads as a classic """ # Fill the data placeholders. str.replace is literal (no backref interpretation), # so backslashes in the inlined JS survive intact — the escaping-bug class that # the triple-quoted string used to cause is gone now that app.js is a real file. def fill_data(s): return (s.replace("COLORMATH_J",COLORMATH_BODY) .replace("SAMPLES_J",json.dumps(SAMPLES)) .replace("PALETTE_J",json.dumps(PALETTE)).replace("CATS_J",json.dumps(CATS)) .replace("UIFACES_J",json.dumps(UI_FACES)).replace("UIMAP_J",json.dumps(UIMAP)).replace("APPS_J",json.dumps(APPS)) .replace("BOLD_J",json.dumps(BOLD)).replace("MAP_J",json.dumps(MAP)).replace("LOCKS_J",json.dumps(LOCKS)).replace("ITALIC_J",json.dumps({k:True for k in ITALIC}))) # Splice the stylesheet and script in first, then fill the data placeholders they # carry. The page contains app.js exactly as fill_data(APP_BODY) renders it — # APP_FILLED is that rendering, the handle the inline-integrity test asserts on. HTML=fill_data(HTML.replace("STYLES_CSS",STYLES).replace("APP_JS",APP_BODY)) APP_FILLED=fill_data(APP_BODY) OUT=os.path.join(HERE,'theme-studio.html') if __name__=='__main__': open(OUT,"w").write(HTML) print("wrote",OUT)