Skip to content

Mark

npm versionnpm monthly downloadsnpm sizenpm license

Mark plugin that adds ==highlight== syntax support to Markdown, rendering highlighted text with a scroll-triggered animation and multiple color variants.

Installation

sh
pnpm add vitepress-plugin-mark
sh
npm install vitepress-plugin-mark
sh
bun add vitepress-plugin-mark
sh
deno add vitepress-plugin-mark
sh
yarn add vitepress-plugin-mark

Usage

.vitepress/config.ts
ts
import { defineConfig } from 'vitepress-tuck'
import mark from 'vitepress-plugin-mark'

export default defineConfig({
  plugins: [mark()],
})

Learn more about vitepress-tuck

Native Mode

.vitepress/config.ts
ts
import { defineConfig } from 'vitepress'
import { markdownPlugin } from 'vitepress-plugin-mark'

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

Register the component in the theme and import the styles:

.vitepress/theme/index.ts
ts
import type { Theme } from 'vitepress'
import { enhanceAppWithMark } from 'vitepress-plugin-mark/client'
import DefaultTheme from 'vitepress/theme'

export default {
  extends: DefaultTheme,
  enhanceApp(ctx) {
    enhanceAppWithMark(ctx) 
  },
} satisfies Theme

Syntax

Wrap inline content with == to render it as a highlighted <mark> element. When the element scrolls into the viewport, a fill-from-left highlight animation plays once, giving the marked text a vivid emphasis effect.

md
==Marked== text

Rendered Result:

Marked text

Inline content inside the markers fully supports Markdown syntax (bold, italic, links, code, etc.):

md
==**bold**==, ==*italic*==, ==[link](https://example.com)==, ==`code`==

Rendered Result:

bold, italic, link to, code

Color Variants

Specify different highlight colors by appending an attrs syntax to the marker. Variant names correspond to VitePress container types and automatically adapt to dark mode.

md
==Default==
==note=={.note}
==info=={.info}
==tip=={.tip}
==warning=={.warning}
==caution=={.caution}
==important=={.important}

Rendered Result:

Default

note

info

tip

warning

caution

important

Variant Reference

VariantDescription
(default)Yellow highlight
.noteCyan highlight
.infoNeutral gray highlight
.tipGreen highlight
.warningGold/amber highlight
.cautionPink highlight (alias: .danger)
.importantLavender/purple highlight

Customization

Customize the highlight appearance by overriding the following CSS variables in your theme styles:

css
:root {
  --vp-mark-linear-color: #f0a;
}
VariableDescriptionDefault
--vp-mark-textText colorcurrentcolor
--vp-mark-bgBackground colortransparent
--vp-mark-linear-colorHighlight fill color#ff0
--vp-mark-bg-imageBackground image used for the fill (gradient)linear-gradient(to right, ...)
--vp-mark-bg-shiftVertical position shift of the background0.55lh
--vp-mark-animationAnimation shorthandmark-highlight 1.25s 0.5s forwards

You can also extend highlight color variants by customizing CSS class names:

css
mark.custom {
  --vp-mark-linear-color: #f0a;
}
md
==Custom variant=={.custom}

Rendered result:

Custom variant

Released under the MIT License