├── .editorconfig ├── .eslintrc.js ├── .gitignore ├── LICENSE ├── README-zh_CN.md ├── README.md ├── lerna.json ├── package.json └── packages ├── vuepress-plugin-dumi-previewer ├── README-zh_CN.md ├── README.md ├── package.json └── src │ ├── Previewer.vue │ ├── enhanceAppFile.js │ ├── highlight.js │ └── index.js └── vuepress-theme-dumi ├── README-zh_CN.md ├── README.md ├── components ├── AlgoliaSearchBox.vue ├── DropdownLink.vue ├── DropdownTransition.vue ├── Home.vue ├── NavLink.vue ├── NavLinks.vue ├── Navbar.vue ├── Page.vue ├── PageEdit.vue ├── PageNav.vue ├── Sidebar.vue ├── SidebarButton.vue ├── SidebarGroup.vue ├── SidebarLink.vue └── SidebarLinks.vue ├── global-components ├── Badge.vue ├── CodeBlock.vue └── CodeGroup.vue ├── index.js ├── layouts ├── 404.vue └── Layout.vue ├── noopModule.js ├── package.json ├── styles ├── arrow.styl ├── code.styl ├── config.styl ├── custom-blocks.styl ├── index.styl ├── mobile.styl ├── palette.styl ├── toc.styl └── wrapper.styl └── util └── index.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | end_of_line = lf 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true 11 | 12 | [*.md] 13 | insert_final_newline = false 14 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = { 3 | env: { 4 | browser: true, 5 | node: true, 6 | es6: true 7 | }, 8 | extends: [ 9 | 'standard', 10 | 'plugin:vue/essential' 11 | ], 12 | plugins: [ 13 | 'vue' 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn-error.log 3 | .idea 4 | yarn.lock 5 | .DS_Store 6 | .vscode 7 | package-lock.json -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Oreki S.H. 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 | -------------------------------------------------------------------------------- /README-zh_CN.md: -------------------------------------------------------------------------------- 1 |

vuepress-theme-dumi

2 | 3 | 📖 适配VuePress的dumi样式主题. 4 | 5 | English | 简体中文 6 | 7 | ## 安装 8 | 9 | * 首先安装 [VuePress v1.x](https://github.com/vuejs/vuepress) 10 | 11 | * 接着安装主题 12 | 13 | ```bash 14 | $ npm i -D @vuepress-dumi/vuepress-theme-dumi 15 | # OR 16 | $ yarn add -D @vuepress-dumi/vuepress-theme-dumi 17 | ``` 18 | 19 | ## 用法 20 | 21 | 配置VuePress的config.js文件 22 | 23 | ```js 24 | // .vuepress/config.js 25 | module.exports = { 26 | theme: '@vuepress-dumi/dumi', 27 | } 28 | ``` 29 | 30 | ## 预览 31 | 32 | ![PC模式](https://s3.ax1x.com/2021/02/12/yDNldg.png) 33 | ![手机模式](https://s3.ax1x.com/2021/02/12/yDUi60.png) 34 | ![代码预览](https://s3.ax1x.com/2021/02/12/yDNgQx.png) 35 | 36 | 💡注意: 如果你需要引入element-ui, 则需要指定async-validator的版本: 37 | 38 | ``` bash 39 | $ npm i -D async-validator@1.11.5 40 | # OR 41 | $ yarn add -D async-validator@1.11.5 42 | ``` 43 | 44 | ## 代码预览器用法 45 | 46 | 💡注意: `demo`之前的空格是必需的 47 | 48 | ```md 49 | ::: demo 50 |
click me
51 | 52 | 61 | ::: 62 | ``` 63 | 64 | 如果你需要将代码限制在当前代码块的作用域内, 可以使用`demo[scope]` 65 | 66 | 💡注意: ``标签是必需的, 并且你不能在scope模式下使用`import`语句。另外如果你在一个markdown文件中同时使用`demo[scope]`和`demo`,可能会出现一些报错 67 | 68 | ```md 69 | ::: demo[scope] 70 | 73 | 74 | 81 | ::: 82 | ``` 83 | 84 | ```md 85 | ::: demo[scope] 86 | 89 | 90 | 97 | ::: 98 | ``` -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

vuepress-theme-dumi

2 | 3 | 📖 A dumi style theme for VuePress. 4 | 5 | English | 简体中文 6 | 7 | ## Install 8 | 9 | * First of all, install [vuepress v1.x](https://github.com/vuejs/vuepress) 10 | 11 | * Then install the theme 12 | 13 | ```bash 14 | $ npm i -D @vuepress-dumi/vuepress-theme-dumi 15 | # OR 16 | $ yarn add -D @vuepress-dumi/vuepress-theme-dumi 17 | ``` 18 | 19 | ## Usage 20 | Write vuepress config 21 | 22 | ```js 23 | // .vuepress/config.js 24 | module.exports = { 25 | theme: '@vuepress-dumi/dumi', 26 | } 27 | ``` 28 | 29 | ## Preview 30 | 31 | ![pc mode](https://s3.ax1x.com/2021/02/12/yDNldg.png) 32 | ![mobile mode](https://s3.ax1x.com/2021/02/12/yDUi60.png) 33 | ![code previewer](https://s3.ax1x.com/2021/02/12/yDNgQx.png) 34 | 35 | 💡attention: if you want to import element-ui like me, you need install async-validator@1.11.5 36 | 37 | ``` bash 38 | $ npm i -D async-validator@1.11.5 39 | # OR 40 | $ yarn add -D async-validator@1.11.5 41 | ``` 42 | 43 | ## Code Previewer Usage 44 | 45 | 💡attention: whitespace is in need before `demo` 46 | 47 | ```md 48 | ::: demo 49 |
click me
50 | 51 | 60 | ::: 61 | ``` 62 | 63 | If you need code scope, you can use `demo[scope]`. 64 | 65 | 💡attention: `` is in need, and you can not use `import` statment in scope mode. And if you use `demo[scope]` and `demo` in one markdown file, browser may print some error. 66 | 67 | ```md 68 | ::: demo[scope] 69 | 72 | 73 | 80 | ::: 81 | ``` 82 | 83 | ```md 84 | ::: demo[scope] 85 | 88 | 89 | 96 | ::: 97 | ``` -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | "packages/*" 4 | ], 5 | "version": "0.3.8" 6 | } 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "version": "0.3.7", 4 | "workspaces": [ 5 | "packages/*" 6 | ], 7 | "devDependencies": { 8 | "eslint": "^7.19.0", 9 | "eslint-config-standard": "^16.0.2", 10 | "eslint-plugin-import": "^2.22.1", 11 | "eslint-plugin-node": "^11.1.0", 12 | "eslint-plugin-promise": "^4.2.1", 13 | "eslint-plugin-vue": "^7.5.0", 14 | "husky": "^4.3.8", 15 | "lerna": "^3.22.1", 16 | "lint-staged": "^10.5.4" 17 | }, 18 | "scripts": { 19 | "lint": "eslint --ext .js,.vue ./", 20 | "lintfix": "eslint --fix --ext .js,.vue ./", 21 | "patch": "node_modules/.bin/lerna version patch --no-git-tag-version" 22 | }, 23 | "lint-staged": { 24 | "*.{js,vue}": "npm run lint" 25 | }, 26 | "husky": { 27 | "hooks": { 28 | "pre-commit": "lint-staged" 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/vuepress-plugin-dumi-previewer/README-zh_CN.md: -------------------------------------------------------------------------------- 1 |

vuepress-plugin-dumi-previewer

2 | 3 | English | 简体中文 4 | 5 | 💡注意: `demo`之前的空格是必需的 6 | 7 | ```md 8 | ::: demo 9 |
click me
10 | 11 | 20 | ::: 21 | ``` 22 | 23 | 如果你需要将代码限制在当前代码块的作用域内, 可以使用`demo[scope]` 24 | 25 | 💡注意: ``标签是必需的, 并且你不能在scope模式下使用`import`语句。另外如果你在一个markdown文件中同时使用`demo[scope]`和`demo`,可能会出现一些报错 26 | 27 | ```md 28 | ::: demo[scope] 29 | 32 | 33 | 40 | ::: 41 | ``` 42 | 43 | ```md 44 | ::: demo[scope] 45 | 48 | 49 | 56 | ::: 57 | ``` 58 | 59 | ## 安装 60 | 61 | * 首先安装 [VuePress v1.x](https://github.com/vuejs/vuepress) 62 | 63 | * 接着安装插件 64 | 65 | ```bash 66 | $ npm i -D @vuepress-dumi/vuepress-plugin-dumi-previewer 67 | # OR 68 | $ yarn add -D @vuepress-dumi/vuepress-plugin-dumi-previewer 69 | ``` 70 | 71 | ## 用法 72 | 73 | 配置VuePress的config.js文件 74 | 75 | ```js 76 | // .vuepress/config.js 77 | module.exports = { 78 | plugins: ['@vuepress-dumi/dumi-previewer'], 79 | } 80 | ``` 81 | 82 | ## 预览 83 | 84 | ![代码预览](https://s3.ax1x.com/2021/02/12/yDNgQx.png) 85 | 86 | 💡注意: 如果你需要引入element-ui, 则需要指定async-validator的版本: 87 | 88 | ``` bash 89 | $ npm i -D async-validator@1.11.5 90 | # OR 91 | $ yarn add -D async-validator@1.11.5 92 | ``` 93 | 94 | ## 致谢 95 | 96 | 本项目受到以下开源项目的启发, 感谢他们的杰出贡献 97 | 98 | - [dumi](https://github.com/umijs/dumi) 99 | - [vuepress-plugin-demo-code](https://github.com/BuptStEve/vuepress-plugin-demo-code) -------------------------------------------------------------------------------- /packages/vuepress-plugin-dumi-previewer/README.md: -------------------------------------------------------------------------------- 1 |

vuepress-plugin-dumi-previewer

2 | 3 | English | 简体中文 4 | 5 | 💡attention: whitespace is in need before `demo` 6 | 7 | ```md 8 | ::: demo 9 |
click me
10 | 11 | 20 | ::: 21 | ``` 22 | 23 | If you need code scope, you can use `demo[scope]`. 24 | 25 | 💡attention: `` is in need, and you can not use `import` statment in scope mode. And if you use `demo[scope]` and `demo` in one markdown file, browser may print some error. 26 | 27 | ```md 28 | ::: demo[scope] 29 | 32 | 33 | 40 | ::: 41 | ``` 42 | 43 | ```md 44 | ::: demo[scope] 45 | 48 | 49 | 56 | ::: 57 | ``` 58 | 59 | ## Install 60 | 61 | * First of all, install [vuepress v1.x](https://github.com/vuejs/vuepress) 62 | 63 | * Then install the plugin 64 | 65 | ```bash 66 | $ npm i -D @vuepress-dumi/vuepress-plugin-dumi-previewer 67 | # OR 68 | $ yarn add -D @vuepress-dumi/vuepress-plugin-dumi-previewer 69 | ``` 70 | 71 | ## Usage 72 | Write vuepress config 73 | 74 | ```js 75 | // .vuepress/config.js 76 | module.exports = { 77 | plugins: ['@vuepress-dumi/dumi-previewer'], 78 | } 79 | ``` 80 | 81 | ## Preview 82 | 83 | ![code previewer](https://s3.ax1x.com/2021/02/12/yDNgQx.png) 84 | 85 | 💡attention: if you want to import element-ui like me, you need install async-validator@1.11.5 86 | 87 | ``` bash 88 | $ npm i -D async-validator@1.11.5 89 | # OR 90 | $ yarn add -D async-validator@1.11.5 91 | ``` 92 | 93 | ## Thanks 94 | 95 | This repo is inspired by the following projects, Thanks for their great work. 96 | 97 | - [dumi](https://github.com/umijs/dumi) 98 | - [vuepress-plugin-demo-code](https://github.com/BuptStEve/vuepress-plugin-demo-code) -------------------------------------------------------------------------------- /packages/vuepress-plugin-dumi-previewer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@vuepress-dumi/vuepress-plugin-dumi-previewer", 3 | "version": "0.3.11", 4 | "description": "A dumi style code previewer plugin for VuePress.", 5 | "keywords": [ 6 | "vue", 7 | "vuepress", 8 | "plugin", 9 | "documentation", 10 | "dumi", 11 | "code", 12 | "previewer" 13 | ], 14 | "author": "OrekiSH ", 15 | "homepage": "https://github.com/OrekiSH/vuepress-dumi", 16 | "license": "MIT", 17 | "main": "src/index.js", 18 | "repository": { 19 | "type": "git", 20 | "url": "git+https://github.com/OrekiSH/vuepress-dumi.git", 21 | "directory": "packages/vuepress-plugin-dumi-previewer" 22 | }, 23 | "publishConfig": { 24 | "access": "public" 25 | }, 26 | "bugs": { 27 | "url": "https://github.com/OrekiSH/vuepress-dumi/issues" 28 | }, 29 | "dependencies": { 30 | "@babel/standalone": "^7.14.0", 31 | "@vuepress/markdown": "^1.8.0", 32 | "babel-helper-vue-jsx-merge-props": "^2.0.3", 33 | "babel-plugin-syntax-jsx": "^6.18.0", 34 | "babel-plugin-transform-vue-jsx": "^3.7.0", 35 | "copy-to-clipboard": "^3.3.1", 36 | "markdown-it-container": "^3.0.0", 37 | "vue-template-compiler": "^2.6.12" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /packages/vuepress-plugin-dumi-previewer/src/Previewer.vue: -------------------------------------------------------------------------------- 1 | 49 | 50 | 171 | 172 | 259 | -------------------------------------------------------------------------------- /packages/vuepress-plugin-dumi-previewer/src/enhanceAppFile.js: -------------------------------------------------------------------------------- 1 | import Previewer from './Previewer.vue' 2 | 3 | export default ({ Vue }) => { 4 | Vue.component('Previewer', Previewer) 5 | } 6 | -------------------------------------------------------------------------------- /packages/vuepress-plugin-dumi-previewer/src/highlight.js: -------------------------------------------------------------------------------- 1 | const prism = require('prismjs') 2 | const escapeHtml = require('escape-html') 3 | const loadLanguages = require('prismjs/components/index') 4 | 5 | function wrap (code, lang) { 6 | if (lang === 'text') { 7 | code = escapeHtml(code) 8 | } 9 | return `
${code}
` 10 | } 11 | 12 | function getLangCodeFromExtension (extension) { 13 | const extensionMap = { 14 | vue: 'markup', 15 | html: 'markup', 16 | md: 'markdown', 17 | rb: 'ruby', 18 | ts: 'typescript', 19 | py: 'python', 20 | sh: 'bash', 21 | yml: 'yaml', 22 | styl: 'stylus', 23 | kt: 'kotlin', 24 | rs: 'rust' 25 | } 26 | 27 | return extensionMap[extension] || extension 28 | } 29 | 30 | module.exports = (str, lang) => { 31 | if (!lang) { 32 | return wrap(str, 'text') 33 | } 34 | lang = lang.toLowerCase() 35 | const rawLang = lang 36 | 37 | lang = getLangCodeFromExtension(lang) 38 | 39 | if (!prism.languages[lang]) { 40 | try { 41 | loadLanguages([lang]) 42 | } catch (e) { 43 | console.warn(`[vuepress] Syntax highlight for language "${lang}" is not supported.`) 44 | } 45 | } 46 | if (prism.languages[lang]) { 47 | const code = prism.highlight(str, prism.languages[lang], lang) 48 | return wrap(code, rawLang) 49 | } 50 | return wrap(str, 'text') 51 | } 52 | -------------------------------------------------------------------------------- /packages/vuepress-plugin-dumi-previewer/src/index.js: -------------------------------------------------------------------------------- 1 | const markdownItContainer = require('markdown-it-container') 2 | 3 | module.exports = (options = {}) => { 4 | const { marker = 'demo', scopeMaker = 'demo[scope]' } = options 5 | 6 | function render (tokens, idx, endType, scope) { 7 | const { nesting } = tokens[idx] 8 | 9 | if (nesting === -1) { 10 | return '\n' 11 | } 12 | 13 | let htmlStr = '' 14 | let lastLine = 0 15 | 16 | for (let index = idx; index < tokens.length; index++) { 17 | const { map, type, content } = tokens[index] 18 | 19 | if (type === endType) break 20 | 21 | // add empty lines 22 | if (map) { 23 | const delta = map[0] - (lastLine || map[1]) 24 | 25 | if (delta > 0) { 26 | htmlStr += '\n'.repeat(delta) 27 | } 28 | 29 | lastLine = map[1] 30 | } 31 | 32 | htmlStr += content 33 | } 34 | 35 | return ` 36 | 40 |