-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlockElement.ts
44 lines (35 loc) · 1 KB
/
BlockElement.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
import { InlineContent } from "./InlineContent";
import { parseInline } from "../parser/parseInline";
export class BlockElement {
public tagError?: string;
public labelError?: string;
private _parsedLabel?: InlineContent;
constructor(
readonly tag?: string,
readonly label?: string,
readonly lineDelta: number = 0,
readonly children: BlockElement[] = []
) {}
toJSON() {
return { tag: this.tag, label: this.label, lineDelta: this.lineDelta, children: this.children };
}
get(tag: string | undefined) {
return this.children.find(el => el.tag === tag);
}
getAll(tag: string | undefined) {
return this.children.filter(el => el.tag === tag);
}
get parsedLabel(): InlineContent {
if (!this._parsedLabel) this._parsedLabel = parseInline(this.label || "");
return this._parsedLabel;
}
get source(): string {
return this.tagSource + this.labelSource;
}
get tagSource(): string {
return this.tag ? "#" + this.tag + " " : "";
}
get labelSource(): string {
return this.label || "";
}
}