Skip to content

MarkdownPreview Component ​

File Information ​

  • Path: app/components/preview/MarkdownPreview.vue
  • Purpose: In-app preview of md / markdown assets, rendered to sanitised HTML
  • Type: Preview component
  • Added in: commit 554da86, same design as collage-admin

Overview ​

MarkdownPreview downloads a Markdown file as text and shows it formatted. The text goes through renderMarkdown() (app/utils/markdownRenderer.ts), which parses it with marked and sanitises the result with DOMPurify before it is bound with v-html. It is mounted only by AssetContainer inside ClientOnly, so it never renders during SSR. Unlike TxtViewer it does not use the server proxy and has no zoom or search toolbar.

Props ​

PropTypeDescription
srcstringFile URL. AssetContainer passes markdownSrc: display_file when it is a string, else ''
altstringAlt text for the fallback image (file.display_file_name)
fallbackSrcstringImage shown when loading fails (previewImage || getImageSrc)

No events are emitted.

Load flow ​

RuleValue / behaviour
FetchBrowser fetch straight to display_file (a signed S3 URL from the API). No /api/txt/proxy. credentials: 'omit', cache: 'no-store'
Why no-storeS3 sends no Vary: Origin, so a copy cached from a non-CORS request (for example an <img> preload of the same signed URL) has no CORS headers and would make the fetch fail
PREVIEW_MAX_BYTES5 MB. Checked against Content-Length first (body cancelled, nothing downloaded), then against the text length
RENDER_MAX_BYTES1 MB. Larger files are not parsed; the raw text is shown in .md-preview-raw under "Large file — showing plain text. Download the file to view it formatted."
Too large"This file is too large to preview. Download the file to view it."
ErrorNo src, non-2xx, network or CORS failure shows fallbackSrc (class previewIcon)
Stale responsesOne AbortController per load; results for an older src are dropped; aborted on unmount

Both limits compare text.length (UTF-16 characters), not bytes.

renderMarkdown() ​

app/utils/markdownRenderer.ts, identical to the collage-admin file apart from one comment.

  1. Returns '' for empty or non-string input, and when DOMPurify.isSupported is false (no DOM), so unsanitised HTML is never returned.
  2. Lazy-loads marked once (cached import('marked') promise) and parses with { gfm: true, breaks: false, async: false }. marked passes raw HTML through, so every render is sanitised.
  3. DOMPurify.sanitize with USE_PROFILES: { html: true }, the deny lists below, ALLOW_DATA_ATTR: false and RETURN_DOM_FRAGMENT: true.
  4. Post-processes the returned fragment directly, not through global DOMPurify hooks, so other sanitize calls in the app are not affected.
  5. Returns the innerHTML of a detached div holding the fragment.
Removed by DOMPurifyList
FORBID_TAGSstyle, script, iframe, frame, frameset, object, embed, form, button, textarea, select, option, link, meta, base, svg, math, video, audio, source, track
FORBID_ATTRstyle, srcset, formaction, action, background, poster, ping, lowsrc, dynsrc
Data attributesAll data-* (ALLOW_DATA_ATTR: false)
ElementRule after sanitising
Links (<a>)href matching ^(https?:|mailto:) gets target="_blank" and rel="noopener noreferrer nofollow". #anchor links stay. Every other href (relative paths) is removed
Images (<img>)Only inline data:image/png, jpeg, jpg, gif or webp base64 URIs render. Others are replaced by span.markdown-image-blocked with [image: alt] or [image], so no remote image is requested
Inputs (<input>)GFM task-list checkboxes are kept and set disabled; other input types are removed

Dependencies added to package.json: marked ^18.2.1 and dompurify ^3.5.0 (with @types/dompurify ^3.2.0 in dev dependencies).

Styles ​

app/assets/scss/components/_markdown-preview.scss (imported in main.scss) styles .documents-wapper.md-preview: 8 px outer padding (commit eead984), white body, centred status and notice blocks, pre-wrap raw text, and spacing for headings, lists, blockquotes, code, tables and rules inside .md-preview-content. The same commit commented out the font-family: $font-family-header lines for h1 and h2 in app/assets/scss/base/_typography.scss; that change is global, not limited to the preview.