Path: blob/master/src/packages/util/markdown-utils.ts
1447 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6* license7*/89import { replace_all } from "./misc";1011const escape_map = "$";1213// We used to do this since we wanted to support math delineated by \[ ... \];14// however, that just conflicts too much with markdown itself and Jupyter classic15// doesn't do it. Use $ only.16//const escape_map = "$()[]";1718const unescape_map =19"\uFE22\uFE23\uFE24\uFE25\uFE26"; /* we just use some unallocated unicode... */2021export function math_escape(s: string): string {22for (let i = 0; i < escape_map.length; i++) {23s = replace_all(s, "\\" + escape_map[i], unescape_map[i]);24}25return s;26}2728export function math_unescape(s: string): string {29for (let i = 0; i < escape_map.length; i++) {30s = replace_all(s, unescape_map[i], "\\" + escape_map[i]);31}32return s;33}343536