Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/editors/slate/elements/break/index.tsx
1698 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { register, SlateElement } from "../register";
7
import { Element } from "slate";
8
9
export interface Softbreak extends SlateElement {
10
type: "softbreak";
11
isInline: true;
12
isVoid: true;
13
}
14
15
register({
16
slateType: "softbreak",
17
18
toSlate: () => {
19
return {
20
type: "softbreak",
21
isInline: true,
22
isVoid: true,
23
children: [{ text: "" }],
24
};
25
},
26
27
// A softbreak creates a new line without creating
28
// a new paragraph.
29
StaticElement: ({ attributes, children }) => {
30
return (
31
<span {...attributes}>
32
<span style={{ whiteSpace: "normal" }}> </span>
33
{children}
34
</span>
35
);
36
},
37
});
38
39
export interface Hardbreak extends SlateElement {
40
type: "hardbreak";
41
isInline: true;
42
isVoid: true;
43
}
44
45
export function hardbreak() {
46
return {
47
type: "hardbreak",
48
isInline: true,
49
isVoid: true,
50
children: [{ text: "" }],
51
} as Element;
52
}
53
54
register({
55
slateType: "hardbreak",
56
57
StaticElement: ({ attributes, children }) => {
58
return (
59
<span {...attributes}>
60
<span style={{ whiteSpace: "pre" }}>{"\n"}</span>
61
{children}
62
</span>
63
);
64
},
65
66
toSlate: hardbreak,
67
});
68
69