diff --git a/client/src/components/PDF/TripPDF.test.ts b/client/src/components/PDF/TripPDF.test.ts index 5d010a344..950cae85a 100644 --- a/client/src/components/PDF/TripPDF.test.ts +++ b/client/src/components/PDF/TripPDF.test.ts @@ -399,13 +399,8 @@ describe('downloadTripPDF', () => { // #2692: a place's description and notes print as the planner shows them, not as raw markdown. it('FE-COMP-TRIPPDF-016c: renders markdown in a place description, sanitized', async () => { - const place = { ...placeWithDetails, description: '**Colosseum** tickets - -| Gate | Time | -| --- | --- | -| A | 9:00 | - -' } + const description = ['**Colosseum** tickets', '', '| Gate | Time |', '| --- | --- |', '| A | 9:00 |', '', ''].join('\n') + const place = { ...placeWithDetails, description } const md = { ...richArgs, places: [place], assignments: { '10': [{ ...assignmentForDay, place }] } } await downloadTripPDF(md as any) const html = getIframe()!.srcdoc diff --git a/client/src/components/PDF/TripPDF.tsx b/client/src/components/PDF/TripPDF.tsx index 6bbbe2805..251142fbf 100644 --- a/client/src/components/PDF/TripPDF.tsx +++ b/client/src/components/PDF/TripPDF.tsx @@ -24,7 +24,7 @@ import { fetchExchangeRates } from '../../hooks/useExchangeRates' import { getFlightLegs, getTrainLegs, usesStationRoute } from '../../utils/flightLegs' import { isServiceStopType } from '../Roadtrip/roadtripModel' import { onlyMyPlan } from './pdfScope' -import { createMarkdownHtml } from '../shared/SafeMarkdown' +import { createMarkdownHtml } from '../shared/markdownHtml' /** * Every day starts a new page by default. On a trip of short days that prints @@ -845,13 +845,13 @@ export async function downloadTripPDF({ trip, days, places, assignments: allStor .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-left: 14px; } - .md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { font-size: 10px; font-weight: 700; color: #475569; margin: 4px 0 2px; } + .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: left; } + .md th, .md td { border: 1px solid #e2e8f0; padding: 2px 5px; text-align: start; } .md code { font-family: ui-monospace, monospace; font-size: 8.5px; } .md a { color: inherit; text-decoration: underline; } - .md blockquote { border-left: 2px solid #e2e8f0; padding-left: 6px; } + .md blockquote { border-inline-start: 2px solid #e2e8f0; padding-inline-start: 6px; } .chips { display: flex; flex-wrap: wrap; gap: 4px; padding-left: 21px; margin-top: 4px; } .chip { display: inline-flex; align-items: center; gap: 3px; font-size: 8px; font-weight: 600; background: #f1f5f9; color: #374151; border-radius: 99px; padding: 2px 7px; white-space: nowrap; } diff --git a/client/src/components/shared/SafeMarkdown.test.tsx b/client/src/components/shared/SafeMarkdown.test.tsx index 70d1877a4..6137c2bbf 100644 --- a/client/src/components/shared/SafeMarkdown.test.tsx +++ b/client/src/components/shared/SafeMarkdown.test.tsx @@ -1,7 +1,8 @@ import { render, screen } from '@testing-library/react'; import { describe, expect, it } from 'vitest'; -import { SafeMarkdown, createMarkdownHtml } from './SafeMarkdown'; +import { createMarkdownHtml } from './markdownHtml'; +import { SafeMarkdown } from './SafeMarkdown'; describe('SafeMarkdown (#2692)', () => { it('FE-COMP-SAFEMD-001: renders GitHub markdown with kept line breaks and safe links', () => { diff --git a/client/src/components/shared/SafeMarkdown.tsx b/client/src/components/shared/SafeMarkdown.tsx index 97ef2c1d8..00a759f11 100644 --- a/client/src/components/shared/SafeMarkdown.tsx +++ b/client/src/components/shared/SafeMarkdown.tsx @@ -1,5 +1,3 @@ -import { flushSync } from 'react-dom'; -import { createRoot } from 'react-dom/client'; import Markdown from 'react-markdown'; import remarkBreaks from 'remark-breaks'; import remarkGfm from 'remark-gfm'; @@ -22,26 +20,3 @@ export function SafeMarkdown({ children }: { children: string }) { ); } - -/** - * Turns markdown into the HTML {@link SafeMarkdown} renders, for output built as - * a string such as the PDF export (#2692). It renders through the same - * pipeline into a detached node, so the sanitizer is the one the app uses and - * no second markdown library is bundled. Call it outside a render and dispose - * of it when done; the same text is rendered once. - */ -export function createMarkdownHtml(): { html: (text: string) => string; dispose: () => void } { - const host = document.createElement('div'); - const root = createRoot(host); - const done = new Map(); - return { - html: (text) => { - const known = done.get(text); - if (known !== undefined) return known; - flushSync(() => root.render({text})); - done.set(text, host.innerHTML); - return host.innerHTML; - }, - dispose: () => root.unmount(), - }; -} diff --git a/client/src/components/shared/markdownHtml.tsx b/client/src/components/shared/markdownHtml.tsx new file mode 100644 index 000000000..e8e3d8b2e --- /dev/null +++ b/client/src/components/shared/markdownHtml.tsx @@ -0,0 +1,27 @@ +import { flushSync } from 'react-dom'; +import { createRoot } from 'react-dom/client'; + +import { SafeMarkdown } from './SafeMarkdown'; + +/** + * Turns markdown into the HTML {@link SafeMarkdown} renders, for output built as + * a string such as the PDF export (#2692). It renders through the same + * pipeline into a detached node, so the sanitizer is the one the app uses and + * no second markdown library is bundled. Call it outside a render and dispose + * of it when done; the same text is rendered once. + */ +export function createMarkdownHtml(): { html: (text: string) => string; dispose: () => void } { + const host = document.createElement('div'); + const root = createRoot(host); + const done = new Map(); + return { + html: (text) => { + const known = done.get(text); + if (known !== undefined) return known; + flushSync(() => root.render({text})); + done.set(text, host.innerHTML); + return host.innerHTML; + }, + dispose: () => root.unmount(), + }; +} diff --git a/client/src/mobile/screens/trip/sheets/MTransportSheet.tsx b/client/src/mobile/screens/trip/sheets/MTransportSheet.tsx index e329defac..8cc11ab01 100644 --- a/client/src/mobile/screens/trip/sheets/MTransportSheet.tsx +++ b/client/src/mobile/screens/trip/sheets/MTransportSheet.tsx @@ -125,7 +125,8 @@ export default function MTransportSheet({ planner, shell }: MTripSheetsProps) { // Per-segment booking codes (#1943), only on a real stopover booking: the // single-leg fallback would just echo the booking's own code shown below. - const routeLegs: (FlightLeg | TrainLeg)[] = res.type === 'flight' ? getFlightLegs(res) : usesStationRoute(res.type) ? getTrainLegs(res) : [] + const isFlight = res.type === 'flight' + const routeLegs: (FlightLeg | TrainLeg)[] = isFlight ? getFlightLegs(res) : usesStationRoute(res.type) ? getTrainLegs(res) : [] const legCodes = routeLegs.length > 1 ? routeLegs.filter(l => l.confirmation_number) : [] // Opened from one leg's row, the sheet shows that leg's own number, seat, // platform and times rather than the first leg's (#2701). @@ -148,8 +149,8 @@ export default function MTransportSheet({ planner, shell }: MTripSheetsProps) { else if (date) subParts.push(bookingDayLabel(date, locale)) // A flight's legs carry no seat or platform of their own, so those stay the booking's. - const seat = leg && res.type !== 'flight' ? legDetail.seat : meta.seat - const platform = leg && res.type !== 'flight' ? legDetail.platform : meta.platform + const seat = leg && !isFlight ? legDetail.seat : meta.seat + const platform = leg && !isFlight ? legDetail.platform : meta.platform const transitLegs: TransitLeg[] = Array.isArray(meta.transit?.legs) ? meta.transit.legs : [] const resFiles = filesFor(res, planner.files || []) diff --git a/client/src/pages/SharedTripPage.test.tsx b/client/src/pages/SharedTripPage.test.tsx index a1848dc4e..1e9d88dc5 100644 --- a/client/src/pages/SharedTripPage.test.tsx +++ b/client/src/pages/SharedTripPage.test.tsx @@ -1664,15 +1664,9 @@ describe('SharedTripPage', () => { 21: [{ id: 304, day_id: 21, order_index: 0, notes: '**Bring** cash', place: { - id: 504, name: 'Market', description: '## Opening - -| Day | Hours | -| --- | --- | -| Sat | 8 to 14 | - -', - address: 'Market Square 1', lat: null, lng: null, duration_minutes: 0, notes: '- fruit -- bread', + id: 504, name: 'Market', + description: ['## Opening', '', '| Day | Hours |', '| --- | --- |', '| Sat | 8 to 14 |', '', ''].join('\n'), + address: 'Market Square 1', lat: null, lng: null, duration_minutes: 0, notes: ['- fruit', '- bread'].join('\n'), website: null, phone: null, category_id: null, price: null, place_time: null, end_time: null, image_url: null, transport_mode: 'walking', category: null, tags: [], }, diff --git a/client/tests/unit/mobile/trip/MPlanTimelineRows.test.tsx b/client/tests/unit/mobile/trip/MPlanTimelineRows.test.tsx index 59a29f770..230d077d1 100644 --- a/client/tests/unit/mobile/trip/MPlanTimelineRows.test.tsx +++ b/client/tests/unit/mobile/trip/MPlanTimelineRows.test.tsx @@ -193,7 +193,7 @@ describe('TransportRow', () => { expect(screen.getByText('LH 714 to Tokyo')).toBeInTheDocument() expect(container.textContent).toContain('08:15 – 18:40') - expect(screen.getByText('Lufthansa · LH714 · MUC → HND')).toBeInTheDocument() + expect(screen.getByText('Lufthansa, LH714, MUC → HND')).toBeInTheDocument() }) it('FE-MOB-PLROW-014: a multi-day span shows only the day-relevant time', () => {