├── .github ├── dependabot.yml └── workflows │ ├── publish.yml │ └── release.yml ├── .gitignore ├── package.json ├── LICENSE ├── lib ├── themes.js ├── codeblock.js └── codeblock.css ├── pnpm-lock.yaml ├── CHANGELOG.md ├── README.md └── index.js /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: npm 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | open-pull-requests-limit: 20 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | .DS_Store 12 | dist 13 | dist-ssr 14 | coverage 15 | *.local 16 | 17 | /cypress/videos/ 18 | /cypress/screenshots/ 19 | 20 | # Editor directories and files 21 | .vscode/* 22 | !.vscode/extensions.json 23 | .idea 24 | *.suo 25 | *.ntvs* 26 | *.njsproj 27 | *.sln 28 | *.sw? -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: "Publish" 2 | 3 | on: 4 | push: 5 | tags: 6 | - "v*" 7 | 8 | jobs: 9 | npmjs_publish: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v3 14 | - name: Install Node.js 15 | uses: actions/setup-node@v3 16 | with: 17 | registry-url: "https://registry.npmjs.org" 18 | node-version: 16 19 | - name: Publish to npmjs 20 | run: npm publish 21 | env: 22 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hexo-shiki-plugin", 3 | "version": "1.0.27", 4 | "description": "A beautiful hexo code block highlight plugin based on shiki", 5 | "author": "nova1751", 6 | "license": "MIT", 7 | "main": "index.js", 8 | "scripts": { 9 | "test": "echo \"Error: no test specified\" && exit 1" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/nova1751/hexo-shiki-plugin.git" 14 | }, 15 | "bugs": { 16 | "url": "https://github.com/nova1751/hexo-shiki-plugin/issues" 17 | }, 18 | "homepage": "https://github.com/nova1751/hexo-shiki-plugin", 19 | "keywords": [ 20 | "hexo", 21 | "shiki", 22 | "code", 23 | "highlight", 24 | "butterfly", 25 | "hexo-theme-butterfly" 26 | ], 27 | "dependencies": { 28 | "shiki-nova1751": "^0.0.0", 29 | "strip-indent": "^3.0.0" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: "Release" 2 | 3 | on: 4 | push: 5 | tags: 6 | - "v*" 7 | 8 | jobs: 9 | tagged-release: 10 | runs-on: "ubuntu-latest" 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v3 14 | - name: Get current package version 15 | id: package_version 16 | uses: martinbeentjes/npm-get-version-action@v1.1.0 17 | - name: Get Changelog Entry 18 | id: changelog_reader 19 | uses: mindsers/changelog-reader-action@v2.0.0 20 | with: 21 | validation_level: warn 22 | version: ${{ steps.package_version.outputs.current-version }} 23 | path: "CHANGELOG.md" 24 | - name: Create a Release 25 | id: create_release 26 | uses: actions/create-release@v1 27 | env: 28 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 29 | with: 30 | tag_name: ${{ steps.package_version.outputs.current-version}} 31 | release_name: ${{ steps.package_version.outputs.current-version}} 32 | body: ${{ steps.changelog_reader.outputs.changes }} 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 nova1751 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /lib/themes.js: -------------------------------------------------------------------------------- 1 | const themes = new Map(); 2 | themes.set( 3 | "one-dark-pro", 4 | `` 5 | ); 6 | themes.set( 7 | "material-theme-palenight", 8 | `` 9 | ); 10 | themes.set( 11 | "github-light", 12 | `` 13 | ); 14 | themes.set( 15 | "github-dark", 16 | `` 17 | ); 18 | module.exports = themes; 19 | -------------------------------------------------------------------------------- /pnpm-lock.yaml: -------------------------------------------------------------------------------- 1 | lockfileVersion: '6.0' 2 | 3 | settings: 4 | autoInstallPeers: true 5 | excludeLinksFromLockfile: false 6 | 7 | dependencies: 8 | shiki-nova1751: 9 | specifier: ^0.0.0 10 | version: 0.0.0 11 | strip-indent: 12 | specifier: ^3.0.0 13 | version: 3.0.0 14 | 15 | packages: 16 | 17 | /ansi-sequence-parser@1.1.1: 18 | resolution: {integrity: sha512-vJXt3yiaUL4UU546s3rPXlsry/RnM730G1+HkpKE012AN0sx1eOrxSu95oKDIonskeLTijMgqWZ3uDEe3NFvyg==} 19 | dev: false 20 | 21 | /jsonc-parser@3.2.0: 22 | resolution: {integrity: sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==} 23 | dev: false 24 | 25 | /min-indent@1.0.1: 26 | resolution: {integrity: sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==} 27 | engines: {node: '>=4'} 28 | dev: false 29 | 30 | /shiki-nova1751@0.0.0: 31 | resolution: {integrity: sha512-6RK+IVNm+j5vPYsRP8Yv9M7dETcmQGO2T6sR2TWF64LgqiIc/zAt+yX+5lhTWegQ36nh1/t+YViX8ypZJGqdJA==} 32 | dependencies: 33 | ansi-sequence-parser: 1.1.1 34 | jsonc-parser: 3.2.0 35 | vscode-oniguruma: 1.7.0 36 | vscode-textmate: 8.0.0 37 | dev: false 38 | 39 | /strip-indent@3.0.0: 40 | resolution: {integrity: sha512-laJTa3Jb+VQpaC6DseHhF7dXVqHTfJPCRDaEbid/drOhgitgYku/letMUqOXFoWV0zIIUbjpdH2t+tYj4bQMRQ==} 41 | engines: {node: '>=8'} 42 | dependencies: 43 | min-indent: 1.0.1 44 | dev: false 45 | 46 | /vscode-oniguruma@1.7.0: 47 | resolution: {integrity: sha512-L9WMGRfrjOhgHSdOYgCt/yRMsXzLDJSL7BPrOZt73gU0iWO4mpqzqQzOz5srxqTvMBaR0XZTSrVWo4j55Rc6cA==} 48 | dev: false 49 | 50 | /vscode-textmate@8.0.0: 51 | resolution: {integrity: sha512-AFbieoL7a5LMqcnOF04ji+rpXadgOXnZsxQr//r83kLPr7biP7am3g9zbaZIaBGwBRWeSvoMD4mgPdX3e4NWBg==} 52 | dev: false 53 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [1.0.27] - 2024-6-15 4 | 5 | ### Style Update 6 | 7 | - Ajust the text style. @noraj 8 | 9 | ## [1.0.26] - 2024-6-15 10 | 11 | ### Style Update 12 | 13 | - Ajust the font style. 14 | 15 | ## [1.0.25] - 2024-1-25 16 | 17 | ### Bug Fixes 18 | 19 | - Add cutom CDN url. 20 | 21 | ## [1.0.24] - 2023-12-14 22 | 23 | ### Bug Fixes 24 | 25 | - Ajust the code font to adapt to the PC without consolas font. 26 | 27 | ## [1.0.23] - 2023-11-30 28 | 29 | ### Bug Fixes 30 | 31 | - Remove the tabindex attribute in codeblock. 32 | - Change dependency shiki to shiki-nova1751 to ajust the `vue` code highlight. 33 | 34 | ## [1.0.23] - 2023-11-30 35 | 36 | ### Bug Fixes 37 | 38 | - Remove the tabindex attribute in codeblock. 39 | - Change dependency shiki to shiki-nova1751 to ajust the `vue` code highlight. 40 | 41 | ## [1.0.22] - 2023-11-18 42 | 43 | ### Bug Fixes 44 | 45 | - Ajust the github-light theme style. 46 | 47 | ## [1.0.21] - 2023-11-18 48 | 49 | ### Bug Fixes 50 | 51 | - Fix the code block display problem in the blockquote. 52 | 53 | ## [1.0.20] - 2023-11-17 54 | 55 | ### New Features 56 | 57 | - For the languages not supported by shiki,`hexo-shiki-plugin` will display it as plain text and print the `error` message in the console. 58 | - Add `Clipboard` API to the copy function for better compatibility. 59 | 60 | ## [1.0.19] - 2023-11-16 61 | 62 | ### Chore 63 | 64 | - Remove the box-shadow style to adapt the dark-mode 65 | 66 | ## [1.0.18] - 2023-11-15 67 | 68 | ### New Features 69 | 70 | - Add line_number option to show or hide line_number. 71 | - Add the code highlight theme,for themes not built in,load the theme code in the `one-dark-pro` codeblock style. 72 | 73 | ### Bug Fixes 74 | 75 | - Change the table style to flex to avoid table wrap problems. 76 | - Use `em` unit to unify the code font size. 77 | 78 | ## [1.0.17] - 2023-11-14 79 | 80 | ### Chore 81 | 82 | - Simplify the code 83 | 84 | ## [1.0.16] - 2023-11-14 85 | 86 | ### Bug fixes 87 | 88 | - Remove the css class conflicts with theme butterfly 89 | - fix some style conflicts 90 | - update github workflow 91 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hexo Shiki Plugin 2 | 3 |

4 | NPM Version 9 | Build Status 15 | Hexo Version 21 | License 26 |

27 | 28 | > A code highlight plugin based on shiki,built for hexo.You can go to my [blog](https://blog.refrain.site) for preview. 29 | 30 | ## Installation 31 | 32 | 1. Intall the plugin. 33 | ```bash 34 | yarn add hexo-shiki-plugin 35 | ``` 36 | 2. Setup config. 37 | ```yml 38 | shiki: 39 | theme: one-dark-pro 40 | ``` 41 | 42 | > [!WARNING] 43 | > To avoid conflicts with the native code highlight plugin,please disable the native plugins. 44 | > 45 | > ```yml 46 | > highlight: 47 | > enable: false 48 | > prismjs: 49 | > enable: false 50 | > ``` 51 | > 52 | > for `hexo>=7.0.0` versions,please add a additional line,leave `syntax_highlighter` to empty,just like below. 53 | > 54 | > ```yml 55 | > syntax_highlighter: 56 | > ``` 57 | 58 | ## Usage 59 | 60 | > this plugin has four themes built in,you can choose one of theme to display: 61 | > 62 | > - `one-dark-pro` 63 | > - `material-theme-palenight` 64 | > - `github-light` 65 | > - `github-dark` 66 | 67 | If you choose a theme other than one of the built-in themes,the plugin will use the `one-dark-pro` codeblock style,and load the specific theme code.You can load more code highlight themes in [Themes](https://github.com/shikijs/shiki/blob/main/docs/themes.md). 68 | 69 | There are some other features ported from [hexo-theme-butterfly](https://github.com/jerryc127/hexo-theme-butterfly.git).The available settings are below: 70 | 71 | > [!NOTE] 72 | > If you want to enable the code block beautify config, please make sure your website has introduced the font-awesome icon set. 73 | 74 | ```yml 75 | shiki: 76 | theme: github-light # highlight-theme 77 | line_number: true # whether to show the line_number 78 | beautify: false # whether to add highlight tool true or false 79 | highlight_copy: true # copy button 80 | highlight_lang: false # show the code language 81 | highlight_height_limit: 360 # code-block max height,unit: px 82 | is_highlight_shrink: false # true: shrink the code blocks / false: expand the code blocks | none: expand code blocks and hide the button 83 | copy: # copy message 84 | success: 'Copy Success' 85 | error: 'Copy Error' 86 | no_support: 'Browser Not Support' 87 | ``` 88 | 89 | > [!NOTE] 90 | > Since shiki support a lot of beautiful themes,you can add your own cutom css files to cusomize your codeblock style,here is an example: 91 | 92 | ```css 93 | :root { 94 | --hl-color: #e1e4e8; 95 | --hl-bg: #24292e; 96 | --hltools-bg: #1f2428; 97 | --hltools-color: #c5c5c5; 98 | --hlnumber-bg: #24292e; 99 | --hlnumber-color: #444d56; 100 | --hlscrollbar-bg: #32383e; 101 | --hlexpand-bg: linear-gradient( 102 | 180deg, 103 | rgba(36, 41, 46, 0.6), 104 | rgba(36, 41, 46, 0.9) 105 | ); 106 | } 107 | ``` 108 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const shiki = require("shiki-nova1751"); 2 | const stripIndent = require("strip-indent"); 3 | const themes = require("./lib/themes"); 4 | const { version } = require("./package.json"); 5 | const codeMatch = 6 | /(?[> ]*)(?