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/cache.ts
1697 views
1
import stringify from "json-stable-stringify";
2
import { Descendant } from "slate";
3
4
export function setCache({
5
cache,
6
node,
7
markdown,
8
}: {
9
cache: { [node: string]: string } | undefined;
10
node: Descendant;
11
markdown: string | undefined;
12
}): void {
13
if (cache == null || node == null || !markdown) return;
14
const s = stringify(node)!;
15
if (cache[s] !== undefined) {
16
// Distinct markdown can result in the same slate element; in this case we cache
17
// only the first. An example is the paragraph "_a_" versus "*a*", or different
18
// notation for a displayed math equation.
19
return;
20
}
21
cache[s] = markdown;
22
}
23
24