Files
TREK/client/src/components/PDF/pdfMarkdown.ts
T
Maurice addcbe4801 fix(pdf): render markdown in day notes, booking notes and the day intro
The planner renders a day note's second line and a booking's notes as
markdown, and place texts in the PDF already went through the app's
sanitized markdown pipeline (#2692). Day notes, booking notes and the day
intro were still printed through escHtml, so the export showed the raw
syntax (asterisks, list dashes, rules) instead of the formatting.

They now use the same sanitized pipeline as bare markup inside their own
card, without the info row a place text gets, and drop the pre-line
whitespace that would double every markdown line break. Raw HTML in a
note is still printed as text.

Closes #3236
2026-11-27 19:58:00 +01:00

39 lines
1.7 KiB
TypeScript

import { createMarkdownHtml } from '../shared/markdownHtml';
/**
* Place descriptions and notes, day notes, booking notes and the day intro are
* markdown in the app, so the export renders them the same way instead of
* printing the raw syntax (#2692, #3236), the HTML from the app's own sanitized
* pipeline. `row` lays a place's text out as an info row, `html` is the bare
* markup for a card that brings its own box.
*/
export function createPdfMarkdown(): {
row: (text: string) => string;
html: (text: string) => string;
dispose: () => void;
} {
const markdown = createMarkdownHtml();
return {
row: (text) =>
`<div class="info-row"><span class="info-spacer"></span><div class="info-text muted md">${markdown.html(text)}</div></div>`,
html: markdown.html,
dispose: markdown.dispose,
};
}
/** The markdown's own spacing, lists, tables and links at the export's small size. */
export const PDF_MARKDOWN_CSS = `
.info-text.md { min-width: 0; overflow-wrap: anywhere; }
.note-time.md, .day-intro.md { white-space: normal; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md table, .md blockquote, .md pre { margin: 0 0 4px; }
.md ul, .md ol { padding-inline-start: 14px; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { font-size: 1.1em; font-weight: 700; margin: 4px 0 2px; }
.md table { border-collapse: collapse; }
.md th, .md td { border: 1px solid #e2e8f0; padding: 2px 5px; text-align: start; }
.md code { font-family: ui-monospace, monospace; font-size: calc(8.5px * var(--pdf-text, 1)); }
.md a { color: inherit; text-decoration: underline; }
.md blockquote { border-inline-start: 2px solid #e2e8f0; padding-inline-start: 6px; }
`;