mailer/src/template.tsx

24 lines
512 B
TypeScript

import React from 'preact/compat' //for jsx-email
import { render } from 'jsx-email'
// @deno-types="npm:turndown@^7.1.3"
import Turndown from 'turndown'
import type { JSX } from 'preact'
console.assert(React !== undefined)
const htmlToMd = new Turndown({
headingStyle: 'atx',
codeBlockStyle: 'fenced',
})
export async function renderTemplate(
template: JSX.Element,
): Promise<{ html: string; text: string }> {
const html = await render(template)
return {
html,
text: htmlToMd.turndown(html),
}
}