Overview

The definition-list plugin renders Pandoc-style definition lists as HTML <dl>, <dt>, and <dd> elements.

<dl>
  <dt>Term</dt>
  <dd>Definition</dd>
</dl>

Syntax

Write a term on one line, then follow it with one or more definitions prefixed by : or ~ :

Apple
A round fruit with red or green skin.
Also a technology company.
Orange
A citrus fruit with orange skin.
Apple
: A round fruit with red or green skin.
: Also a technology company.

Orange
: A citrus fruit with orange skin.

A term fits on one line: a marker after a paragraph of two or more lines continues that paragraph instead of starting a list, as in Pandoc.

Each definition is tight or loose on its own. A definition is loose, and wraps its content in <p>, when a blank line comes directly before its marker or separates blocks inside it. Otherwise its paragraphs render unwrapped. A marker with nothing after it produces an empty <dd>.

Sätteri

Sätteri reads definition lists itself, so there is no Mirrordown package for it: turn on its definitionList feature (markdownToHtml(source, { features: { definitionList: true } })), as the Sätteri preset does. It renders what the two plugins render, except in three corners:

  • After a marker with nothing on its line, the plugins take indented content after a blank line into that definition. Sätteri ends the list there.
  • In a blockquote, a definition whose marker follows a blank line is loose in the plugins and tight in Sätteri.
  • After a list nested in a definition, a blank line and more content give a <p> in the plugins and unwrapped text in Sätteri.

Styling

The plugin ships no stylesheet: <dl>, <dt> and <dd> get the browser's defaults, which indent each definition and leave its term plain. The examples in the Mirrordown docs use the docs' own styles, which bold the term and set each definition off with a rule:

dt {
  font-weight: 600;
}

dd {
  margin-inline-start: 0.25rem;
  padding-inline-start: 1rem;
  border-inline-start: 2px solid #e5e7eb;
}

Usage

Install @mirrordown/remd-definition-list. You must also pass defListHastHandlers to remarkRehype so the custom AST nodes are converted to HTML correctly:

npm install @mirrordown/remd-definition-list
import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import rehypeStringify from "rehype-stringify";
import { remarkDefinitionList, defListHastHandlers } from "@mirrordown/remd-definition-list";

const processor = unified()
  .use(remarkParse)
  .use(remarkDefinitionList)
  .use(remarkRehype, { handlers: defListHastHandlers })
  .use(rehypeStringify);
// astro.config.ts
import { defineConfig } from "astro/config";
import { remarkDefinitionList, defListHastHandlers } from "@mirrordown/remd-definition-list";

export default defineConfig({
  markdown: {
    remarkPlugins: [remarkDefinitionList],
    remarkRehype: { handlers: defListHastHandlers },
  },
});
npm install @mirrordown/mdit-definition-list
import MarkdownIt from "markdown-it";
import { dl } from "@mirrordown/mdit-definition-list";

const md = new MarkdownIt().use(dl);
// .vitepress/config.ts
import { defineConfig } from "vitepress";
import { dl } from "@mirrordown/mdit-definition-list";

export default defineConfig({
  markdown: {
    config: (md) => md.use(dl),
  },
});