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