-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
595 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Xiaohan Zou (@Renovamen) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# @renovamen/vuepress-plugin-mermaid | ||
|
||
A plugin for adding [Mermaid](https://mermaid-js.github.io) to [VuePress](https://vuepress.vuejs.org/). | ||
|
||
| ||
|
||
## Installation | ||
|
||
Install this plugin with: | ||
|
||
```bash | ||
yarn add @renovamen/vuepress-plugin-mermaid | ||
# or | ||
npm install @renovamen/vuepress-plugin-mermaid | ||
``` | ||
|
||
And add it to your `.vuepress/config.js`: | ||
|
||
```js | ||
module.exports = { | ||
plugins: [ | ||
[ | ||
'@renovamen/vuepress-plugin-mermaid' | ||
] | ||
] | ||
} | ||
``` | ||
|
||
| ||
|
||
## Usage | ||
|
||
Then you can use [Mermaid](https://mermaid-js.github.io) in Markdown: | ||
|
||
<pre><code>```mermaid | ||
sequenceDiagram | ||
Alice->John: Hello John, how are you? | ||
loop Every minute | ||
John-->Alice: Great! | ||
end | ||
``` | ||
</code></pre> | ||
|
||
| ||
|
||
## License | ||
|
||
[MIT](LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Mermaid from './lib/Mermaid'; | ||
|
||
export default function (ctx) { | ||
const { Vue } = ctx; | ||
Vue.component('Mermaid', Mermaid); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const path = require('path') | ||
const mermaid = require('./lib/markdown-it-mermaid') | ||
|
||
module.exports = (options, ctx) => { | ||
return { | ||
name:'@renovamen/vuepress-plugin-mermaid', | ||
enhanceAppFiles: path.resolve(__dirname, './enhanceApp.js'), | ||
chainMarkdown(config) { | ||
config | ||
.plugin('mermaid') | ||
.use(mermaid) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<template> | ||
<div :id="id" class="vuepress-mermaid"> | ||
{{ code }} | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'mermaid', | ||
props: { | ||
id: { | ||
type: String, | ||
required: true | ||
}, | ||
code: { | ||
type: String, | ||
required: true | ||
} | ||
}, | ||
mounted () { | ||
import('mermaid/dist/mermaid.min').then(mermaid => { | ||
mermaid.initialize({ | ||
startOnLoad: true | ||
}); | ||
mermaid.init(undefined, '#' + this.id); | ||
}) | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="stylus"> | ||
.vuepress-mermaid | ||
margin 30px 0 | ||
overflow scroll | ||
text-align center | ||
display flex | ||
justify-content center | ||
align-items center | ||
@media (max-width: 419px) | ||
margin 0 | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { hash } = require('@vuepress/shared-utils') | ||
|
||
const mermaid = (md) => { | ||
const temp = md.renderer.rules.fence.bind(md.renderer.rules); | ||
md.renderer.rules.fence = (tokens, idx, options, env, slf) => { | ||
const token = tokens[idx]; | ||
|
||
if (token.info === 'mermaid') { | ||
try { | ||
const key = `mermaid_${hash(idx)}`; | ||
const code = token.content.trim(); | ||
|
||
md.$dataBlock[key] = code; | ||
return `<Mermaid id="${key}" :code="$dataBlock.${key}"></Mermaid>`; | ||
} | ||
catch (err) { | ||
return `<pre>${err}</pre>` | ||
} | ||
} | ||
return temp(tokens, idx, options, env, slf); | ||
} | ||
} | ||
|
||
module.exports = mermaid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "@renovamen/vuepress-plugin-mermaid", | ||
"version": "0.1.0", | ||
"description": "A plugin for adding Mermaid to VuePress.", | ||
"author": "Renovamen <renovamenzxh@gmail.com>", | ||
"main": "index.js", | ||
"keywords": [ | ||
"vue", | ||
"vuepress", | ||
"vuepress-plugin", | ||
"mermaid" | ||
], | ||
"homepage": "https://github.com/Renovamen/vuepress-theme-gungnir/tree/main/packages/plugins/mermaid", | ||
"bugs": { | ||
"url": "https://github.com/Renovamen/vuepress-theme-gungnir/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Renovamen/vuepress-theme-gungnir.git", | ||
"directory": "packages/plugins/mermaid" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"mermaid": "^8.9.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
6c1d135
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: