generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
91 lines (90 loc) · 7.71 KB
/
main.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __export = (target, all) => {
__markAsModule(target);
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __reExport = (target, module2, desc) => {
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
for (let key of __getOwnPropNames(module2))
if (!__hasOwnProp.call(target, key) && key !== "default")
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
}
return target;
};
var __toModule = (module2) => {
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
};
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
// main.ts
__export(exports, {
default: () => EmbedPlugin
});
var import_obsidian = __toModule(require("obsidian"));
var EmbedPlugin = class extends import_obsidian.Plugin {
postprocessor(content, el, ctx) {
return __async(this, null, function* () {
let json;
try {
json = (0, import_obsidian.parseYaml)(content);
validate(json, el);
var frame = '<iframe src="file:' + this.app.vault.getRoot().vault.adapter.basePath + "/" + json.path + '" width="' + json.width + '" height="' + json.height + '" frameborder="0"></iframe>';
yield import_obsidian.MarkdownRenderer.renderMarkdown(frame, el, "", this.app.workspace.activeLeaf.view);
} catch (error) {
let errorDiv = document.createElement("div");
errorDiv.textContent = "Couldn't render HTML:" + error;
el.appendChild(errorDiv);
}
});
}
onload() {
return __async(this, null, function* () {
console.log("Loading EmbedPlugin");
this.registerDomEvent(document, "click", (evt) => {
console.log("click", evt);
});
this.registerMarkdownCodeBlockProcessor("embedhtml", this.postprocessor.bind(this));
this.registerInterval(window.setInterval(() => console.log("setInterval"), 5 * 60 * 1e3));
});
}
onunload() {
console.log("Unloading EmbedPlugin");
}
};
var allowValues = ["path", "width", "height"];
var validate = (json, el) => {
if (!json) {
throw "There should be a valid JSON in this block.";
}
Object.keys(json).forEach((key) => {
if (!allowValues.contains(key)) {
throw "The only valid keys are path, width and height.";
}
});
};
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsibWFpbi50cyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsiaW1wb3J0IHsgQXBwLCBFZGl0b3IsIFBsdWdpbiwgTWFya2Rvd25Qb3N0UHJvY2Vzc29yQ29udGV4dCwgcGFyc2VZYW1sLCBNYXJrZG93blJlbmRlcmVyIH0gZnJvbSAnb2JzaWRpYW4nO1xyXG5cclxuXHJcbmV4cG9ydCBkZWZhdWx0IGNsYXNzIEVtYmVkUGx1Z2luIGV4dGVuZHMgUGx1Z2luIHtcclxuXHJcblxyXG5cdGFzeW5jIHBvc3Rwcm9jZXNzb3IoY29udGVudDogc3RyaW5nLCBlbDogSFRNTEVsZW1lbnQsIGN0eDogTWFya2Rvd25Qb3N0UHJvY2Vzc29yQ29udGV4dCl7XHJcblx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