-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplugin.mjs
44 lines (44 loc) · 848 Bytes
/
plugin.mjs
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/** @type {import("myst-common").MystPlugin} */
export default {
name: "any-directive",
directives: [
{
name: "any",
doc: "Embed any component",
arg: {
type: String,
required: true,
doc: "",
},
options: {
styles: {
type: String,
required: false,
doc: "URL to the CSS file",
},
},
body: {
doc: "JSON object with props to pass down to the component",
type: String,
required: true,
},
validate(data, _vfile) {
// TODO: validate the URL for the esm
return data;
},
run(data, _vfile, _opts) {
const body = /** @type {string} */ (data?.body ?? "{}");
return [
{
type: "any",
import: data.arg,
styles: data.options?.styles ?? "",
data: { json: JSON.parse(body) },
},
];
},
},
],
roles: [],
transforms: [],
};