Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Dollar Sign Escape #4363

Closed
32 changes: 18 additions & 14 deletions app/components/markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,25 @@ export function PreCode(props: { children: any }) {
);
}

function escapeDollarNumber(text: string) {
let escapedText = "";

for (let i = 0; i < text.length; i += 1) {
let char = text[i];
const nextChar = text[i + 1] || " ";

if (char === "$" && nextChar >= "0" && nextChar <= "9") {
char = "\\$";
function escapeDollarNumber(text: string): string {
let isInBlockCode = false;
return text.split('\n').map(line => {
if (line.trim() === '```' || line.trim() === '`') {
isInBlockCode = !isInBlockCode;
return line;
}

escapedText += char;
}

return escapedText;
if (!isInBlockCode) {
return line.split(/(`.*?`)/g).map((segment, index) => {
if (index % 2 === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now it only handle correctly for left but not the right one

image

return segment.replace(/(?<!\\)\$\d\w*([,.](\d\w*[,.])?\d\w*)?((?=\s\$)|(?!.*\$\B))/g, '\\$&');
} else {
return segment;
}
}).join('');
} else {
return line;
}
}).join('\n');
}

function escapeBrackets(text: string) {
Expand Down
Loading