fix(email-renderer): preserve valid column table structure
This commit is contained in:
1 parent
ad81306625
commit
d8b9c2dcb5
3 files changed
+38
-3
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@wrnexus/email-renderer",
|
||||
"version": "0.1.6",
|
||||
"version": "0.1.7",
|
||||
"type": "module",
|
||||
"description": "WRNexus block email renderers with HTML, text, AMP Email, and MJML interoperability.",
|
||||
"exports": {
|
||||
|
||||
@@ -206,9 +206,9 @@ export const columnBlock = defineBlock({
|
||||
}),
|
||||
renderers: {
|
||||
emailHtml: ({ node, slots }) =>
|
||||
`<td data-block-id="${html(node.id)}" class="wrn-column" width="${html(attrs(node).width)}" valign="top">${slots.content}</td>`,
|
||||
`<td data-block-id="${html(node.id)}" class="wrn-column" width="${html(attrs(node).width)}" valign="top"><table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">${slots.content}</table></td>`,
|
||||
ampEmail: ({ node, slots }) =>
|
||||
`<td width="${html(attrs(node).width)}" valign="top">${slots.content}</td>`,
|
||||
`<td width="${html(attrs(node).width)}" valign="top"><table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">${slots.content}</table></td>`,
|
||||
mjml: ({ node, slots }) =>
|
||||
`<mj-column width="${html(attrs(node).width)}">${slots.content}</mj-column>`,
|
||||
},
|
||||
|
||||
@@ -73,6 +73,41 @@ describe("email renderer", () => {
|
||||
expect((await validateAmpEmail("<html></html>")).valid).toBe(false);
|
||||
});
|
||||
|
||||
test("keeps rendered block rows inside valid column tables", async () => {
|
||||
const columnDocument = structuredClone(document);
|
||||
const content = columnDocument.root.slots.content[0]!.slots.content;
|
||||
columnDocument.root.slots.content[0]!.slots.content = [
|
||||
{
|
||||
id: "columns",
|
||||
type: "layout.columns",
|
||||
version: 1,
|
||||
props: {},
|
||||
styles: {},
|
||||
slots: {
|
||||
columns: [
|
||||
{
|
||||
id: "column",
|
||||
type: "layout.column",
|
||||
version: 1,
|
||||
props: { width: "100%" },
|
||||
styles: {},
|
||||
slots: { content },
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
const rendered = await renderEmail(columnDocument, { amp: true });
|
||||
expect(rendered.ok).toBe(true);
|
||||
if (!rendered.ok) return;
|
||||
expect(rendered.value.parts.html.content).toContain(
|
||||
'data-block-id="column" class="wrn-column" width="100%" valign="top"><table role="presentation"',
|
||||
);
|
||||
expect(rendered.value.parts.html.content).toContain(
|
||||
'<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td data-block-id="heading"',
|
||||
);
|
||||
});
|
||||
|
||||
test("compiles only allowlisted semantic styles", async () => {
|
||||
const styled = structuredClone(document);
|
||||
styled.root.slots.content[0]!.slots.content[0]!.styles = {
|
||||
|
||||
Reference in new issue
Block a user