Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 1x 1x | export function escapeMarkdownChar(s: string, whiteSpace: boolean) { // note: could replace with a common lib but too much baggage to be worth it for now // commonmark 2.4: all punct can be escaped // const punct = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'; // Per ParsedownExtra https://github.com/erusev/parsedown/blob/f5aa6fd1caf5ffb41af2e85d3ef1a51263a31545/Parsedown.php#L1964 // '\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '>', '#', '+', '-', '.', '!', '|', '~' // and add < for start of HTML tag (hyphen moved to end to prevent range match!) s = s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); s = s.replace(/[\\`*_{}\[\]()#+.!|~-]/g, '\\$&'); // Per commonmark: s = s.replace(/[!"#$%&'()*+,-./:;<=>?@\[\\\]^_`{|}~]/g, '\\$&'); if(whiteSpace) { // replace whitepsace s = s.replace(/[\n]/g, '\\n'); s = s.replace(/[\r]/g, '\\r'); s = s.replace(/[\t]/g, '\\t'); s = s.replace(/ /g, ' '); s = s.replace(/\u00a0/g, ' '); } return s; } |