Skip to content

Commit e552946

Browse files
committed
feat: add mermaid plugin
1 parent a652b25 commit e552946

File tree

5 files changed

+94
-0
lines changed

5 files changed

+94
-0
lines changed

packages/plugin-mermaid/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Rongjian Zhang
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.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "@bytemd/plugin-mermaid",
3+
"version": "0.0.1",
4+
"description": "Mermaid plugin for bytemd",
5+
"main": "dist/index.cjs.js",
6+
"module": "dist/index.esm.js",
7+
"types": "index.d.ts",
8+
"svelte": "src/index.js",
9+
"keywords": [],
10+
"files": [
11+
"dist",
12+
"index.d.ts"
13+
],
14+
"author": "Rongjian Zhang <pd4d10@gmail.com>",
15+
"license": "MIT",
16+
"dependencies": {
17+
"mermaid": "^8.4.8"
18+
},
19+
"peerDependencies": {
20+
"bytemd": "*"
21+
}
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script>
2+
import mermaid from 'mermaid'
3+
4+
export let value
5+
let element
6+
7+
const id = 'mermaid' // TODO:
8+
9+
function insertSvg(svgCode, bindFunctions) {
10+
element.innerHTML = svgCode;
11+
if (bindFunctions) bindFunctions(element);
12+
}
13+
14+
$: if (element) {
15+
mermaid.render(id, value, insertSvg, element);
16+
}
17+
</script>
18+
19+
<div bind:this={element}></div>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import MermaidView from './MermaidView.svelte';
2+
3+
export default {
4+
transformNode(node) {},
5+
shouldTransformElement(node) {
6+
return node.type === 'code' && node.lang === 'mermaid';
7+
},
8+
component: MermaidView
9+
};

rollup.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const reactPkg = require('./packages/bytemd-react/package.json');
1717
const highlightPkg = require('./packages/plugin-highlight/package.json');
1818
const katexPkg = require('./packages/plugin-katex/package.json');
1919
const graphvizPkg = require('./packages/plugin-graphviz/package.json');
20+
const mermaidPkg = require('./packages/plugin-mermaid/package.json');
2021

2122
function serve() {
2223
let started = false;
@@ -179,6 +180,28 @@ const configs = {
179180
commonjs(),
180181
production && terser()
181182
]
183+
},
184+
'plugin-mermaid': {
185+
input: 'src/index.js',
186+
output: [
187+
{
188+
format: 'es',
189+
file: mermaidPkg.module
190+
},
191+
{
192+
format: 'cjs',
193+
file: mermaidPkg.main
194+
}
195+
],
196+
plugins: [
197+
svelte({ dev: !production }),
198+
resolve({
199+
browser: true,
200+
dedupe: ['svelte']
201+
}),
202+
commonjs(),
203+
production && terser()
204+
]
182205
}
183206
};
184207

0 commit comments

Comments
 (0)