{"id":15486548,"url":"https://github.com/buptsteve/vuepress-plugin-demo-code","last_synced_at":"2025-04-08T03:20:10.755Z","repository":{"id":34053031,"uuid":"167794752","full_name":"BuptStEve/vuepress-plugin-demo-code","owner":"BuptStEve","description":"📝 Demo and code plugin for vuepress","archived":false,"fork":false,"pushed_at":"2022-10-17T01:59:10.000Z","size":976,"stargazers_count":124,"open_issues_count":4,"forks_count":28,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-31T01:33:28.904Z","etag":null,"topics":["code","demo","vuepress","vuepress-plugin"],"latest_commit_sha":null,"homepage":"https://buptsteve.github.io/vuepress-plugin-demo-code/","language":"Vue","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BuptStEve.png","metadata":{"files":{"readme":"README-zh_CN.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-27T10:10:31.000Z","updated_at":"2024-11-01T21:51:15.000Z","dependencies_parsed_at":"2023-01-15T04:30:28.217Z","dependency_job_id":null,"html_url":"https://github.com/BuptStEve/vuepress-plugin-demo-code","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BuptStEve%2Fvuepress-plugin-demo-code","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BuptStEve%2Fvuepress-plugin-demo-code/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BuptStEve%2Fvuepress-plugin-demo-code/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BuptStEve%2Fvuepress-plugin-demo-code/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BuptStEve","download_url":"https://codeload.github.com/BuptStEve/vuepress-plugin-demo-code/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247767239,"owners_count":20992548,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code","demo","vuepress","vuepress-plugin"],"created_at":"2024-10-02T06:08:56.790Z","updated_at":"2025-04-08T03:20:10.717Z","avatar_url":"https://github.com/BuptStEve.png","language":"Vue","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003evuepress-plugin-demo-code\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/vuepress-plugin-demo-code\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://badgen.net/npm/dm/vuepress-plugin-demo-code\" alt=\"Downloads per month\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/vuepress-plugin-demo-code.svg\" alt=\"Version\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/vuepress-plugin-demo-code/next.svg\" alt=\"Next Version\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/l/vuepress-plugin-demo-code.svg\" alt=\"License\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003ca href=\"https://buptsteve.github.io/vuepress-plugin-demo-code/\"\u003eEnglish\u003c/a\u003e | 简体中文\n\n\u003e demo-code plugin for vuepress.\n\n借助这个插件，你可以通过下述的语法在展示 demo 的同时，将这段代码展示出来。\n\n```md\n::: demo\n\u003cdiv @click=\"onClick\"\u003eClick me!\u003c/div\u003e\n\n\u003cscript\u003e\nexport default {\n  methods: {\n    onClick: () =\u003e { window.alert(1) },\n  },\n}\n\u003c/script\u003e\n:::\n```\n\n\u003ca href=\"https://buptsteve.github.io/vuepress-plugin-demo-code/zh/example/\"\u003e实际效果请点击这里\u003c/a\u003e\n\n## Features\n* 只有一份代码同时生成 demo 和 code\n* 代码可折叠\n* 支持在线编辑\n  * ✔ Codepen\n  * ✔ JSFiddle\n  * ✔ CodeSandbox\n* 专门为浏览长代码进行了设计\n  * Sticky 的收起按钮\n  * 点击收起按钮时自动滚动到代码的顶部\n\n## Install\n\n* 首先安装 [vuepress v1.x](https://github.com/vuejs/vuepress)\n\n* 接着安装插件\n\n```bash\n$ npm i -D vuepress-plugin-demo-code\n# OR\n$ pnpm i -D vuepress-plugin-demo-code\n# OR\n$ yarn add -D vuepress-plugin-demo-code\n```\n\n* 如果你用的是 [vuepress 2.x](https://v2.vuepress.vuejs.org/)，请安装 next 版本。\n\n```bash\n$ npm i -D vuepress-plugin-demo-code@next\n# OR\n$ pnpm i -D vuepress-plugin-demo-code@next\n# OR\n$ yarn add -D vuepress-plugin-demo-code@next\n```\n\n## Usage\n配置 vuepress config\n\n```js\nmodule.exports = {\n  plugins: ['demo-code'],\n}\n```\n\n## Options\n插件支持以下配置\n\n```js\nmodule.exports = {\n  plugins: [\n    ['demo-code', {\n      jsLibs: [\n        // umd\n        'https://unpkg.com/tua-storage/dist/TuaStorage.umd.js',\n      ],\n      cssLibs: [\n        'https://unpkg.com/animate.css@3.7.0/animate.min.css',\n      ],\n      vueVersion: '^3',\n      showText: 'show code',\n      hideText: 'hide',\n      styleStr: 'text-decoration: underline;',\n      minHeight: 200,\n      onlineBtns: {\n        codepen: true,\n        jsfiddle: true,\n        codesandbox: true,\n      },\n      jsfiddle: {\n        framework: 'library/pure', // default\n        // framework: 'vue/2.6.11',\n      },\n      codesandbox: {\n        deps: { 'lodash': 'latest' },\n        json: '',\n        query: '',\n        embed: '',\n      },\n      demoCodeMark: 'demo-code',\n      copyOptions: { ... },\n    }]\n  ],\n}\n```\n\n### jsLibs\n* 类型：`Array`\n* 默认值：`[]`\n\n展示 demo 所需的 js 库。\n\n### cssLibs\n* 类型：`Array`\n* 默认值：`[]`\n\n展示 demo 所需的 css 库。\n\n### vueVersion\n* 类型：`String` (语义化版本格式)\n* 默认值：`^2.6.14`\n\nvue 的语义化版本字符串。想要了解更多的语义化版本格式，可以看这里 [npm semver calculator](https://semver.npmjs.com/).\n\n### showText\n* 类型：`String`\n* 默认值：`show code`\n\n展开代码按钮的文案。\n\n### hideText\n* 类型：`String`\n* 默认值：`hide code`\n\n收起代码按钮的文案。\n\n### minHeight\n* 类型：`Number`\n* 默认值：`200`(px)\n\n代码收起时的高度。\n\n### onlineBtns\n* 类型：`Object`\n* 默认值：`{ codepen: true, jsfiddle: true, codesandbox: true }`\n\n展示哪些在线编辑的按钮。\n\n### jsfiddle\n* Type: `Object`\n* Default: `{ framework: 'library/pure' }`\n\n透传 [jsfiddle options](https://docs.jsfiddle.net/api/display-a-fiddle-from-post).\n\n### codesandbox\n* 类型：`Object`\n* 默认值：`{ deps: {}, json: '', query: 'module=App.vue'', embed: '' }`\n\n透传 [CodeSandbox options](https://codesandbox.io/docs/importing#define-api).\n\n\u003e `deps` is dependencies\n\n### demoCodeMark\n* 类型：`String`\n* 默认值：`demo`\n\n插件的标记，即跟在 `:::` 后的标记。\n\n### copyOptions\n* 类型：`Object/Boolean`\n* 默认值：`{ align: 'top', selector: '.demo-and-code-wrapper div[class*=\"language-\"] pre' }`\n\n透传 [vuepress-plugin-code-copy](https://github.com/znicholasbrown/vuepress-plugin-code-copy#options) 的参数，或传 `false` 禁用它。\n\n## Related\n* [vuepress-plugin-demo-block](https://github.com/xiguaxigua/vuepress-plugin-demo-block)\n\n## License\n\n[MIT](http://opensource.org/licenses/MIT)\n\nCopyright (c) StEve Young\n\n## Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://buptsteve.github.io\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/11501493?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eStEve Young\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/BuptStEve/vuepress-plugin-demo-code/commits?author=BuptStEve\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/BuptStEve/vuepress-plugin-demo-code/commits?author=BuptStEve\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"#infra-BuptStEve\" title=\"Infrastructure (Hosting, Build-Tools, etc)\"\u003e🚇\u003c/a\u003e \u003ca href=\"#translation-BuptStEve\" title=\"Translation\"\u003e🌍\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/leandrofngl\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/11283636?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eleandrofngl\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/BuptStEve/vuepress-plugin-demo-code/issues?q=author%3Aleandrofngl\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/tianjianchn\"\u003e\u003cimg src=\"https://avatars0.githubusercontent.com/u/7612199?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eTian Jian\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/BuptStEve/vuepress-plugin-demo-code/issues?q=author%3Atianjianchn\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://barr.media\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/30320791?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eSpence\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/BuptStEve/vuepress-plugin-demo-code/commits?author=mrspence\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuptsteve%2Fvuepress-plugin-demo-code","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbuptsteve%2Fvuepress-plugin-demo-code","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuptsteve%2Fvuepress-plugin-demo-code/lists"}