The DlCode block component displays code snippets in a visually appealing and readable format. Among others it supports syntax highlighting, copy-to-clipboard functionality, easily integrates into your content pages of any kind. Use this component whenever you want to showcase code examples or command-line instructions to your users.
Features
- 🖍️ multiple-language syntax highlighting with Shiki
- 🎨 configurable highlighter
- 🖌️ built-in visual transformations: highlighting, focusing, diffing
- 🧑💻 custom and pre-built code transformations
- 🪄 dynamic fragments resolving
- 📋 one-click copy to clipboard
- 🗂️ automatic code blocks tabbing
- 🗂️ automatic tabs overlapping
- 📏 collapsible long code blocks
- 🔗 internal reference links with JSDoc
@linktag - 🧩 theme-friendly visual adjustments
- ⚠️ extensive error reporter
Usage
Use the ::dl-code as a block component with your Markdown code block provided in the default slot.
With a tab
Notice that in the previous example, no tabs are displayed above the code block. To show tabs (the filename with its extension), you need to set the tabs prop, aligned with MDC formatting.
With multiple tabs
To display multiple tabs with different code blocks, separate the tab names with commas. Remember that the number of code blocks must be the same as the number of defined tabs. Hence, different setup will print the Nuxt Error.
The difference between the tab contents is simply to demonstrate how switching between tabs works - the code will execute the same result.
Tabs overlapping
If you define multiple tab code components, the total width of the tab list will be calculated. If the tabs would overlap the block container, they will be grouped into a special context menu accessible from the right side of the component. Here is the simple example.
Be aware that this calculation must be performed only client-side. As a result, for the first visible block, you may see a loading indicator that will eventually be replaced by the component's content.
With visual transforms (highlighting, diffing, focusing)
The DlCode component implements couple of Shiki's visual transformers that you can use to highlight specific parts of your code. These transforms are applied by adding special markers inside your code blocks. You can use the same syntax as their original configuration presents.
Implemented transforms are:
transformerNotationHighlight,transformerNotationDiff,transformerNotationFocus,
and this is how you can use them.
Highlighting specific lines
The
!character has been escaped manually to demonstrate the code usage, remove the backslash when using it.
Diffing the code blocks
The
!character has been escaped manually to demonstrate the code usage, remove the backslash when using it.
Focusing (unbluring) specific lines of code
The
!character has been escaped manually to demonstrate the code usage, remove the backslash when using it.
With dynamic string replacement
The DlCode component supports dynamic string replacement within code blocks. This might be particularly very useful when you want to showcase code snippets that include variables or placeholders that should be replaced with actual values at runtime. To enable this feature, use the dynamic prop to provide the string that should be injected. Within your code block add :dl-dynamic: wherever you want the replacement to occur. This is how you can do it:
The :dl-dynamic: placeholder will be replaced with the value provided by the dynamic prop when the code block is rendered. For example, we use this feature on the utilities page to provide a dynamic imports description for certain utilities. So this solution might be a great way to handle dynamic values within your shareable components.
With reference link
The DlCode component can display reference links inside code blocks, using the JSDoc @link tag syntax. While documenting your code with JSDoc, you can point to other references within your application - either to local anchors (on the same page) or to global locations (on different pages); you can also use external websites as the link reference. Even more conveniently, you can use dl.pathMap markers to define internal reference links. Here’s how you can do it:
This way, the code block will render with clickable reference links inside it. These links are automatically resolved and displayed in a user-friendly format, making it easy for users to navigate related documentation.
Please note that this feature only works with the JSDoc @link notation, and with limited support for Shiki themes. Also, if you use external links, only secure links (those beginning with https://) will be handled.
Global Configuration
While basic, component-based configuration is managed through the props, the DlCode component also supports several global options. These options are set in the app.config.ts file under the dl.components.DlCode key. Below you'll find a list of all available options and details on how to configure them.
extensionIcons
An object mapping file extensions to icon names, used in the component tabs.
Extension to Icon mapping
Under the hood, DocLayer uses the Nuxt Icon Module (with the vscode set) to provide icons for the DlCode component tab list. When defining a tab name as a file, its extension must correspond to a specific icon name (e.g., .sh ➡️ shell). Sometimes these icons have different names and don’t follow extension definitions. This mapping helps avoid icon display issues.
More about module configuration, you can read here.
| type | default | required |
|---|---|---|
Record<string, string> | see below | no |
Below are the settings provided by default.
To extend the list of icons, simply define the same object inside your app.config.ts file and add new extension-to-icon mappings.
highlighter
This object configures the custom implementation of the Shiki code highlighter.
Custom Highlighter
Although Nuxt Content provides a built-in Shiki highlighter that automatically generates code blocks, we've decided to build our own custom DlCodeHighlighter component with a custom implementation of Shiki.
This gives us greater control over how code snippets are rendered, flexibility for custom configuration, and - most importantly - the ability to perform post-rendering code transformations, such as escaping specific code sections, which you can control as well.
| type | default | required |
|---|---|---|
Highlighter | see below | no |
Below are the settings provided by default.
To add more languages for the highlighter, simply provide your own list in the configuration object inside the app.config.ts file, they will be merged. If you want to specify a new themes, be aware that they will replace the default github themes.
Single Shiki instance
Please note that the highlighter uses a single, globally defined instance of the Shiki. If you want to use different highlighter instances for specific code blocks, you can achieve this by using the utilShikiHighlighter composable.
Code transformer
Note that the highlighter uses a specialized code transformer. This transformer processes the contents of code blocks inside the DlCode component and is currently used to escape selected chunks of code. The transformer is configured globally via dl.transformers.code.
maxHeight
Value that lets you set the maximum height of the code block. If the content exceeds this height, an expand button will appear. To always show the full block, set a large value (e.g., 1000rem).
| type | default | required |
|---|---|---|
'${string}rem' | 50rem | no |
Props
Here are the properties you can use with the DlCode 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.
| name | type | default | description |
|---|---|---|---|
lazy | boolean | undefined | Whether to lazy load the component. |
tabs | string | empty string | Comma-separated list of tab names (file names) for code blocks. |
maxHeight | string | 50rem | Maximum height of the code block. |
dynamic | string | undefined | Handles dynamic string to be replaced within the code with |
Slots
| name | description |
|---|---|
default | Default slot for the code content. |
ui | Dedicated slot for defining the component’s |
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.
CSS Variables
Here is a set of CSS variables you can use to customize the appearance of the DlCode component globally. More about theming and styling with CSS variables, you can read here.
CSS Utilities
Below are the CSS utility classes used by the DlCode component. They make use of the CSS variables described above and define the default styling for the component's markup elements.
Recipes
Below you'll find a few solutions to common issues you may encounter while writing content inside the DlCode component. If you find something worth reporting, please open an issue in the DocLayer repository.
Escaping code from being parsed
Sometimes, code placed inside the DlCode component may cause parsing issues, especially when it contains a mix of characters like quotes, colons, or other special symbols. This is particularly relevant for the dl-search Module parsing process - module will log code blocks with potential issues.
For example, JSON data is typically formatted with double quotes, which is the correct and standard way. However, if your code block also uses double quotes (such as in Vue props), the parser might have trouble interpreting it correctly, potentially causing formatting issues. To avoid this, it's better to use single quotes in your regular code definitions.
However, if you need to prevent code from being parsed (for example, if it causes formatting issues or is being unintentionally processed), wrap that code with [[ esc ]]...[[ /esc ]] tags. Any content inside these tags will be resolved, removed, or rendered as plain text, ensuring it is properly preserved.
You can also escape regular content - learn more about this here.

Because using these tags inside the DlCode component will escape (remove) them, you can see the example in the image above.
If you encounter any issues with formatting Markdown and MDC component definitions you can use this notation: &[[esc]]. It will divide the code properly and apply escaping.
Caution when using code transformer
Escaped code will be automatically processed and potentially removed in the output generated by the dl-search Module. However, the visual presentation (within the content) of these escape tags is managed by a dl.transformers.code global property. If you modify this functionality, the way how code is processed inside your components may/will change.
