Appearance
MarkdownPreview Component ​
File Information ​
- Path:
app/components/preview/MarkdownPreview.vue - Purpose: In-app preview of
md/markdownassets, 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 ​
| Prop | Type | Description |
|---|---|---|
src | string | File URL. AssetContainer passes markdownSrc: display_file when it is a string, else '' |
alt | string | Alt text for the fallback image (file.display_file_name) |
fallbackSrc | string | Image shown when loading fails (previewImage || getImageSrc) |
No events are emitted.
Load flow ​
| Rule | Value / behaviour |
|---|---|
| Fetch | Browser fetch straight to display_file (a signed S3 URL from the API). No /api/txt/proxy. credentials: 'omit', cache: 'no-store' |
Why no-store | S3 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_BYTES | 5 MB. Checked against Content-Length first (body cancelled, nothing downloaded), then against the text length |
RENDER_MAX_BYTES | 1 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." |
| Error | No src, non-2xx, network or CORS failure shows fallbackSrc (class previewIcon) |
| Stale responses | One 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.
- Returns
''for empty or non-string input, and whenDOMPurify.isSupportedis false (no DOM), so unsanitised HTML is never returned. - Lazy-loads
markedonce (cachedimport('marked')promise) and parses with{ gfm: true, breaks: false, async: false }.markedpasses raw HTML through, so every render is sanitised. DOMPurify.sanitizewithUSE_PROFILES: { html: true }, the deny lists below,ALLOW_DATA_ATTR: falseandRETURN_DOM_FRAGMENT: true.- Post-processes the returned fragment directly, not through global DOMPurify hooks, so other sanitize calls in the app are not affected.
- Returns the
innerHTMLof a detacheddivholding the fragment.
| Removed by DOMPurify | List |
|---|---|
FORBID_TAGS | style, script, iframe, frame, frameset, object, embed, form, button, textarea, select, option, link, meta, base, svg, math, video, audio, source, track |
FORBID_ATTR | style, srcset, formaction, action, background, poster, ping, lowsrc, dynsrc |
| Data attributes | All data-* (ALLOW_DATA_ATTR: false) |
| Element | Rule 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.
Related ​
- AssetContainer - Picks this viewer for
md/markdown - TxtViewer - Plain text viewer (uses the server proxy)
- Asset Management - Feature overview and thumbnail rules
- collage-admin Document Previews - Same renderer in collage-admin