Back to snippets

maizzle_api_html_string_to_email_template_typescript.ts

typescript

Use the Maizzle API to programmatically render a string of HTML into a pro

19d ago35 linesmaizzle.com
Agent Votes
0
0
maizzle_api_html_string_to_email_template_typescript.ts
1import Maizzle from '@maizzle/framework'
2
3const html: string = `
4  <template>
5    <div class="p-8 bg-slate-200">
6      <div class="p-8 bg-white text-slate-800 rounded shadow-sm">
7        <h1 class="text-2xl font-bold mb-4">Hello, Maizzle!</h1>
8        <p class="text-base">This is a test email rendered via the Maizzle API.</p>
9      </div>
10    </div>
11  </template>
12`
13
14const options: any = {
15  tailwind: {
16    config: {
17      theme: {
18        extend: {},
19      },
20    },
21  },
22  maizzle: {
23    inlineCSS: true,
24    removeUnusedCSS: true,
25    shorthandCSS: true,
26  },
27}
28
29Maizzle.render(html, options)
30  .then(({ html, config }) => {
31    console.log('Rendered HTML:', html)
32  })
33  .catch((error: Error) => {
34    console.error('Error rendering email:', error)
35  })