Skip to content

Commit

Permalink
prettier#16160: restore unescaped underscore
Browse files Browse the repository at this point in the history
  • Loading branch information
Yana Peycheva committed Apr 29, 2024
1 parent 1264a4c commit e50975f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/language-markdown/parser-markdown.js
Expand Up @@ -27,6 +27,8 @@ import wikiLink from "./unified-plugins/wiki-link.js";
*/
function createParse({ isMDX }) {
return (text) => {
text = restoreUnescapedUnderscore(text)

const processor = unified()
.use(remarkParse, {
commonmark: true,
Expand All @@ -43,6 +45,17 @@ function createParse({ isMDX }) {
};
}

function restoreUnescapedUnderscore(text) {
const textArray = text.split(" ");
for (let i = 0; i < textArray.length; i++) {
const nrOfUnderscores = (textArray[i].match(/(?<!\\)_/g) || []).length;
if (nrOfUnderscores !== 0 && nrOfUnderscores !== 2) {
textArray[i] = textArray[i].replaceAll("_","\\_");
}
}
return textArray.join(" ")
}

function noop() {}

const baseParser = {
Expand Down

0 comments on commit e50975f

Please sign in to comment.