-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathfigure.js
28 lines (28 loc) · 765 Bytes
/
figure.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
CMS.registerEditorComponent({
id: "figure",
label: "Figure",
fields: [{
name: "title",
label: "Figure Title",
widget: "string"
},
{
name: "src",
label: "Figure SRC",
widget: "string"
},
],
pattern: /{{< figure src="([a-zA-Z0-9-_ ]+)" title="([a-zA-Z0-9-_ ]+)" >}}/,
fromBlock: function(match) {
return {
title: match[1],
src: match[2],
};
},
toBlock: function(obj) {
return `{{< figure src="${obj.src}" title="${obj.title}" >}}`;
},
toPreview: function(obj) {
return `<figure><img src=${obj.src} alt=${obj.title}><figcaption>${obj.title}</figcaption></figure>`;
},
});