Skip to content

Commit e25d036

Browse files
committed
Add widget type
1 parent 8c1d99c commit e25d036

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

static/admin/index.html

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,58 @@ <h4 style="margin:0 0 4px;font-size:1em;">${b.title}</h4>
343343
]
344344
});
345345

346+
// Admonitions
347+
CMS.registerEditorComponent({
348+
id: "admonition",
349+
label: "Admonition",
350+
fields: [
351+
{
352+
name: "type",
353+
label: "Admonition Type",
354+
widget: "select",
355+
options: [
356+
{ label: "Note", value: "note" },
357+
{ label: "Info", value: "info" },
358+
{ label: "Warning", value: "warning" },
359+
{ label: "Caution", value: "caution" },
360+
{ label: "Construction", value: "construction" }
361+
],
362+
default: "note"
363+
},
364+
{
365+
name: "body",
366+
label: "Content",
367+
widget: "text",
368+
default: ""
369+
}
370+
],
371+
pattern: /^{{<\s*admonition\s+type="(.*?)"\s*>}}([\s\S]*?){{<\s*\/admonition\s*>}}$/,
372+
373+
fromBlock: function(match) {
374+
return {
375+
type: match[1],
376+
body: match[2].trim()
377+
};
378+
},
379+
380+
toBlock: function(obj) {
381+
return [
382+
`{{< admonition type="${obj.type}" >}}`,
383+
obj.body,
384+
`{{< /admonition >}}`
385+
].join("\n");
386+
},
387+
388+
preview: function(obj) {
389+
const title = obj.type.charAt(0).toUpperCase() + obj.type.slice(1);
390+
return `
391+
<div class="admonition ${obj.type}">
392+
<strong>${title}:</strong> ${CMS.previewFieldFormatter(obj.body)}
393+
</div>
394+
`;
395+
}
396+
});
397+
346398
</script>
347399
</body>
348400
</html>

0 commit comments

Comments
 (0)