From 23c7dace129e78cdc1c6aa9155fc1690750431d7 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 17 Feb 2024 21:03:22 -0400 Subject: replacer: squash non-markdown single backslashes --- src/util/replacer.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/util/replacer.js b/src/util/replacer.js index c1d13c7..9544328 100644 --- a/src/util/replacer.js +++ b/src/util/replacer.js @@ -201,6 +201,8 @@ function parseNodes(input, i, stopAt, textOnly) { string = string.trimEnd(); } + string = squashBackslashes(string); + if (string.length) { nodes.push({i: iString, iEnd: i, type: 'text', data: string}); string = ''; @@ -418,6 +420,15 @@ function parseNodes(input, i, stopAt, textOnly) { return nodes; } +export function squashBackslashes(text) { + // Squash backslashes which aren't themselves escaped into + // the following character, unless that character is one of + // a set of characters where the backslash carries meaning + // into later formatting (i.e. markdown). Note that we do + // NOT compress double backslashes into single backslashes. + return text.replace(/([^\\](?:\\{2})*)\\(?![\\*_-])/g, '$1'); +} + export function postprocessImages(inputNodes) { const outputNodes = []; -- cgit 1.3.0-6-gf8a5