diff --git a/.vscode/settings.json b/.vscode/settings.json index 0914fe961..8d4a5479c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -46,6 +46,7 @@ "prefetch", "preload", "prismjs", + "revealjs", "shiki", "shikijs", "slugify", diff --git a/plugins/markdown/plugin-markdown-stylize/package.json b/plugins/markdown/plugin-markdown-stylize/package.json new file mode 100644 index 000000000..e508ea313 --- /dev/null +++ b/plugins/markdown/plugin-markdown-stylize/package.json @@ -0,0 +1,62 @@ +{ + "name": "@vuepress/plugin-markdown-stylize", + "version": "2.0.0-rc.54", + "description": "VuePress plugin - markdown stylize", + "keywords": [ + "vuepress-plugin", + "vuepress", + "plugin", + "markdown", + "stylize" + ], + "homepage": "https://ecosystem.vuejs.press/plugins/markdown/markdown-stylize.html", + "bugs": { + "url": "https://github.com/vuepress/ecosystem/issues" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/vuepress/ecosystem.git", + "directory": "plugins/markdown/plugin-markdown-stylize" + }, + "license": "MIT", + "author": { + "name": "Mr.Hope", + "email": "mister-hope@outlook.com", + "url": "https://mister-hope.com" + }, + "type": "module", + "exports": { + ".": "./lib/node/index.js", + "./package.json": "./package.json" + }, + "main": "./lib/node/index.js", + "types": "./lib/node/index.d.ts", + "files": [ + "lib" + ], + "scripts": { + "build": "tsc -b tsconfig.build.json", + "bundle": "rollup -c rollup.config.ts --configPlugin esbuild", + "clean": "rimraf --glob ./lib ./*.tsbuildinfo" + }, + "dependencies": { + "@mdit/plugin-align": "^0.13.1", + "@mdit/plugin-attrs": "^0.13.1", + "@mdit/plugin-mark": "^0.13.1", + "@mdit/plugin-spoiler": "^0.13.1", + "@mdit/plugin-stylize": "^0.13.1", + "@mdit/plugin-sub": "^0.13.1", + "@mdit/plugin-sup": "^0.13.1", + "@types/markdown-it": "^14.1.2", + "@vuepress/helper": "workspace:*" + }, + "peerDependencies": { + "vuepress": "2.0.0-rc.18" + }, + "devDependencies": { + "markdown-it": "^14.1.0" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/plugins/markdown/plugin-markdown-stylize/rollup.config.ts b/plugins/markdown/plugin-markdown-stylize/rollup.config.ts new file mode 100644 index 000000000..f970a5d27 --- /dev/null +++ b/plugins/markdown/plugin-markdown-stylize/rollup.config.ts @@ -0,0 +1,13 @@ +import { rollupBundle } from '../../../scripts/rollup.js' + +export default rollupBundle('node/index', { + external: [ + '@mdit/plugin-align', + '@mdit/plugin-attrs', + '@mdit/plugin-mark', + '@mdit/plugin-spoiler', + '@mdit/plugin-stylize', + '@mdit/plugin-sub', + '@mdit/plugin-sup', + ], +}) diff --git a/plugins/markdown/plugin-markdown-stylize/src/node/index.ts b/plugins/markdown/plugin-markdown-stylize/src/node/index.ts new file mode 100644 index 000000000..3bb01fbdf --- /dev/null +++ b/plugins/markdown/plugin-markdown-stylize/src/node/index.ts @@ -0,0 +1,2 @@ +export * from './markdownStylizePlugin.js' +export type * from './options.js' diff --git a/plugins/markdown/plugin-markdown-stylize/src/node/markdownStylizePlugin.ts b/plugins/markdown/plugin-markdown-stylize/src/node/markdownStylizePlugin.ts new file mode 100644 index 000000000..0217e610a --- /dev/null +++ b/plugins/markdown/plugin-markdown-stylize/src/node/markdownStylizePlugin.ts @@ -0,0 +1,43 @@ +import { align as alignPlugin } from '@mdit/plugin-align' +import { attrs as attrsPlugin } from '@mdit/plugin-attrs' +import { mark as markPlugin } from '@mdit/plugin-mark' +import { spoiler as spoilerPlugin } from '@mdit/plugin-spoiler' +import { stylize as stylizePlugin } from '@mdit/plugin-stylize' +import { sub as subPlugin } from '@mdit/plugin-sub' +import { sup as supPlugin } from '@mdit/plugin-sup' +import type { Plugin } from 'vuepress/core' +import type { MarkdownEnv } from 'vuepress/markdown' +import { isPlainObject } from 'vuepress/shared' +import type { MarkdownStylizePluginOptions } from './options.js' +import { prepareConfigFile } from './prepareConfigFile.js' + +export const markdownStylizePlugin = ({ + attrs, + align, + mark, + spoiler, + sup, + sub, + stylize, +}: MarkdownStylizePluginOptions): Plugin => { + return { + name: '@vuepress/plugin-markdown-stylize', + + extendsMarkdown: (md) => { + if (attrs) md.use(attrsPlugin, isPlainObject(attrs) ? attrs : {}) + if (align) md.use(alignPlugin) + if (mark) md.use(markPlugin) + if (spoiler) md.use(spoilerPlugin) + if (sub) md.use(subPlugin) + if (sup) md.use(supPlugin) + if (stylize) + md.use(stylizePlugin, { + config: stylize, + localConfigGetter: (env: MarkdownEnv) => + env.frontmatter?.stylize || null, + }) + }, + + clientConfigFile: spoiler ? (app) => prepareConfigFile(app) : undefined, + } +} diff --git a/plugins/markdown/plugin-markdown-stylize/src/node/options.ts b/plugins/markdown/plugin-markdown-stylize/src/node/options.ts new file mode 100644 index 000000000..bd060159b --- /dev/null +++ b/plugins/markdown/plugin-markdown-stylize/src/node/options.ts @@ -0,0 +1,65 @@ +import type { MarkdownItAttrsOptions } from '@mdit/plugin-attrs' +import type { MarkdownItStylizeConfig } from '@mdit/plugin-stylize' + +export interface MarkdownStylizePluginOptions { + /** + * Whether to enable align support + * + * 是否启用自定义对齐支持。 + * + * @default false + */ + align?: boolean + + /** + * Whether to enable attr support + * + * 是否启用属性支持。 + * + * @default false + */ + attrs?: MarkdownItAttrsOptions | boolean + + /** + * Whether to enable superscript format support + * + * 是否启用上角标格式支持。 + * + * @default false + */ + sup?: boolean + + /** + * Whether to enable subscript format support + * + * 是否启用下角标格式支持。 + * + * @default false + */ + sub?: boolean + + /** + * Whether to enable mark format support + * + * 是否启用标注支持。 + * + * @default false + */ + mark?: boolean + + /** + * Whether to enable spoiler support + * + * 是否启用剧透支持 + * + * @default false + */ + spoiler?: boolean + + /** + * Keyword enhancement + * + * 关键词显示增强选项 + */ + stylize?: MarkdownItStylizeConfig +} diff --git a/plugins/markdown/plugin-markdown-stylize/src/node/prepareConfigFile.ts b/plugins/markdown/plugin-markdown-stylize/src/node/prepareConfigFile.ts new file mode 100644 index 000000000..95a349964 --- /dev/null +++ b/plugins/markdown/plugin-markdown-stylize/src/node/prepareConfigFile.ts @@ -0,0 +1,12 @@ +import { getRealPath } from '@vuepress/helper' +import type { App } from 'vuepress' + +const { url } = import.meta + +export const prepareConfigFile = (app: App): Promise => + app.writeTemp( + `markdown-ext/config.js`, + `\ +import "${getRealPath('@mdit/plugin-spoiler/style', url)}"; +`, + ) diff --git a/plugins/markdown/plugin-markdown-stylize/tsconfig.build.json b/plugins/markdown/plugin-markdown-stylize/tsconfig.build.json new file mode 100644 index 000000000..85b37d29a --- /dev/null +++ b/plugins/markdown/plugin-markdown-stylize/tsconfig.build.json @@ -0,0 +1,9 @@ +{ + "extends": "../../../tsconfig.build.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "./lib" + }, + "include": ["./src"], + "references": [{ "path": "../../../tools/helper/tsconfig.build.json" }] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index abdf37cea..e47ca7e74 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -745,6 +745,43 @@ importers: specifier: ^14.1.0 version: 14.1.0 + plugins/markdown/plugin-markdown-stylize: + dependencies: + '@mdit/plugin-align': + specifier: ^0.13.1 + version: 0.13.1(markdown-it@14.1.0) + '@mdit/plugin-attrs': + specifier: ^0.13.1 + version: 0.13.1(markdown-it@14.1.0) + '@mdit/plugin-mark': + specifier: ^0.13.1 + version: 0.13.1(markdown-it@14.1.0) + '@mdit/plugin-spoiler': + specifier: ^0.13.1 + version: 0.13.1(markdown-it@14.1.0) + '@mdit/plugin-stylize': + specifier: ^0.13.1 + version: 0.13.1(markdown-it@14.1.0) + '@mdit/plugin-sub': + specifier: ^0.13.1 + version: 0.13.1(markdown-it@14.1.0) + '@mdit/plugin-sup': + specifier: ^0.13.1 + version: 0.13.1(markdown-it@14.1.0) + '@types/markdown-it': + specifier: ^14.1.2 + version: 14.1.2 + '@vuepress/helper': + specifier: workspace:* + version: link:../../../tools/helper + vuepress: + specifier: 2.0.0-rc.18 + version: 2.0.0-rc.18(@vuepress/bundler-vite@2.0.0-rc.18(@types/node@22.7.7)(jiti@1.21.6)(lightningcss@1.27.0)(sass-embedded@1.80.3)(sass@1.80.3)(terser@5.36.0)(tsx@4.19.1)(typescript@5.6.3)(yaml@2.4.5))(@vuepress/bundler-webpack@2.0.0-rc.18(esbuild@0.23.1)(typescript@5.6.3))(typescript@5.6.3)(vue@3.5.12(typescript@5.6.3)) + devDependencies: + markdown-it: + specifier: ^14.1.0 + version: 14.1.0 + plugins/markdown/plugin-markdown-tab: dependencies: '@mdit/plugin-tab': @@ -2390,6 +2427,24 @@ packages: markdown-it: optional: true + '@mdit/plugin-align@0.13.1': + resolution: {integrity: sha512-g8je53oEpYNHEudhtB5ViSiAaiMcca+hvoGbInhLl979tWuvEosOs0oWH2X3GM4f6goTGx8gLwzA10Z5C4FxIQ==} + engines: {node: '>= 18'} + peerDependencies: + markdown-it: ^14.1.0 + peerDependenciesMeta: + markdown-it: + optional: true + + '@mdit/plugin-attrs@0.13.1': + resolution: {integrity: sha512-3saBw5W2y3T0QNbui+uk7nfD36FOoBWNQImk+pbMGpKRqunjouiYP4ZtnttT/AiieGbZBVaOqhM4e01Uyua8VA==} + engines: {node: '>= 18'} + peerDependencies: + markdown-it: ^14.1.0 + peerDependenciesMeta: + markdown-it: + optional: true + '@mdit/plugin-container@0.13.1': resolution: {integrity: sha512-mFfm7YViyLHo8uORVa9oLi9+acZZoSVdPf3WPqzC/yLZAJbF27rfJgWZ9Kylt+tyaAYng8L4DiSeVcSNUIHF1A==} engines: {node: '>= 18'} @@ -2453,6 +2508,15 @@ packages: markdown-it: optional: true + '@mdit/plugin-mark@0.13.1': + resolution: {integrity: sha512-UV+7cSY8iQXlfnrIJ/gEpgwiL2SSVzVLtaWMOV0J4tRSsdtN8ZXnJn/gC547SxBaOLIkt+0ObSskXaCH/UzuIA==} + engines: {node: '>= 18'} + peerDependencies: + markdown-it: ^14.1.0 + peerDependenciesMeta: + markdown-it: + optional: true + '@mdit/plugin-mathjax-slim@0.13.1': resolution: {integrity: sha512-ZFtKG2BtLAk1BarJZei9HP4aK0vNU7YvDb+R+nApK7MRmLQ53xHe7upu3qlfNBoOZWHXsdRmcz0G4xL3oxzlqA==} engines: {node: '>= 18'} @@ -2465,6 +2529,42 @@ packages: mathjax-full: optional: true + '@mdit/plugin-spoiler@0.13.1': + resolution: {integrity: sha512-6aOD+kjGavkn+Ta0Iq8AUfBG3UsKsL5e0pxi0Eng13lIEp8DrDw36W+E6fLOFtX8Te3ays6eTkTc1I5WzHO0Gw==} + engines: {node: '>= 18'} + peerDependencies: + markdown-it: ^14.1.0 + peerDependenciesMeta: + markdown-it: + optional: true + + '@mdit/plugin-stylize@0.13.1': + resolution: {integrity: sha512-1v+3H1nMMvXsbu6iyV1pQ7WccrRNkuHovkIAp04Vj0FtbjnKrBHlmzFZace5OaD2RcZ0fn6qRpyR+/AIMjUvtQ==} + engines: {node: '>= 18'} + peerDependencies: + markdown-it: ^14.1.0 + peerDependenciesMeta: + markdown-it: + optional: true + + '@mdit/plugin-sub@0.13.1': + resolution: {integrity: sha512-2rIvEl6pXUoXIm3JMO5ZOQ+vWIeFXmLkqxcmTZB2yOIfhYdLwIcSyquRwtI2AX8zCuvaTdiQ/aypvIE4tDoURw==} + engines: {node: '>= 18'} + peerDependencies: + markdown-it: ^14.1.0 + peerDependenciesMeta: + markdown-it: + optional: true + + '@mdit/plugin-sup@0.13.1': + resolution: {integrity: sha512-vkNif2Rbj7/gtk4/HJt5hnb+Dcbnek/V4HtLdtqUUnq9bIbzFBpYw5jZ1ZKKZeetDtRvOUPH5oy5d7iXAHorUg==} + engines: {node: '>= 18'} + peerDependencies: + markdown-it: ^14.1.0 + peerDependenciesMeta: + markdown-it: + optional: true + '@mdit/plugin-tab@0.13.2': resolution: {integrity: sha512-evpIXvo6vXRWhgNE6vu4ok1I2dVOzrBYmBUGc1gW8nT9MvkW9litu7RbJ6CafscqaiiYRIM5Oib1ahS0lwte6g==} peerDependencies: @@ -9765,6 +9865,19 @@ snapshots: optionalDependencies: markdown-it: 14.1.0 + '@mdit/plugin-align@0.13.1(markdown-it@14.1.0)': + dependencies: + '@mdit/plugin-container': 0.13.1(markdown-it@14.1.0) + '@types/markdown-it': 14.1.2 + optionalDependencies: + markdown-it: 14.1.0 + + '@mdit/plugin-attrs@0.13.1(markdown-it@14.1.0)': + dependencies: + '@types/markdown-it': 14.1.2 + optionalDependencies: + markdown-it: 14.1.0 + '@mdit/plugin-container@0.13.1(markdown-it@14.1.0)': dependencies: '@types/markdown-it': 14.1.2 @@ -9809,6 +9922,12 @@ snapshots: katex: 0.16.11 markdown-it: 14.1.0 + '@mdit/plugin-mark@0.13.1(markdown-it@14.1.0)': + dependencies: + '@types/markdown-it': 14.1.2 + optionalDependencies: + markdown-it: 14.1.0 + '@mdit/plugin-mathjax-slim@0.13.1(markdown-it@14.1.0)(mathjax-full@3.2.2)': dependencies: '@mdit/plugin-tex': 0.13.1(markdown-it@14.1.0) @@ -9818,6 +9937,30 @@ snapshots: markdown-it: 14.1.0 mathjax-full: 3.2.2 + '@mdit/plugin-spoiler@0.13.1(markdown-it@14.1.0)': + dependencies: + '@types/markdown-it': 14.1.2 + optionalDependencies: + markdown-it: 14.1.0 + + '@mdit/plugin-stylize@0.13.1(markdown-it@14.1.0)': + dependencies: + '@types/markdown-it': 14.1.2 + optionalDependencies: + markdown-it: 14.1.0 + + '@mdit/plugin-sub@0.13.1(markdown-it@14.1.0)': + dependencies: + '@types/markdown-it': 14.1.2 + optionalDependencies: + markdown-it: 14.1.0 + + '@mdit/plugin-sup@0.13.1(markdown-it@14.1.0)': + dependencies: + '@types/markdown-it': 14.1.2 + optionalDependencies: + markdown-it: 14.1.0 + '@mdit/plugin-tab@0.13.2(markdown-it@14.1.0)': dependencies: '@types/markdown-it': 14.1.2 diff --git a/tsconfig.build.json b/tsconfig.build.json index 1076a9fe3..32e9c295e 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -52,6 +52,9 @@ }, { "path": "./plugins/markdown/plugin-markdown-image/tsconfig.build.json" }, { "path": "./plugins/markdown/plugin-markdown-math/tsconfig.build.json" }, + { + "path": "./plugins/markdown/plugin-markdown-stylize/tsconfig.build.json" + }, { "path": "./plugins/markdown/plugin-markdown-tab/tsconfig.build.json" }, { "path": "./plugins/markdown/plugin-prismjs/tsconfig.build.json"