Skip to content

Commit a652b25

Browse files
committed
feat: add graphviz plugin
1 parent 6e704eb commit a652b25

File tree

6 files changed

+99
-7
lines changed

6 files changed

+99
-7
lines changed

packages/example/src/App.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { Editor } from 'bytemd';
33
import highlight from '@bytemd/plugin-highlight'
44
import katex from '@bytemd/plugin-katex'
5+
import graphviz from '@bytemd/plugin-graphviz'
56
let source = `# bytemd
67
78
[![npm](https://img.shields.io/npm/v/bytemd.svg)](https://npm.im/bytemd)
@@ -34,4 +35,4 @@ MIT
3435
`
3536
</script>
3637

37-
<Editor {source} plugins={[highlight, katex]} />
38+
<Editor {source} plugins={[highlight, katex, graphviz]} />

packages/plugin-graphviz/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-graphviz",
3+
"version": "0.0.1",
4+
"description": "Graphviz 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+
"peerDependencies": {
17+
"bytemd": "*"
18+
},
19+
"dependencies": {
20+
"viz.js": "^2.1.2"
21+
}
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script>
2+
import Viz from 'viz.js'
3+
import workerURL from 'viz.js/full.render.js';
4+
5+
const viz = new Viz(workerURL)
6+
7+
export let value
8+
</script>
9+
10+
{#await viz.renderString(value)}
11+
<p>...</p>
12+
{:then raw}
13+
{@html raw}
14+
{:catch error}
15+
<p style="color: red">{error.message}</p>
16+
{/await}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import GraphvizView from './GraphvizView.svelte';
2+
3+
export default {
4+
transformNode(node) {},
5+
shouldTransformElement(node) {
6+
return node.type === 'code' && ['graphviz', 'dot'].includes(node.lang);
7+
},
8+
component: GraphvizView
9+
};

rollup.config.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ const production = !process.env.ROLLUP_WATCH;
1414

1515
const corePkg = require('./packages/bytemd/package.json');
1616
const reactPkg = require('./packages/bytemd-react/package.json');
17-
const pluginHighlightPkg = require('./packages/plugin-highlight/package.json');
18-
const pluginKatexPkg = require('./packages/plugin-katex/package.json');
17+
const highlightPkg = require('./packages/plugin-highlight/package.json');
18+
const katexPkg = require('./packages/plugin-katex/package.json');
19+
const graphvizPkg = require('./packages/plugin-graphviz/package.json');
1920

2021
function serve() {
2122
let started = false;
@@ -118,11 +119,11 @@ const configs = {
118119
output: [
119120
{
120121
format: 'es',
121-
file: pluginHighlightPkg.module
122+
file: highlightPkg.module
122123
},
123124
{
124125
format: 'cjs',
125-
file: pluginHighlightPkg.main
126+
file: highlightPkg.main
126127
}
127128
],
128129
plugins: [
@@ -140,11 +141,33 @@ const configs = {
140141
output: [
141142
{
142143
format: 'es',
143-
file: pluginKatexPkg.module
144+
file: katexPkg.module
144145
},
145146
{
146147
format: 'cjs',
147-
file: pluginKatexPkg.main
148+
file: katexPkg.main
149+
}
150+
],
151+
plugins: [
152+
svelte({ dev: !production }),
153+
resolve({
154+
browser: true,
155+
dedupe: ['svelte']
156+
}),
157+
commonjs(),
158+
production && terser()
159+
]
160+
},
161+
'plugin-graphviz': {
162+
input: 'src/index.js',
163+
output: [
164+
{
165+
format: 'es',
166+
file: graphvizPkg.module
167+
},
168+
{
169+
format: 'cjs',
170+
file: graphvizPkg.main
148171
}
149172
],
150173
plugins: [

0 commit comments

Comments
 (0)