Some checks failed
Deploy to Production / Deploy to Server (push) Failing after 20s
- Include compiled TypeScript with new /impressum, /privacy, /terms routes - Temporary commit of dist files for Docker deployment
30 lines
1.2 KiB
JavaScript
30 lines
1.2 KiB
JavaScript
import { marked } from "marked";
|
|
const defaultCss = `
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
font-size: 14px;
|
|
line-height: 1.6;
|
|
color: #1a1a1a;
|
|
max-width: 100%;
|
|
}
|
|
h1 { font-size: 2em; margin-bottom: 0.5em; border-bottom: 1px solid #eee; padding-bottom: 0.3em; }
|
|
h2 { font-size: 1.5em; margin-bottom: 0.5em; }
|
|
h3 { font-size: 1.25em; }
|
|
code { background: #f4f4f4; padding: 2px 6px; border-radius: 3px; font-size: 0.9em; }
|
|
pre { background: #f4f4f4; padding: 16px; border-radius: 6px; overflow-x: auto; }
|
|
pre code { background: none; padding: 0; }
|
|
table { border-collapse: collapse; width: 100%; margin: 1em 0; }
|
|
th, td { border: 1px solid #ddd; padding: 8px 12px; text-align: left; }
|
|
th { background: #f8f8f8; font-weight: 600; }
|
|
blockquote { border-left: 4px solid #ddd; margin: 1em 0; padding: 0.5em 1em; color: #666; }
|
|
img { max-width: 100%; }
|
|
`;
|
|
export function markdownToHtml(md, css) {
|
|
const html = marked.parse(md, { async: false });
|
|
return wrapHtml(html, css || defaultCss);
|
|
}
|
|
export function wrapHtml(body, css) {
|
|
return `<!DOCTYPE html>
|
|
<html><head><meta charset="utf-8"><style>${css || defaultCss}</style></head>
|
|
<body>${body}</body></html>`;
|
|
}
|