Skip to content

Commit 83e8be6

Browse files
committed
feat: plantuml plugin
1 parent f0a3871 commit 83e8be6

File tree

7 files changed

+91
-3
lines changed

7 files changed

+91
-3
lines changed

packages/example/src/App.svelte

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import math from '@bytemd/plugin-math'
55
import graphviz from '@bytemd/plugin-graphviz'
66
import mermaid from '@bytemd/plugin-mermaid'
7+
import plantuml from '@bytemd/plugin-plantuml'
78
89
let source = `# bytemd [![npm](https://img.shields.io/npm/v/bytemd.svg)](https://npm.im/bytemd)
910
@@ -51,6 +52,12 @@ digraph G {
5152
}
5253
\`\`\`
5354
55+
## PlantUML
56+
57+
\`\`\`plantuml
58+
A -> B: Hello
59+
\`\`\`
60+
5461
## Code syntax highlight
5562
5663
\`\`\`js
@@ -75,12 +82,14 @@ new Viewer({
7582
math: true,
7683
graphviz: true,
7784
mermaid: true,
85+
plantuml: true,
7886
}
7987
$: plugins = [
8088
enabled.highlight && highlight(),
8189
enabled.math && math(),
8290
enabled.graphviz && graphviz(),
8391
enabled.mermaid && mermaid(),
92+
enabled.plantuml && plantuml()
8493
].filter(x => x)
8594
</script>
8695

@@ -95,9 +104,6 @@ new Viewer({
95104

96105
<div>
97106
Plugins:
98-
<label>
99-
<input type=checkbox bind:checked={enabled.highlight} /> highlight
100-
</label>
101107
<label>
102108
<input type=checkbox bind:checked={enabled.math} /> math
103109
</label>
@@ -107,5 +113,11 @@ new Viewer({
107113
<label>
108114
<input type=checkbox bind:checked={enabled.mermaid} /> mermaid
109115
</label>
116+
<label>
117+
<input type=checkbox bind:checked={enabled.plantuml} /> plantuml
118+
</label>
119+
<label>
120+
<input type=checkbox bind:checked={enabled.highlight} /> highlight
121+
</label>
110122
</div>
111123
<Editor {source} plugins={plugins} />

packages/plugin-plantuml/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-plantuml",
3+
"version": "0.0.1",
4+
"description": "Plantuml plugin for bytemd",
5+
"main": "dist/index.cjs.js",
6+
"module": "dist/index.esm.js",
7+
"types": "src/index.d.ts",
8+
"svelte": "src/index.js",
9+
"keywords": [],
10+
"files": [
11+
"dist",
12+
"src"
13+
],
14+
"author": "Rongjian Zhang <[email protected]>",
15+
"license": "MIT",
16+
"dependencies": {
17+
"plantuml-encoder": "^1.4.0"
18+
},
19+
"peerDependencies": {
20+
"bytemd": "*"
21+
}
22+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
import { encode } from 'plantuml-encoder'
3+
export let value
4+
</script>
5+
6+
<img src={`//www.plantuml.com/plantuml/img/${encode(value)}`} alt="plantuml" />
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { Plugin } from 'bytemd';
2+
export interface BytemdPlantumlOptions {
3+
}
4+
export default function plantuml({}?: BytemdPlantumlOptions): Plugin;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import PlantumlView from './PlantumlView.svelte';
2+
export default function plantuml(_a) {
3+
_a = {};
4+
return {
5+
shouldTransformElement: function (node) {
6+
return node.type === 'code' && node.lang === 'plantuml';
7+
},
8+
component: PlantumlView
9+
};
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Plugin } from 'bytemd';
2+
import PlantumlView from './PlantumlView.svelte';
3+
4+
export interface BytemdPlantumlOptions {}
5+
6+
export default function plantuml({}: BytemdPlantumlOptions = {}): Plugin {
7+
return {
8+
shouldTransformElement(node) {
9+
return node.type === 'code' && node.lang === 'plantuml';
10+
},
11+
component: PlantumlView
12+
};
13+
}

0 commit comments

Comments
 (0)