-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.ts
50 lines (44 loc) · 1.37 KB
/
util.ts
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
import { setIcon } from 'obsidian';
export function createEl(tagName: string, attrs?: any): HTMLElement {
const c = document.createElement(tagName)
if (!attrs)
return c
for (let p in attrs) {
if (!p || !Object.prototype.hasOwnProperty.call(attrs, p))
continue
if (p == "textContent") {
c.setText(attrs[p])
} else {
c.setAttribute(p, attrs[p])
}
}
return c
}
const adocSpecificTypes = ["important", "caution"];
const admotionIcons: Map<string, string> = new Map([
["danger", "zap"],
["note", "pencil"],
["tip", "flame"],
["warning", "alert-triangle"]
]);
export function patchAdmonitionBlock(item: HTMLElement)
{
let abType = item.className.replace("admonitionblock ", "");
if (adocSpecificTypes.includes(abType)) {
abType = "danger";
}
const iconElement = item.getElementsByClassName("icon");
item.setAttribute("data-callout", abType);
item.className = "callout";
let calloutTitle = createEl("div", { class: "callout-title" });
const calloutIcon = createEl("div", { class: "callout-icon" });
let iconName = admotionIcons.get(abType);
if (iconName == undefined)
iconName = "pencil";
setIcon(calloutIcon, iconName);
calloutTitle.appendChild(calloutIcon)
if (iconElement.length > 0 && iconElement[0]) {
calloutTitle.appendChild(iconElement[0])
item.insertBefore(calloutTitle, item.firstChild);
}
}