test/node_modules/@mdit-vue/plugin-title/README.md
2024-08-13 09:27:52 +08:00

37 lines
835 B
Markdown

# @mdit-vue/plugin-title
[![npm](https://badgen.net/npm/v/@mdit-vue/plugin-title)](https://www.npmjs.com/package/@mdit-vue/plugin-title)
[![license](https://badgen.net/github/license/mdit-vue/mdit-vue)](https://github.com/mdit-vue/mdit-vue/blob/main/LICENSE)
A [markdown-it](https://github.com/markdown-it/markdown-it) plugin to get page title.
- Extracts title (the content of the first level-1 heading) into markdown-it `env.title`.
## Install
```sh
npm i @mdit-vue/plugin-title
```
## Usage
```ts
import { titlePlugin } from '@mdit-vue/plugin-title';
import type { MarkdownItEnv } from '@mdit-vue/types';
import MarkdownIt from 'markdown-it';
const md = MarkdownIt({ html: true }).use(titlePlugin);
const env: MarkdownItEnv = {};
const rendered = md.render(
`\
# h1
## h2
### h3
`,
env,
);
console.log(env.title);
```