From 727e1a2a689841a85299540c4817ccf046ed0475 Mon Sep 17 00:00:00 2001 From: Tim McMackin Date: Thu, 28 Nov 2024 09:53:37 -0500 Subject: [PATCH] Clean up escapes (#474) --- src/scripts/concatenate.mjs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/scripts/concatenate.mjs b/src/scripts/concatenate.mjs index a5813da22..f62df6e19 100644 --- a/src/scripts/concatenate.mjs +++ b/src/scripts/concatenate.mjs @@ -90,6 +90,20 @@ function removeFrontMatter(mdText) { } } +// Unified tools put escapes in places +// We could get around this by forking mdast-util-to-string as described here: +// https://github.com/remarkjs/strip-markdown/issues/28#issuecomment-1290847745 +function cleanUpEscapes(text) { + return text + // Fix stripped markdown escaping such as `_` to `\_` + .replaceAll('\\\_', '_') + .replaceAll('\\<', '<') + .replaceAll('\\[', '[') + .replaceAll(/^\\-/gm, '-') + .replaceAll('\\.', '.') + .replaceAll('\\*', '*'); +} + async function concatSidebar(sidebarName) { const outputPath = path.resolve(__dirname, '../../', fileNames[sidebarName]); @@ -115,8 +129,7 @@ async function concatSidebar(sidebarName) { const oneFileText = await remark() .use(strip) .process(markdownText); - // Fix strip plugin escaping `_` as `\_` - const oneFileTextFixEscaped = String(oneFileText).replaceAll('\\\_', '_'); + const oneFileTextFixEscaped = cleanUpEscapes(String(oneFileText)); return fs.promises.appendFile(outputPath, oneFileTextFixEscaped + '\n\n'); }, Promise.resolve());