UNPKG

@maizzle/framework

Version:

Maizzle is a framework that helps you quickly build HTML emails with Tailwind CSS.

36 lines (35 loc) 1.84 kB
//#region src/transformers/minifyCodeInline.ts /** * Restore HTML inside elements marked `data-minify-inline`, then strip the * marker attribute and trim formatter-injected whitespace. * * Named for its primary client, `<CodeInline theme="…">`. The component * replaces shiki's structural `<`/`>` with private markers `§MZLT§` / * `§MZGT§` so the format pass (oxfmt with `htmlWhitespaceSensitivity: * 'ignore'`) can't see them as real angle brackets and reflow the * chain of `<span>` tokens. Source-level entities like `&lt;` (a * literal `<` in the user's code) are made of `&`, `l`, `t`, `;` — * no real `<` — so they pass through this pipeline untouched and * land in the browser as entities, rendering correctly as `<`. * * Runs unconditionally near the end of the pipeline so: * 1. The markers always get decoded back to real `<` / `>`. * 2. The `data-minify-inline` attribute never leaks to final HTML * (whether or not the inner content had markers). * 3. Whitespace the formatter injected around the inner content * (e.g. between `<code>` and the text node) is trimmed so the * inline element lands flush. * * The marker attribute is intentionally generic so any component facing * the same formatter-vs-inline-structure problem can opt in. */ function minifyCodeInline(html) { if (!html.includes("data-minify-inline")) return html; return html.replace(/<([a-zA-Z][\w-]*)([^>]*?)\s+data-minify-inline(?:="[^"]*")?([^>]*)>([\s\S]*?)<\/\1>/g, (_full, tag, before, after, contents) => { const cleanedAttrs = `${before}${after}`.replace(/\s+/g, " ").trim(); return `${cleanedAttrs ? `<${tag} ${cleanedAttrs}>` : `<${tag}>`}${contents.replace(/§MZLT§/g, "<").replace(/§MZGT§/g, ">").trim()}</${tag}>`; }); } //#endregion export { minifyCodeInline }; //# sourceMappingURL=minifyCodeInline.js.map