-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathblock.ts
More file actions
35 lines (30 loc) · 1.27 KB
/
block.ts
File metadata and controls
35 lines (30 loc) · 1.27 KB
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
import { Blot } from "parchment";
import Block from "quill/blots/block";
class MxBlock extends Block {
isEmptyTailBlock(): boolean {
const hasNoValidChildren =
this.children.length === 0 ||
(this.children.length === 1 && this.children.head?.statics.tagName?.toString().toUpperCase() === "BR");
return hasNoValidChildren;
}
html(): string {
// quill return empty paragraph when there is no content (just empty line)
// to preserve the line breaks, we add empty space
if (this.domNode.childElementCount === 1 && this.domNode.children[0] instanceof HTMLBRElement) {
return this.domNode.outerHTML.replace(/<br>/g, "<br />");
} else if (this.domNode.childElementCount === 0 && this.domNode.textContent?.trim() === "") {
this.domNode.innerHTML = "<br />";
return this.domNode.outerHTML;
} else {
return this.domNode.outerHTML;
}
}
static IsMxBlock(blot: Blot | null): blot is MxBlock {
return blot?.statics.blotName === "mx-block";
}
static IsEmptyBlock(blot: Blot | null): boolean {
return blot != null && MxBlock.IsMxBlock(blot) && blot.isEmptyTailBlock();
}
}
MxBlock.blotName = "mx-block";
export default MxBlock;