forked from typeup/dom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile.ts
More file actions
27 lines (25 loc) · 738 Bytes
/
File.ts
File metadata and controls
27 lines (25 loc) · 738 Bytes
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
import { Error } from "@cogneco/mend"
import { Node, register } from "./Node"
import { Block, Paragraph } from "./block"
export class File extends Node {
readonly class: string = "File"
constructor(readonly content: Block[], region?: Error.Region) {
super(region)
}
toObject(): { class: string } | any {
return { ...super.toObject(), content: this.content.map(element => element.toObject()) }
}
toString(): string {
let result = ""
let wasParagraph = false
for (const c of this.content) {
const isParagraph = c instanceof Paragraph
if (isParagraph && wasParagraph)
result += "\n"
result += c.toString()
wasParagraph = isParagraph
}
return result
}
}
register("File", data => new File(data.content))