""" Strips the dead SPA-fragment dual-render wrapper from a barant-site/jet/*.jet route file, leaving just the real page content (the former "_full_NAME" tag body), unwrapped, with no fragment-flag try/catch, no _frag_NAME tag definition, no dispatch , and no dead client-side SPA navigation script. Structure being removed (present in all 20 files, verified consistent): #api GET /NAME ...... ... fragment-only content, NEVER actually invoked any more since the client-side SPA click handlers were already disabled earlier this session ... ... the REAL page content - full doctype/head/style/body wrapper ... <_frag_NAME /><_full_NAME /> Kept: "#api GET /NAME\n" plus everything between "" and its own matching close, MINUS the dead ", re.DOTALL, ) new_content, n = pattern.subn("", content, count=1) return new_content, n def strip_fragment_wrapper(content, page_name): lines = content.split("\n", 1) assert lines[0].startswith("#api GET /"), f"unexpected first line: {lines[0]!r}" api_line = lines[0] rest = lines[1] if len(lines) > 1 else "" start_marker = ( '' '' f'' ) if start_marker not in rest: return None, f"start marker not found" idx = rest.index(start_marker) prefix_extra = rest[:idx] # should just be leading whitespace/newline, kept as-is rest = rest[idx + len(start_marker):] mid_marker = f'' if mid_marker not in rest: return None, f"mid marker not found" mid_idx = rest.index(mid_marker) rest = rest[mid_idx + len(mid_marker):] end_pattern = re.compile( r'' rf'<_frag_{re.escape(page_name)} /><_full_{re.escape(page_name)} />\s*$' ) m = end_pattern.search(rest) if not m: return None, f"end marker not found" full_content = rest[:m.start()] full_content, nscript = strip_dead_spa_script(full_content) result = api_line + "\n" + prefix_extra + full_content return result, f"ok (removed {nscript} dead script block(s))" def main(): if len(sys.argv) != 4: print("usage: strip_fragments.py ") sys.exit(1) with open(sys.argv[1], encoding="utf-8", newline="") as f: content = f.read() result, status = strip_fragment_wrapper(content, sys.argv[3]) if result is None: print(f"FAILED for {sys.argv[3]}: {status}") sys.exit(1) with open(sys.argv[2], "w", encoding="utf-8", newline="") as f: f.write(result) print(f"{sys.argv[3]}: {status} ({len(content)} -> {len(result)} bytes)") if __name__ == "__main__": main()