DlImage

Present optimized, responsive images with optional caption and inline styling

The DlImage inline component renders images with optional captions, visually integrating them into your content. It is based on NuxtImg, providing integrated image compression and caching.

The Why

Adding images in Markdown is simple, but keeping consistent styling, spacing, borders, and captions across a large applications can be tedious. DlImage centralizes these concerns and makes images easy to standardize, while still letting you customize visuals inline when needed.

Features

  • 🖼️ simple, declarative image rendering
  • 🏷️ optional caption with Markdown formatting
  • đź§© theme-friendly visual adjustments
  • 🔄 consistent spacing, border, and radius across docs
  • 🤏 sensible defaults with accessibility in mind
  • ⚠️ extensive error reporter

Usage

Use :dl-image[...] as an inline component with the image source provided either as the default slot or via the src property. Always include an alt attribute for the best accessibility.

:dl-image[/images/ss-000.png]{alt="Beautiful Image"}<!-- or -->:dl-image{src="/images/ss-000.png" alt="Beautiful Image"}

Result:

Screenshot: Getting Started

With a caption

Captions support Markdown formatting, allowing you to create expressive and consistent descriptions. This is especially useful for highlighting code, UI elements, or providing additional context.

:dl-image{src="/images/ss-000.png" alt="Search UI" caption="A **simple** _search_ `result` layout."}

Result:

Search UI
A simple search result layout.

With a filename

Additionally, you can set the filename prop to true to display the file name alongside the caption.

:dl-image{src="/images/ss-000.png" alt="Search UI" caption="Test caption" filename=true}

Result:

Search UI
Test caption | ss-000.png

Styled inline

You can customize the component’s classes directly from Markdown using the iui slot, following the same rules as for component styling.

:dl-image{src="/images/ss-000.png" alt="Highlighted screenshot" :iui='{"image": "border-4"}'}

Result:

Highlighted screenshot

Configuration

Because the DlImage component is built on top of NuxtImg, it supports all configuration options available to the component. You can modify these options in your nuxt.config.ts file. Here you can check the default internal setup.

Props

Here are the properties you can use with the DlImage component. Each property should be set on an individual component instance; they do not affect the global configuration. More about defining properties in MDC components you can read here.

nametypedefaultdescription
lazybooleanundefined

Whether to lazy load the component.

srcstringundefined

Image source URL. Must be publicly reachable or handled by your image provider.

altstringImage

Alternative text for accessibility. Provide a descriptive value whenever the image conveys meaning.

captionstringundefined

Optional caption, supports Markdown formatting.

filenamebooleanfalse

Whether to display the file name (from the image source) in the caption.

iuiRecord<string, string>undefined

Special property dedicated to inline components, can be used to add TW classes for certain component markup elements.

Slots

namedescription
default

Default slot for the image source. You can use it interchangeably with the src prop for clearer presentation. Define without quotes.

Styling

Styling from Markdown

Every DocLayer component can be styled directly within your Markdown file using dedicated slot/property configuration. This allows you to customize the appearance of the component's markup elements without modifying global styles. More about components styling you can read here.

Below you'll find the default set of Tailwind classes for the component's dedicated markup elements.

<script lang="ts">const ui = defineDoclayerComponentUi({  base: ['u-space-mt', 'flex', 'justify-center', 'items-center', 'flex-col', 'w-full'],  image: ['u-space-p', 'u-border-color', 'u-border-radius', 'border', 'w-full', 'h-auto'],  caption: ['u-space-mt/2', 'u-text-color-doomed', 'text-sm'],});</script>

Accessibility

Alternative (alt) text. While the DlImage component will automatically add a generic alt text if none is provided, you should always define a meaningful alt attribute whenever the image conveys information. If the image is purely decorative, leave alt as it is in non-critical contexts.

Captions. Use captions to provide context, especially for screenshots and diagrams. Captions are particularly helpful when presenting code screenshots, as they offer additional information that connects the image to the surrounding content.