diff --git a/modules/rspace/mod.ts b/modules/rspace/mod.ts
index 9e82633..13fe383 100644
--- a/modules/rspace/mod.ts
+++ b/modules/rspace/mod.ts
@@ -36,6 +36,29 @@ routes.get("/api/meta", async (c) => {
* Strips the shell chrome (header, tab-bar, welcome overlay) that renderShell provides,
* and returns just the canvas-specific DOM + inline styles + module scripts.
*/
+/** Strip a
and all its nested children by counting open/close tags. */
+function stripNestedDiv(html: string, className: string): string {
+ const re = new RegExp(`
]*class="[^"]*${className}[^"]*"[^>]*>`);
+ const match = html.match(re);
+ if (!match || match.index === undefined) return html;
+
+ let depth = 1;
+ let pos = match.index + match[0].length;
+ while (depth > 0 && pos < html.length) {
+ const nextOpen = html.indexOf("
", pos);
+ if (nextClose === -1) break;
+ if (nextOpen !== -1 && nextOpen < nextClose) {
+ depth++;
+ pos = nextOpen + 4;
+ } else {
+ depth--;
+ pos = nextClose + 6;
+ }
+ }
+ return html.substring(0, match.index) + html.substring(pos);
+}
+
function extractCanvasContent(html: string): { body: string; styles: string; scripts: string } {
// Extract inline