« get me outta code hell

replacer: squash non-markdown single backslashes - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-02-17 21:03:22 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-02-17 21:03:22 -0400
commit23c7dace129e78cdc1c6aa9155fc1690750431d7 (patch)
treea9d04671157608938790703117e2d419ba9a468c
parente2dbe28c6bf606422bf53973cfa5fb08bca9d873 (diff)
replacer: squash non-markdown single backslashes
-rw-r--r--src/util/replacer.js11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/util/replacer.js b/src/util/replacer.js
index c1d13c7c..9544328f 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 = [];