fix: Port escape overrides from enterprise fork

This commit is contained in:
Tom Moor
2023-10-15 10:52:48 -04:00
parent d5bac6cbca
commit 9e3b2c043c

View File

@@ -35,4 +35,35 @@ const service = new TurndownService({
.use(breaks)
.use(emptyLists);
const escapes: [RegExp, string][] = [
[/\\/g, "\\\\"],
[/\*/g, "\\*"],
[/^-/g, "\\-"],
[/^\+ /g, "\\+ "],
[/^(=+)/g, "\\$1"],
[/^(#{1,6}) /g, "\\$1 "],
[/`/g, "\\`"],
[/^~~~/g, "\\~~~"],
[/\[/g, "\\["],
[/\]/g, "\\]"],
[/\(/g, "\\("], // OLN-91
[/\)/g, "\\)"], // OLN-91
[/^>/g, "\\>"],
[/_/g, "\\_"],
[/^(\d+)\. /g, "$1\\. "],
];
/**
* Overrides the Markdown escaping, as documented here:
* https://github.com/mixmark-io/turndown/blob/4499b5c313d30a3189a58fdd74fc4ed4b2428afd/README.md#overriding-turndownserviceprototypeescape
*
* @param text The string to escape
* @returns A string with Markdown syntax escaped
*/
service.escape = function (text) {
return escapes.reduce(function (accumulator, escape) {
return accumulator.replace(escape[0], escape[1]);
}, text);
};
export default service;