diff --git a/packages/nutui-vite-plugins/package.json b/packages/nutui-vite-plugins/package.json index 672a144685..3796932c3b 100644 --- a/packages/nutui-vite-plugins/package.json +++ b/packages/nutui-vite-plugins/package.json @@ -31,12 +31,12 @@ "license": "MIT", "dependencies": { "fs-extra": "^11.2.0", - "highlight.js": "^11.9.0", "lzutf8": "^0.6.3", "markdown-it-container": "^4.0.0", "unplugin-vue-markdown": "^0.26.0" }, "devDependencies": { + "@shikijs/markdown-it": "^1.2.0", "@types/fs-extra": "^11.0.4", "@types/markdown-it-container": "^2.0.9", "tsup": "^8.0.2", diff --git a/packages/nutui-vite-plugins/src/markdown.ts b/packages/nutui-vite-plugins/src/markdown.ts index 4050ecb3aa..28567ab692 100644 --- a/packages/nutui-vite-plugins/src/markdown.ts +++ b/packages/nutui-vite-plugins/src/markdown.ts @@ -1,6 +1,6 @@ import Markdown from 'unplugin-vue-markdown/vite'; import MarkdownIt from 'markdown-it-container'; -import hljs from 'highlight.js'; +import Shiki from '@shikijs/markdown-it'; import LZUTF8 from 'lzutf8'; import fs from 'fs-extra'; import path from 'path'; @@ -60,17 +60,9 @@ export default function markdown(options: MarkdownOptions) { TransformMarkdownDemo(options), Markdown({ markdownItOptions: { - typographer: false, - highlight: function (str, lang) { - if (lang && (lang === 'vue' || hljs.getLanguage(lang))) { - return hljs.highlight(str, { - language: lang === 'vue' ? 'html' : lang - }).value; - } - return ''; - } + typographer: false }, - markdownItSetup(md) { + markdownItSetup: async (md) => { md.use(MarkdownIt, 'demo', { validate: function (params: any) { return params.match(/^demo\s*(.*)$/); @@ -87,6 +79,14 @@ export default function markdown(options: MarkdownOptions) { } } }); + md.use( + await Shiki({ + themes: { + light: 'github-light', + dark: 'github-dark' + } + }) + ); } }) ]; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3e2491328a..54afc51239 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -299,9 +299,6 @@ importers: fs-extra: specifier: ^11.2.0 version: 11.2.0 - highlight.js: - specifier: ^11.9.0 - version: 11.9.0 lzutf8: specifier: ^0.6.3 version: 0.6.3 @@ -312,6 +309,9 @@ importers: specifier: ^0.26.0 version: 0.26.0(vite@5.1.6) devDependencies: + '@shikijs/markdown-it': + specifier: ^1.2.0 + version: 1.2.0 '@types/fs-extra': specifier: ^11.0.4 version: 11.0.4 @@ -2529,6 +2529,24 @@ packages: requiresBuild: true optional: true + /@shikijs/core@1.2.0: + resolution: {integrity: sha512-OlFvx+nyr5C8zpcMBnSGir0YPD6K11uYhouqhNmm1qLiis4GA7SsGtu07r9gKS9omks8RtQqHrJL4S+lqWK01A==} + dev: true + + /@shikijs/markdown-it@1.2.0: + resolution: {integrity: sha512-XH+Qg4yJtEPe1S8tzRkeIKNu6G/6YlipISqzVuOxU5IpNEMAiEd40NHeU7XKpQsTVwJ2+rhMPaXKF4Ohz/Rrkg==} + dependencies: + '@shikijs/transformers': 1.2.0 + markdown-it: 14.0.0 + shiki: 1.2.0 + dev: true + + /@shikijs/transformers@1.2.0: + resolution: {integrity: sha512-xKn7DtA65DQV4FOfYsrvqM80xOy2xuXnxWWKsZmHv1VII/IOuDUDsWDu3KnpeLH6wqNJWp1GRoNUsHR1aw/VhQ==} + dependencies: + shiki: 1.2.0 + dev: true + /@sideway/address@4.1.4: resolution: {integrity: sha512-7vwq+rOHVWjyXxVlR76Agnvhy8I9rpzjosTESvmhNeXOXdZZB15Fl+TI9x1SiHZH5Jv2wTGduSxFDIaq0m3DUw==} dependencies: @@ -8859,11 +8877,6 @@ packages: resolution: {integrity: sha512-tzcUFauisWKNHaRkN4Wjl/ZA07gENAjFl3J/c480dprkGTg5EQstgaNFqBfUqCq54kZRIEcreTsAgF/m2quD7A==} dev: true - /highlight.js@11.9.0: - resolution: {integrity: sha512-fJ7cW7fQGCYAkgv4CPfwFHrfd/cLS4Hau96JuJ+ZTOWhjnhoeN1ub1tFmALm/+lW5z4WCAuAV9bm05AP0mS6Gw==} - engines: {node: '>=12.0.0'} - dev: false - /history@5.3.0: resolution: {integrity: sha512-ZqaKwjjrAYUYfLG+htGaIIZ4nioX2L70ZUMIFysS3xvBsSG4x/n1V6TXV3N8ZYNuFGlDirFg32T7B6WOUPDYcQ==} dependencies: @@ -13360,6 +13373,12 @@ packages: resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} engines: {node: '>=8'} + /shiki@1.2.0: + resolution: {integrity: sha512-xLhiTMOIUXCv5DqJ4I70GgQCtdlzsTqFLZWcMHHG3TAieBUbvEGthdrlPDlX4mL/Wszx9C6rEcxU6kMlg4YlxA==} + dependencies: + '@shikijs/core': 1.2.0 + dev: true + /shortid@2.2.16: resolution: {integrity: sha512-Ugt+GIZqvGXCIItnsL+lvFJOiN7RYqlGy7QE41O3YC1xbNSeDGIRO7xg2JJXIAj1cAGnOeC1r7/T9pgrtQbv4g==} deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. diff --git a/src/sites/assets/styles/highlight.scss b/src/sites/assets/styles/highlight.scss index 5e0f85c795..4501050cde 100644 --- a/src/sites/assets/styles/highlight.scss +++ b/src/sites/assets/styles/highlight.scss @@ -26,79 +26,3 @@ pre { margin-top: 20px; } } - -.hljs { - display: block; - padding: 30px; - overflow-x: auto; - background: #f7f8fa; -} - -.hljs-comment, -.hljs-quote { - color: #a0a1a7; - font-style: italic; -} - -.hljs-doctag, -.hljs-formula, -.hljs-keyword { - color: #a626a4; -} - -.hljs-deletion, -.hljs-name, -.hljs-section, -.hljs-selector-tag, -.hljs-subst { - color: #e45649; -} - -.hljs-literal { - color: #0184bb; -} - -.hljs-addition, -.hljs-attribute, -.hljs-meta-string, -.hljs-regexp, -.hljs-string { - color: #50a14f; -} - -.hljs-built_in, -.hljs-class .hljs-title { - color: #c18401; -} - -.hljs-attr, -.hljs-number, -.hljs-selector-attr, -.hljs-selector-class, -.hljs-selector-pseudo, -.hljs-template-variable, -.hljs-type, -.hljs-variable { - color: #986801; -} - -.hljs-bullet, -.hljs-link, -.hljs-meta, -.hljs-selector-id, -.hljs-symbol, -.hljs-title { - color: #4078f2; -} - -.hljs-emphasis { - font-style: italic; -} - -.hljs-strong { - font-weight: 700; -} - -.hljs-link { - text-decoration: underline; -}