Color mode

Highlight

Inline ==highlight== support. Text wrapped in double equals is rendered as a <mark> element at build time.

日本語

Overview

highlight() registers a remark transformer that rewrites ==text== in Markdown text nodes into raw HTML before the tree is converted to HTML. It complements remark-gfm (which only understands ~~strikethrough~~).

Usage

ts
import { defineConfig } from "@riebeckite/core";
import { highlight } from "@riebeckite/plugin-highlight";
 
export default defineConfig({
  // ...
  plugins: [highlight()],
});

Syntax

md
This sentence has a ==highlighted phrase== inside it.

Output:

html
This sentence has a <mark class="rb-highlight">highlighted phrase</mark> inside it.

Highlights are matched non-greedily, must stay on a single line, and are ignored when they are empty or contain only whitespace. Matches inside code blocks, inline code, raw HTML, and frontmatter are left untouched.

Options

Option Type Default Description
className string "rb-highlight" CSS class on each generated element
tag string "mark" HTML tag used for the highlight
ts
highlight({ className: "my-highlight", tag: "span" });

Styling

The package ships style.css, exposed as @riebeckite/plugin-highlight/style.css. The default rule styles .rb-highlight with a subtle accent background and falls back to the --rb-color-accent theme variable when available:

css
.rb-highlight {
  --rb-highlight-accent: var(--rb-color-accent, #f6d365);
  padding: 0.05em 0.25em;
  border-radius: 0.2em;
  background: color-mix(in srgb, var(--rb-highlight-accent) 45%, transparent);
  color: inherit;
}

Because the plugin registers a style asset, the host site includes this stylesheet automatically; override the class or supply your own CSS to change the appearance.

Limitations

  • A highlight never spans multiple text nodes or lines, so == delimiters cannot wrap other Markdown (links, emphasis, code) or line breaks.
  • Nested highlights are not supported; the innermost == pair wins.
  • The transformer emits raw HTML, so enable raw HTML output in the pipeline (the default Riebeckite pipeline does).

Exports

  • highlight(options?) — plugin factory
  • highlightPlugin — alias of highlight
  • remarkHighlight(options?) — the underlying remark transformer
  • Type: HighlightOptions

See also

History

1 changesCollapseExpand
1 + <!-- Generated from packages/plugins/highlight/README.md. Do not edit this page directly; edit the package README and run `pnpm docs:sync`. -->
2 +
3 + # Highlight
4 +
5 + Inline `==highlight==` support. Text wrapped in double equals is rendered as a
6 + `<mark>` element at build time.
7 +
8 + [日本語](./highlight.md)
9 +
10 + ## Overview
11 +
12 + `highlight()` registers a remark transformer that rewrites `==text==` in
13 + Markdown text nodes into raw HTML before the tree is converted to HTML. It
14 + complements `remark-gfm` (which only understands `~~strikethrough~~`).
15 +
16 + ## Usage
17 +
18 + ```ts
19 + import { defineConfig } from "@riebeckite/core";
20 + import { highlight } from "@riebeckite/plugin-highlight";
21 +
22 + export default defineConfig({
23 + // ...
24 + plugins: [highlight()],
25 + });
26 + ```
27 +
28 + ## Syntax
29 +
30 + ```md
31 + This sentence has a ==highlighted phrase== inside it.
32 + ```
33 +
34 + Output:
35 +
36 + ```html
37 + This sentence has a <mark class="rb-highlight">highlighted phrase</mark> inside it.
38 + ```
39 +
40 + Highlights are matched non-greedily, must stay on a single line, and are
41 + ignored when they are empty or contain only whitespace. Matches inside code
42 + blocks, inline code, raw HTML, and frontmatter are left untouched.
43 +
44 + ## Options
45 +
46 + | Option | Type | Default | Description |
47 + | ------ | ---- | ------- | ----------- |
48 + | `className` | `string` | `"rb-highlight"` | CSS class on each generated element |
49 + | `tag` | `string` | `"mark"` | HTML tag used for the highlight |
50 +
51 + ```ts
52 + highlight({ className: "my-highlight", tag: "span" });
53 + ```
54 +
55 + ## Styling
56 +
57 + The package ships `style.css`, exposed as
58 + `@riebeckite/plugin-highlight/style.css`. The default rule styles
59 + `.rb-highlight` with a subtle accent background and falls back to the
60 + `--rb-color-accent` theme variable when available:
61 +
62 + ```css
63 + .rb-highlight {
64 + --rb-highlight-accent: var(--rb-color-accent, #f6d365);
65 + padding: 0.05em 0.25em;
66 + border-radius: 0.2em;
67 + background: color-mix(in srgb, var(--rb-highlight-accent) 45%, transparent);
68 + color: inherit;
69 + }
70 + ```
71 +
72 + Because the plugin registers a style asset, the host site includes this
73 + stylesheet automatically; override the class or supply your own CSS to change
74 + the appearance.
75 +
76 + ## Limitations
77 +
78 + - A highlight never spans multiple text nodes or lines, so `==` delimiters
79 + cannot wrap other Markdown (links, emphasis, code) or line breaks.
80 + - Nested highlights are not supported; the innermost `==` pair wins.
81 + - The transformer emits raw HTML, so enable raw HTML output in the pipeline
82 + (the default Riebeckite pipeline does).
83 +
84 + ## Exports
85 +
86 + - `highlight(options?)` — plugin factory
87 + - `highlightPlugin` — alias of `highlight`
88 + - `remarkHighlight(options?)` — the underlying remark transformer
89 + - Type: `HighlightOptions`
90 +
91 + ## See also
92 +
93 + - [Plugin guide](../reference/plugin-api.en.md)
94 +