diff --git a/formrestyle.js b/formrestyle.js new file mode 100644 index 0000000..73f7711 --- /dev/null +++ b/formrestyle.js @@ -0,0 +1,65 @@ +// Parse-or-refuse for pasted autoresponder forms (ported from Branded Voice lib/formrestyle.ts, 2026-09-29). +// Keeps the MECHANICS (action, method, hidden fields, visible text/email fields), replaces the SKIN, escapes +// everything. Anything that cannot be rebuilt faithfully is REFUSED with a reason; member markup is never +// injected into a page as-is. +'use strict'; +const EMBED_MAX_CHARS = 20000; +const escAttr = s => String(s).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); +function attr(tag, name) { + const m = tag.match(new RegExp('\\b' + name + '\\s*=\\s*"([^"]*)"', 'i')) || tag.match(new RegExp('\\b' + name + "\\s*=\\s*'([^']*)'", 'i')) || tag.match(new RegExp('\\b' + name + '\\s*=\\s*([^\\s"\'>]+)', 'i')); + return m ? m[1] : null; +} +const hasFlag = (tag, name) => new RegExp('\\b' + name + '\\b', 'i').test(tag); +function derivePlaceholder(type, name) { const n = name.toLowerCase(); if (type === 'email' || n.includes('email')) return 'Your best email address'; if (n.includes('first')) return 'Your first name'; if (n.includes('last')) return 'Your last name'; if (n.includes('name')) return 'Your name'; return 'Your answer'; } + +function problem(embed) { + const src = String(embed || '').trim(); + if (!src) return null; + if (src.length > EMBED_MAX_CHARS) return 'Form code is too long. Paste only the