Skip to content

Commit cfb6bda

Browse files
committed
Add generic plugin API
1 parent 12b6e0c commit cfb6bda

File tree

5 files changed

+44
-30
lines changed

5 files changed

+44
-30
lines changed

index.js

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
"kirbyup": "^0.23.0"
1818
},
1919
"dependencies": {
20-
"@codemirror/commands": "^0.19.8",
20+
"@codemirror/commands": "^0.20.0",
2121
"@codemirror/comment": "^0.19.1",
22-
"@codemirror/highlight": "^0.19.7",
22+
"@codemirror/highlight": "^0.19.8",
2323
"@codemirror/history": "^0.19.2",
24-
"@codemirror/lang-markdown": "^0.19.6",
25-
"@codemirror/language": "^0.19.8",
24+
"@codemirror/lang-markdown": "^0.20.0",
25+
"@codemirror/language": "^0.20.0",
2626
"@codemirror/rangeset": "^0.19.9",
27-
"@codemirror/search": "^0.19.9",
28-
"@codemirror/state": "^0.19.9",
29-
"@codemirror/stream-parser": "^0.19.7",
30-
"@codemirror/view": "^0.19.47",
31-
"underscore": "^1.13.2"
27+
"@codemirror/search": "^0.20.1",
28+
"@codemirror/state": "^0.20.0",
29+
"@codemirror/stream-parser": "^0.19.9",
30+
"@codemirror/view": "^0.20.4",
31+
"underscore": "^1.13.3"
3232
}
3333
}

src/components/Buttons/Button.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,4 @@ export default class Button extends Extension {
4242

4343
return () => this.editor.isActiveToken("Kirbytag", "FencedCode", "Link", "URL");
4444
}
45-
46-
/**
47-
* Creates a custom button from an object
48-
*/
49-
static factory(definition) {
50-
const button = new Button();
51-
completeAssign(button, definition);
52-
return button;
53-
}
5445
}

src/components/Extension.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { formatKeyName } from "./Utils/keymap.js";
2+
import completeAssign from "./Utils/complete-assign.js";
23

34
export default class Extension {
45

@@ -55,4 +56,13 @@ export default class Extension {
5556
get syntax() {
5657
return null;
5758
}
59+
60+
/**
61+
* Creates a custom extension from an object
62+
*/
63+
static factory(definition) {
64+
const extension = new Extension();
65+
completeAssign(extension, definition);
66+
return extension;
67+
}
5868
}

src/components/MarkdownInput.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import PageLink from "./Buttons/PageLink.js"
7777
import SpecialChars from "./Buttons/SpecialChars.js"
7878
import Strikethrough from "./Buttons/Strikethrough.js"
7979
import StrongEmphasis from "./Buttons/StrongEmphasis.js"
80+
import Extension from './Extension.js';
8081
8182
8283
let resizeObserver;
@@ -153,6 +154,7 @@ export default {
153154
extensions: [
154155
...this.createHighlights(),
155156
...this.createToolbarButtons(),
157+
...this.createCustomExtensions(),
156158
],
157159
events: {
158160
active: (active) => {
@@ -226,6 +228,17 @@ export default {
226228
], []);
227229
},
228230
231+
createCustomExtensions() {
232+
if (!window.markdownEditorExtensions) {
233+
return [];
234+
}
235+
236+
return window.markdownEditorExtensions.reduce((accumulator, definition) => [
237+
...accumulator,
238+
Extension.factory(definition)
239+
], []);
240+
},
241+
229242
createToolbarButtons() {
230243
const available = [
231244
new Blockquote(),

0 commit comments

Comments
 (0)