Skip to content

Commit 43745d3

Browse files
committed
docs: add AppImage component and markdown image shorthand
Wraps the v0 Image compound (Root/Img/Placeholder/Fallback) into a figure with lazy loading (200px rootMargin), a skeleton placeholder, rounded corners, a Retry-button fallback, and an optional figcaption. Overrides markdown-it's image rule so ![alt](url "caption") emits <AppImage> with the title attribute mapped to caption.
1 parent b7b247d commit 43745d3

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

apps/docs/build/markdown.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,17 @@ export function applyMarkdownPlugins (md: MarkdownIt, highlighter: DocsHighlight
459459
md.renderer.rules.table_open = () => '<div class="overflow-x-auto mb-4"><table>'
460460
md.renderer.rules.table_close = () => '</table></div>'
461461

462+
// Emit <AppImage> for markdown images: ![alt](src "title") — title maps to caption
463+
md.renderer.rules.image = (tokens, index) => {
464+
const token = tokens[index]
465+
const src = token.attrGet('src') ?? ''
466+
const alt = token.content || token.attrGet('alt') || ''
467+
const title = token.attrGet('title')
468+
const escape = md.utils.escapeHtml
469+
const captionAttr = title ? ` caption="${escape(title)}"` : ''
470+
return `<AppImage src="${escape(src)}" alt="${escape(alt)}"${captionAttr} />`
471+
}
472+
462473
md.renderer.rules.link_open = (tokens, index, options, env, self) => {
463474
const t = tokens[index]
464475
const classes = t.attrGet('class') || ''
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<script setup lang="ts">
2+
// Framework
3+
import { Image } from '@vuetify/v0'
4+
5+
const { src, alt, caption } = defineProps<{
6+
src: string
7+
alt: string
8+
caption?: string
9+
}>()
10+
</script>
11+
12+
<template>
13+
<figure class="my-4">
14+
<Image.Root
15+
:lazy="true"
16+
root-margin="200px"
17+
:src
18+
>
19+
<Image.Placeholder>
20+
<div class="bg-surface-variant animate-pulse w-full rounded-lg" style="min-height: 12rem" />
21+
</Image.Placeholder>
22+
<Image.Img
23+
:alt
24+
class="rounded-lg w-full block"
25+
/>
26+
<Image.Fallback v-slot="{ retry }">
27+
<div class="bg-surface-variant text-on-surface-variant flex flex-col items-center justify-center gap-2 rounded-lg w-full p-6" style="min-height: 12rem">
28+
<span class="text-sm">Failed to load image</span>
29+
<button
30+
class="text-xs bg-surface text-on-surface rounded px-3 py-1 hover:bg-surface-tint"
31+
type="button"
32+
@click="retry"
33+
>
34+
Retry
35+
</button>
36+
</div>
37+
</Image.Fallback>
38+
</Image.Root>
39+
<figcaption
40+
v-if="caption"
41+
class="text-sm text-on-surface-variant mt-2 text-center"
42+
>
43+
{{ caption }}
44+
</figcaption>
45+
</figure>
46+
</template>

0 commit comments

Comments
 (0)