Overview

The github-alerts plugin converts GitHub-style alert blockquotes (> [!NOTE], > [!WARNING], etc.) and Obsidian callouts of any type (> [!custom-type]) into styled <div> containers with an icon and title. Foldable alerts are rendered as <details> elements.

<div class="markdown-alert" data-alert="note">
  <p class="markdown-alert-title">Note</p>
  <p>...</p>
</div>

Syntax

Write a blockquote with a [!TYPE] marker on the first line:

Note

Useful information that users should know, even if skimming.

Tip

Helpful advice for getting things done more effectively.

Important

Key information users need to know to achieve their goal.

Warning

Urgent info that needs immediate user attention to avoid problems.

Caution

Advises about risks or negative outcomes of certain actions.

> [!NOTE]
> Useful information that users should know, even if skimming.

> [!TIP]
> Helpful advice for getting things done more effectively.

> [!IMPORTANT]
> Key information users need to know to achieve their goal.

> [!WARNING]
> Urgent info that needs immediate user attention to avoid problems.

> [!CAUTION]
> Advises about risks or negative outcomes of certain actions.

The keyword is read in any case ([!note] is a note), without the spaces around it, and with each run of spaces inside it as a -, as Obsidian reads it: [! NOTE ] is a note, and [!My type] is the type my-type. A keyword can name any type, not only the built-in ones: see undefined types. A backslash before the marker (> \[!NOTE]) leaves the quote a quote, with the marker as text.

Custom titles

Override the default title by adding a space and text after the type marker. Text written straight against the marker (> [!NOTE]Title, > [!NOTE]-Title) leaves the quote a quote, as it does in Obsidian and on GitHub. Everything after the marker on that line is the title, and it can use inline formatting; the body starts on the next line. Emphasis, a code span or a link that opens in the title and closes on a later line takes the title with it, to the end of the line it closes on:

Custom Title

This alert uses a custom title instead of the default.

> [!NOTE] Custom *Title*
> This alert uses a custom title instead of the default.

Foldable alerts

Use + to make an alert open by default, or - to make it collapsed by default:

Tip

This tip is open by default.

Warning

This warning is collapsed by default.

> [!TIP]+
> This tip is open by default.

> [!WARNING]-
> This warning is collapsed by default.

Metadata

Text after a | in the marker is the alert's metadata, as in Obsidian. It goes on the container as data-alert-metadata, without the spaces around it, for a stylesheet to read; empty metadata ([!info|]) adds nothing. It works with every type, and with folding:

Metadata

This alert carries data-alert-metadata="wide".

> [!info|wide]+ Metadata
> This alert carries `data-alert-metadata="wide"`.
<details class="markdown-alert" data-alert="info" data-alert-metadata="wide" open>

The stylesheet gives metadata no meaning of its own: style it with a selector such as [data-alert-metadata~="wide"]. The marker's text is read as written, so an escaped character or a character reference anywhere between its brackets ([!info|a &amp; b]) leaves the quote a quote.

Attributes

With the attrs plugin, or Sätteri's built-in attributes feature, an alert takes attribute blocks the way a blockquote does. A block on a line after the alert, written without the >, goes on the alert. Written with the >, it goes on the body's last paragraph. A block touching an inline element in the title goes on that element and is left out of the title's label.

> [!NOTE] An *important*{.loud} note
> The body.
{#setup-note .wide}

List the attrs plugin after the alerts plugin. The engines differ in three places:

  • A block after a blank line (> [!NOTE], the body, a blank line, then {#setup-note}) goes on the alert in markdown-it and remark. Sätteri reads that line as an empty paragraph of its own, so use the form above there.
  • A block that ends the title line, as in > [!NOTE] Title {.wide}, goes on the title in markdown-it and is printed as text in remark and Sätteri. Put the block on its own line instead.
  • An alert with no body takes a block from the next line only on Sätteri. In markdown-it and remark, > [!NOTE] followed by {.wide} leaves an empty paragraph inside the alert.

Configuration

All options are passed when registering the plugin.

Disable icons

Set icons: false to suppress the SVG icon from every alert title:

Note

This note has no icon.

Warning

This warning has no icon.

> [!NOTE]
> This note has no icon.

> [!WARNING]
> This warning has no icon.
remarkGithubAlerts({ icons: false })
md.use(githubAlerts, { icons: false })
satteriGithubAlerts({ icons: false })

Override default titles

Supply a titles map to replace the default heading text for any built-in type:

Tip

This is a pro tip.

> [!TIP]
> This is a pro tip.
remarkGithubAlerts({ titles: { tip: "Pro tip" } })
md.use(githubAlerts, { titles: { tip: "Pro tip" } })
satteriGithubAlerts({ titles: { tip: "Pro tip" } })

Add custom alert types

Register new keywords with types. The value is the canonical type name that appears in the data-alert attribute and determines which CSS variable set applies. Style the new type with your own CSS:

remarkGithubAlerts({
  types: { release: "release", changelog: "release" },
  titles: { release: "Release notes" },
})
[data-alert="release"] {
  --markdown-alert-color: oklch(0.55 0.18 300);
}
md.use(githubAlerts, {
  types: { release: "release", changelog: "release" },
  titles: { release: "Release notes" },
})
[data-alert="release"] {
  --markdown-alert-color: oklch(0.55 0.18 300);
}
satteriGithubAlerts({
  types: { release: "release", changelog: "release" },
  titles: { release: "Release notes" },
})
[data-alert="release"] {
  --markdown-alert-color: oklch(0.55 0.18 300);
}

A key of types is read as a keyword is: "Release Notes" matches [!release notes] and [!RELEASE-NOTES]. A type you register keeps the title it is given, or its name capitalised (my-type is "My-type"), and has no icon.

Undefined types

A keyword that names no type, neither built-in (GitHub's five, and Obsidian's abstract, info, todo, success, question, failure, danger, bug, example and quote, with their aliases) nor registered with types, still makes an alert, as it does in Obsidian. The keyword is its type, in data-alert for a stylesheet to target. Its default title is the keyword with each - as a space and the first letter capitalised, unless titles names it; it takes the note's icon and the stylesheet's default colours. It folds and takes a title like any alert:

Custom type

An alert of a type nothing defines.

Pancakes

Folded, with a title of its own.

> [!custom-type]
> An alert of a type nothing defines.

> [!recipe]- Pancakes
> Folded, with a title of its own.
[data-alert="recipe"] {
  --markdown-alert-color: oklch(0.55 0.15 60);
}

Only a keyword made of letters, numbers, _ and - falls back: with any other character ([!a.b], [!what?]), the quote stays a quote. To keep to the built-in types and the ones you register, so that every other keyword leaves a quote, set fallback: false:

remarkGithubAlerts({ fallback: false })
md.use(githubAlerts, { fallback: false })
satteriGithubAlerts({ fallback: false })

Other options

Option Default
matchCaseInsensitive true false reads a keyword only as it is registered: the built-in keywords are lowercase, so [!note] is a note and [!NOTE] is not. [!NOTE] is then an undefined type of its own, NOTE, or a quote with fallback: false; an undefined type keeps its case.
containerClass "markdown-alert" The alert's class, which also starts the title's (-title). The stylesheet targets the default.

Usage

Install @mirrordown/remd-github-alerts and import the stylesheet. Pass githubAlertsHastHandlers to remarkRehype too: they add the title's icon, and without them an alert renders with no icon. List the plugin after the steps and tabs plugins if you use them, so a marker line directly under a step or tab header stays that body's text, as in markdown-it:

npm install @mirrordown/remd-github-alerts
import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import rehypeStringify from "rehype-stringify";
import { remarkGithubAlerts, githubAlertsHastHandlers } from "@mirrordown/remd-github-alerts";
import "@mirrordown/remd-github-alerts/github-alerts.css";

const processor = unified()
  .use(remarkParse)
  .use(remarkGithubAlerts)
  .use(remarkRehype, { handlers: githubAlertsHastHandlers })
  .use(rehypeStringify);
// astro.config.ts
import { defineConfig } from "astro/config";
import { remarkGithubAlerts, githubAlertsHastHandlers } from "@mirrordown/remd-github-alerts";
import "@mirrordown/remd-github-alerts/github-alerts.css";

export default defineConfig({
  markdown: {
    remarkPlugins: [remarkGithubAlerts],
    remarkRehype: { handlers: githubAlertsHastHandlers },
  },
});
npm install @mirrordown/mdit-github-alerts
import MarkdownIt from "markdown-it";
import { githubAlerts } from "@mirrordown/mdit-github-alerts";
import "@mirrordown/mdit-github-alerts/styles";

const md = new MarkdownIt().use(githubAlerts);
// .vitepress/config.ts
import { defineConfig } from "vitepress";
import { githubAlerts } from "@mirrordown/mdit-github-alerts";
import "@mirrordown/mdit-github-alerts/styles";

export default defineConfig({
  markdown: {
    config: (md) => md.use(githubAlerts),
  },
});
npm install @mirrordown/sat-github-alerts

List it after the plugins for inline syntax (mark, kbd and so on), so a title's aria-label reads the title's text rather than its markup, and after the steps and tabs plugins, so a marker line directly under a step or tab header stays that body's text.

import { markdownToHtml } from "satteri";
import { satteriGithubAlerts } from "@mirrordown/sat-github-alerts";
import "@mirrordown/sat-github-alerts/github-alerts.css";

const { html } = markdownToHtml(source, {
  mdastPlugins: [satteriGithubAlerts()],
});
// astro.config.ts
import { defineConfig } from "astro/config";
import { satteri } from "@astrojs/markdown-satteri";
import { satteriGithubAlerts } from "@mirrordown/sat-github-alerts";

export default defineConfig({
  markdown: {
    processor: satteri({ mdastPlugins: [satteriGithubAlerts()] }),
  },
});

// In your layout:
import "@mirrordown/sat-github-alerts/github-alerts.css";