fuc-new/doc/node_modules/@vuepress/plugin-markdown-hint/lib/node/markdownHintPlugin.js
hellcat 6adbc04d4b 1
2025-10-03 17:17:08 +08:00

53 lines
1.4 KiB
JavaScript

import { getFullLocaleConfig } from '@vuepress/helper';
import { getDirname, path } from 'vuepress/utils';
import { alert } from './alert.js';
import { hint } from './hint.js';
import { hintLocaleInfo } from './locales.js';
const PLUGIN_NAME = '@vuepress/plugin-markdown-hint';
const __dirname = import.meta.dirname || getDirname(import.meta.url);
/**
* Markdown hint plugin
*
* Markdown 提示插件
*
* @param options - plugin options / 插件选项
*
* @example
* ```ts
* import { markdownHintPlugin } from '@vuepress/plugin-markdown-hint'
*
* export default {
* plugins: [
* markdownHintPlugin({
* hint: true,
* alert: true,
* }),
* ],
* }
* ```
*/
export const markdownHintPlugin = (options) => {
if (!options.alert && options.hint === false)
return {
name: PLUGIN_NAME,
};
return {
name: PLUGIN_NAME,
extendsMarkdown: (md, app) => {
const locale = getFullLocaleConfig({
app,
name: PLUGIN_NAME,
default: hintLocaleInfo,
config: options.locales,
});
if (options.alert)
md.use(alert, locale);
if (options.hint ?? true)
md.use(hint, locale);
},
clientConfigFile: (options.injectStyles ?? true)
? path.resolve(__dirname, '../client/config.js')
: undefined,
};
};