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 isInMultilineCode = false;
return text.split('\n').map(line => {
if (line.trim() === '```' || line.trim() === '`') {
isInMultilineCode = !isInMultilineCode;
return line;
}

escapedText += char;
}

return escapedText;
if (!isInMultilineCode) {
Copy link
Contributor

Choose a reason for hiding this comment

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

it's better

image

I think it should be fine for inside a table

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just made another edits. The previous one had issues rendering latex. Check the new one. Hopefully there are no more issues.

return line.replace(/(`[^`]*`)|(\$[0-9]+(?:[,.][0-9]+)*)/g, (match, inlineCode, number) => {
if (inlineCode) {
return inlineCode;
} else {
return `\\${number}`;
}
});
} else {
return line;
}
}).join('\n');
}

function _MarkDownContent(props: { content: string }) {
Expand Down
Loading