From 9efa2c1a801d37ef079bfda0b716374d77d664ea Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Thu, 19 Jun 2025 00:12:22 +0800 Subject: [PATCH] feat(plugin-md-power): improve `plot` behavior (#620) --- docs/notes/theme/guide/components/plot.md | 8 +- docs/notes/theme/guide/markdown/plot.md | 86 ++++++++++---- .../src/client/components/Plot.vue | 110 +++++++++--------- .../plugin-md-power/src/node/inline/plot.ts | 16 +-- plugins/plugin-md-power/src/shared/plot.ts | 27 ++--- 5 files changed, 139 insertions(+), 108 deletions(-) diff --git a/docs/notes/theme/guide/components/plot.md b/docs/notes/theme/guide/components/plot.md index afb99d0a..ab33a2eb 100644 --- a/docs/notes/theme/guide/components/plot.md +++ b/docs/notes/theme/guide/components/plot.md @@ -29,12 +29,8 @@ export default defineUserConfig({ 鼠标悬停触发,或者点击触发 ::: -::: field name="mask" type="string | { light: string, dark: string }" default="'#000'" optional -遮罩颜色 -::: - -::: field name="color" type="string | { light: string, dark: string }" default="'#fff'" optional -文本颜色 +::: field name="effect" type="'blur' | 'mask'" default="'mask'" optional +遮罩层效果,或者文本模糊效果 ::: :::: diff --git a/docs/notes/theme/guide/markdown/plot.md b/docs/notes/theme/guide/markdown/plot.md index 1e97c6d0..e762e8da 100644 --- a/docs/notes/theme/guide/markdown/plot.md +++ b/docs/notes/theme/guide/markdown/plot.md @@ -33,33 +33,23 @@ export default defineUserConfig({ }) ``` -`markdownPower.plot` 支持传入 `boolean | PlotOptions` 类型 +`markdownPower.plot` 支持传入 `boolean | PlotOptions` 类型,该配置用于控制该功能的默认行为。 ```ts interface PlotOptions { - /** - * 是否启用 `!! !!` markdown (该标记为非标准标记,脱离插件将不生效) - * 如果设置为 false, 则表示不启用该标记,只能使用 组件 - * @default true - */ - tag?: boolean - - /** - * 遮罩层颜色 - */ - mask?: string | { light: string, dark: string } - - /** - * 文本颜色 - */ - color?: string | { light: string, dark: string } - /** * 触发方式 * * @default 'hover' */ trigger?: 'hover' | 'click' + + /** + * 遮罩层效果 + * + * @default 'mask' + */ + effect?: 'mask' | 'blur' } ``` @@ -69,21 +59,71 @@ interface PlotOptions { !!需要隐秘的内容!! ``` -如果不想使用 非标准的 `!! !!` 标记语法,你可以将 `plot.tag` 设置为 `false` , -然后使用 [``](../components/plot.md) 组件替代。 +还可以通过属性语法控制行为: + +```md +!!需要隐秘的内容!!{.click} +!!需要隐秘的内容!!{.hover} + +!!需要隐秘的内容!!{.mask} +!!需要隐秘的内容!!{.blur} + +!!需要隐秘的内容!!{.blur .click} +``` + +- `.click` - 点击触发 +- `.hover` - 鼠标悬停触发 +- `.mask` - 遮罩层效果 +- `.blur` - 文本模糊效果 + +::: info 你也可以使用 [``](../components/plot.md) 组件替代。 +::: + +## Frontmatter + +在 Frontmatter 中使用 `plot` 选项来控制在当前页面中该功能的默认行为: + +``` +--- +plot: + trigger: hover + effect: blur +--- +``` ## 示例 -输入: +**输入**: ```md 你知道吗, !!鲁迅!! 曾说过:“ !!我没说过这句话!!! ” 令我醍醐灌顶,深受启发,浑身迸发出无可匹敌的 力量!于是,!!我在床上翻了个身!! ! ``` -输出: +**输出**: :::demo-wrapper -你知道吗, !!鲁迅!! 曾说过:“ !!我没说过这句话!!! ” 令我醍醐灌顶,深受启发,浑身迸发出无可匹敌的 +你知道吗, !!鲁迅!! 曾说过:“ !!我没说过这句话!!!” 令我醍醐灌顶,深受启发,浑身迸发出无可匹敌的 力量!于是,!!我在床上翻了个身!! ! ::: + +**输入**: + +```md +遮罩层效果 + 鼠标悬停:!!鼠标悬停看到我了!!{.mask .hover} +遮罩层效果 + 点击:!!点击看到我了!!{.mask .click} +文本模糊效果 + 鼠标悬停:!!鼠标悬停看到我了!!{.blur .hover} +文本模糊效果 + 点击:!!点击看到我了!!{.blur .click} +``` + +**输出**: + +:::demo-wrapper +遮罩层效果 + 鼠标悬停:!!鼠标悬停看到我了!!{.mask .hover} + +遮罩层效果 + 点击:!!点击看到我了!!{.mask .click} + +文本模糊效果 + 鼠标悬停:!!鼠标悬停看到我了!!{.blur .hover} + +文本模糊效果 + 点击:!!点击看到我了!!{.blur .click} +::: diff --git a/plugins/plugin-md-power/src/client/components/Plot.vue b/plugins/plugin-md-power/src/client/components/Plot.vue index 02e2b2c2..7ec7ca88 100644 --- a/plugins/plugin-md-power/src/client/components/Plot.vue +++ b/plugins/plugin-md-power/src/client/components/Plot.vue @@ -1,61 +1,46 @@ @@ -64,8 +49,7 @@ function onClick() { @@ -73,25 +57,39 @@ function onClick() { diff --git a/plugins/plugin-md-power/src/node/inline/plot.ts b/plugins/plugin-md-power/src/node/inline/plot.ts index d5287c62..2262ffa4 100644 --- a/plugins/plugin-md-power/src/node/inline/plot.ts +++ b/plugins/plugin-md-power/src/node/inline/plot.ts @@ -60,9 +60,15 @@ const plotDef: RuleInline = (state, silent) => { state.posMax = state.pos state.pos = start + 2 - const token = state.push('plot_inline', 'Plot', 0) - token.markup = '!!' - token.content = content + const openToken = state.push('plot_inline_open', 'Plot', 1) + openToken.markup = '!!' + openToken.content = content + + const contentToken = state.push('text', '', 0) + contentToken.content = content + + const closeToken = state.push('plot_inline_close', 'Plot', -1) + closeToken.markup = '!!' state.pos = state.posMax + 2 state.posMax = max @@ -71,9 +77,5 @@ const plotDef: RuleInline = (state, silent) => { } export const plotPlugin: PluginWithOptions = (md) => { - md.renderer.rules.plot_inline = (tokens, idx) => { - const token = tokens[idx] - return `${token.content}` - } md.inline.ruler.before('emphasis', 'plot', plotDef) } diff --git a/plugins/plugin-md-power/src/shared/plot.ts b/plugins/plugin-md-power/src/shared/plot.ts index 923d44c1..bd33fc8e 100644 --- a/plugins/plugin-md-power/src/shared/plot.ts +++ b/plugins/plugin-md-power/src/shared/plot.ts @@ -1,24 +1,19 @@ +/** + * 是否启用 `!! !!` markdown (该标记为非标准标记,脱离插件将不生效) + */ export interface PlotOptions { - /** - * 是否启用 `!! !!` markdown (该标记为非标准标记,脱离插件将不生效) - * @default true - */ - tag?: boolean - - /** - * 遮罩层颜色 - */ - mask?: string | { light: string, dark: string } - - /** - * 文本颜色 - */ - color?: string | { light: string, dark: string } - /** * 触发方式 * * @default 'hover' */ trigger?: 'hover' | 'click' + + /** + * 遮罩层效果 + * + * @default 'mask' + */ + effect?: 'mask' | 'blur' + }