UNPKG

@maizzle/framework

Version:

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

34 lines (33 loc) 1.38 kB
//#region src/render/plugins/rawExtract.ts /** * Vite plugin that extracts raw slot content from <Raw> tags * and passes it as a :content prop before Vue compiles the template. * * Lets users write content (including `{{ }}` interpolation syntax used * by ESPs / Handlebars / Liquid) inside <Raw> without Vue parsing it. */ function rawExtract() { const re = /<(Raw)((?:\s[^>]*?)?)>([\s\S]*?)<\/\1>/g; return { name: "maizzle:raw-extract", enforce: "pre", transform(code, id) { if (!id.endsWith(".vue") && !id.endsWith(".md")) return; if (!code.includes("Raw")) return; const transformed = code.replace(re, (_match, tag, attrs, content) => { if (/(?:^|\s):content\b/.test(attrs) || /v-bind:content\b/.test(attrs)) return _match; const stripped = content.replace(/^\n+/, "").replace(/\s+$/, ""); if (!stripped) return _match; const minIndent = stripped.match(/^[ \t]*(?=\S)/gm)?.reduce((min, ws) => Math.min(min, ws.length), Infinity) ?? 0; return `<${tag}${attrs} content="${(minIndent > 0 ? stripped.replace(new RegExp(`^[ \\t]{${minIndent}}`, "gm"), "") : stripped).replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;")}" />`; }); if (transformed !== code) return { code: transformed, map: null }; } }; } //#endregion export { rawExtract }; //# sourceMappingURL=rawExtract.js.map