mailer/src/template.tsx

22 lines
463 B
TypeScript
Raw Normal View History

2024-03-29 16:04:11 +01:00
import React from 'preact/compat' //for jsx-email
import { render } from 'jsx-email'
// @deno-types="npm:turndown"
import Turndown from 'turndown'
import { JSX } from 'preact'
2024-03-28 22:32:46 +01:00
2024-03-29 16:04:11 +01:00
const htmlToMd = new Turndown({
headingStyle: 'atx',
codeBlockStyle: 'fenced',
})
2024-03-28 22:32:46 +01:00
2024-03-29 16:04:11 +01:00
export async function renderTemplate(
template: JSX.Element,
): Promise<{ html: string; text: string }> {
const html = await render(template)
2024-03-28 22:32:46 +01:00
2024-03-29 16:04:11 +01:00
return {
html,
text: htmlToMd.turndown(html),
}
}