CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/util/markdown-utils.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
/*
7
* license
8
*/
9
10
import { replace_all } from "./misc";
11
12
const escape_map = "$";
13
14
// We used to do this since we wanted to support math delineated by \[ ... \];
15
// however, that just conflicts too much with markdown itself and Jupyter classic
16
// doesn't do it. Use $ only.
17
//const escape_map = "$()[]";
18
19
const unescape_map =
20
"\uFE22\uFE23\uFE24\uFE25\uFE26"; /* we just use some unallocated unicode... */
21
22
export function math_escape(s: string): string {
23
for (let i = 0; i < escape_map.length; i++) {
24
s = replace_all(s, "\\" + escape_map[i], unescape_map[i]);
25
}
26
return s;
27
}
28
29
export function math_unescape(s: string): string {
30
for (let i = 0; i < escape_map.length; i++) {
31
s = replace_all(s, unescape_map[i], "\\" + escape_map[i]);
32
}
33
return s;
34
}
35
36