Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/editors/slate/markdown-to-slate/handle-open.ts
1697 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 } from "./register";
7
import { endswith } from "@cocalc/util/misc";
8
9
function handleOpen({ token, state }) {
10
if (!endswith(token.type, "_open")) return;
11
// Opening for new array of children. We start collecting them
12
// until hitting a token with close_type (taking into account nesting).
13
state.contents = [];
14
const i = token.type.lastIndexOf("_open");
15
state.close_type = token.type.slice(0, i) + "_close";
16
state.open_type = token.type;
17
state.nesting = 0;
18
state.attrs = token.attrs;
19
state.block = token.block;
20
state.open_token = token;
21
return [];
22
}
23
24
register(handleOpen);
25
26