DlFormat

Format Markdown content into a structured HTML output

The DlFormat inline component formats content at runtime and renders it safely inside your docs. It is universal by design and supports multiple formatting strategies. Use it when you need to format inline text that comes from props or slots, without manually writing raw HTML.

The Why

Sometimes you need to format dynamic strings (from frontmatter, data, or slots) using a specific formatting strategy. DlFormat transforms those strings into plain HTML for you, while still respecting DocLayer’s sanitization rules, keeping content consistent and safe.

Features

  • 🧰 universal formatter with pluggable strategies
  • 🧩 works with inline Markdown content
  • 🛡️ HTML sanitization via utilSafeHTML (configurable)
  • ⚠️ extensive error reporter when content is missing

Usage

Use :dl-format as an inline component providing the content through the default slot or the content prop. Choose the formatting strategy via the type prop.

:dl-format[**Bold** _italic_ and `code` ~~strikethrough~~]
:dl-format{content="**Bold** _italic_ and `code` ~~strikethrough~~"}

Result: Bold italic and code strikethrough

Configuration

By default, DlFormat sanitizes all generated HTML using the utilSafeHTML utility function. You can disable sanitization globally by setting sanitizeHTML to false in the module configuration. To disable sanitization only for specific instances, use the unsafe prop.

Formatting Types

DlFormat is designed to support multiple formatting strategies:

  • md-html: Markdown to HTML

Props

Here are the properties you can use with the DlFormat 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
contentstringundefined

Content to format. Required when the default slot is not provided.

type'md-html''md-html'

Formatting strategy. Currently only md-html (Markdown to HTML) is supported.

unsafebooleanfalse

Whether to render the content as unsafe HTML.

Accessibility

DlFormat outputs semantic HTML and sanitizes the output by default. Avoid inserting non-semantic HTML in Markdown.