Skip to content

Commit

Permalink
Clean up escapes (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
timothymcmackin authored Nov 28, 2024
1 parent ac9f345 commit 727e1a2
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/scripts/concatenate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand All @@ -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());

Expand Down

0 comments on commit 727e1a2

Please sign in to comment.