Attrs support
Less than 1 minute
You can use custom syntax to add attrs for Markdown content.
Config
// .vuepress/config.ts
import { mdEnhancePlugin } from "vuepress-plugin-md-enhance";
export default {
plugins: [
mdEnhancePlugin({
// Enable attrs support
attrs: true,
}),
],
};
// .vuepress/config.js
import { mdEnhancePlugin } from "vuepress-plugin-md-enhance";
export default {
plugins: [
mdEnhancePlugin({
// Enable attrs support
attrs: true,
}),
],
};
Usage
You can use {attrs}
to add attrs to Markdown content.
For example, if you want a heading2 "Hello World" with a id "say-hello-world", you can write:
## Hello World {#say-hello-world}
If you want a image with class "full-width", you can write:
 {.full-width}
Also, other attrs are supported, so:
A paragraph with some text. {#p .a .b align=center customize-attr="content with spaces"}
will be rendered into:
<p id="p" class="a b" align="center" customize-attr="content with spaces">
A paragraph with some text.
</p>
Advanced
You can pass options to attrs
to customize plugin behavior.
interface AttrsOptions {
/**
* left delimiter
*
* @default '{'
*/
left?: string;
/**
* right delimiter
*
* @default '}'
*/
right?: string;
/**
* allowed attributes
*
* @description An empty list means allowing all attribute
*
* @default []
*/
allowed?: (string | RegExp)[];
}
Demo
Text with inline code
and , also supporting emphasis and bold.
Table |
---|
content |
list item
- nested list item
A line with break
block content
Text with `inline code`{.inline-code} and {.image}, also supporting _emphasis_{.emphasis} and **bold**{.bold}.
| Table |
| ------- |
| content |
{.table}
- list item{.list-item}
- nested list item
{.nested}
{.list}
A line with break
{.break}
--- {.horizontal}
block content {.block}