Skip to content

Commit a30daac

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
refactor(files): isolate PDF export from Markdown behavior
1 parent 2d91c3d commit a30daac

13 files changed

Lines changed: 461 additions & 436 deletions

File tree

apps/sim/app/api/files/export/[id]/markdown-pdf.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,19 @@ import {
1616
import type { JSONContent } from '@tiptap/core'
1717
import sharp from 'sharp'
1818
import { parseServerMarkdownToDoc } from '@/lib/collab-doc/server-markdown'
19-
import { embeddedFileRefKey, extractEmbeddedFileRef } from '@/lib/uploads/utils/embedded-image-ref'
19+
import {
20+
type EmbeddedFileRef,
21+
extractEmbeddedFileRef,
22+
} from '@/lib/uploads/utils/embedded-image-ref'
2023
import { splitFrontmatter } from '@/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/markdown-fidelity'
2124

2225
type PdfImage = { data: Buffer; format: 'png' }
26+
type ResolvedPdfImageRef = Exclude<EmbeddedFileRef, null>
27+
28+
/** PDF-local map key for either embedded workspace-image reference spelling. */
29+
export function markdownPdfImageKey(ref: ResolvedPdfImageRef): string {
30+
return 'key' in ref ? `key:${ref.key}` : `id:${ref.fileId}`
31+
}
2332

2433
interface GlyphFont {
2534
hasGlyphForCodePoint(codePoint: number): boolean
@@ -426,7 +435,7 @@ function renderImage(
426435
): ReactNode {
427436
const src = stringAttr(node, 'src') ?? ''
428437
const ref = extractEmbeddedFileRef(src)
429-
const image = ref ? images.get(embeddedFileRefKey(ref)) : undefined
438+
const image = ref ? images.get(markdownPdfImageKey(ref)) : undefined
430439
if (!image) {
431440
const alt = stringAttr(node, 'alt')
432441
return (

0 commit comments

Comments
 (0)