-
Notifications
You must be signed in to change notification settings - Fork 59.4k
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
Fixing Dollar Sign Escape #4363
Conversation
@Algorithm5838 is attempting to deploy a commit to the NextChat Team on Vercel. A member of the Team first needs to authorize it. |
Your build has completed! |
quantizor/markdown-to-jsx#485 (comment) |
Unfortunately, I am unfamiliar with it, maybe others can help out. I just fixed the inconsistent escaping. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Algorithm5838 Just letting you know
app/components/markdown.tsx
Outdated
|
||
return escapedText; | ||
if (!isInCodeBlock) { | ||
return line.replace(/(?<!`.*|\\)\$\d+([,.](\d+[,.])?\d+)?(?!.*\$\B)(?!.*`)/g, '\\$&'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you may need to handle inside single backtick, table as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your input. It does handle inside single backticks, unless one used a backtick in one line and another in the next line. Also, it does handle tables as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this?
function escapeDollarNumber(text: string): string {
let isInCode = false;
return text.split('\n').map(line => {
if (line.trim() === '```' || line.trim() === '`') {
isInCode = !isInCode;
return line;
}
if (!isInCode) {
return line.replace(/(?<!`.*|\\)\$\d+([,.](\d+[,.])?\d+)?(?!.*\$\B)(?!.*`)/g, '\\$&');
} else {
return line;
}
}).join('\n');
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your input. It does handle inside single backticks, unless one used a backtick in one line and another in the next line. Also, it does handle tables as well.
However, it still doesn't handle properly in your deployment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I will try to fix it.
Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app/components/markdown.tsx
Outdated
return line; | ||
} | ||
if (!isInCode) { | ||
return line.replace(/(?<!\\)\$\d+([,.](\d+[,.])?\d+)?(?!.*\$\B)(?!`+)/g, '\\$&'); | ||
if (!isInMultilineCode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return inlineCode; | ||
if (!isInBlockCode) { | ||
return line.split(/(`.*?`)/g).map((segment, index) => { | ||
if (index % 2 === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app/components/markdown.tsx
Outdated
@@ -109,7 +109,7 @@ function escapeDollarNumber(text: string): string { | |||
if (!isInBlockCode) { | |||
return line.split(/(`.*?`)/g).map((segment, index) => { | |||
if (index % 2 === 0) { | |||
return segment.replace(/(?<!\\)\$\d+([,.](\d+[,.])?\d+)?(?!.*\$\B)/g, '\\$&'); | |||
return segment.replace(/(?<!\\)\$\d+([,.](\d+[,.])?\d+)?(?!.*\$\.)/g, '\\$&'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, there is a new issue with: $1$
, or any other number. It always escapes numbers. I will look into it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, there is a new issue with:
$1$
, or any other number. It always escapes numbers. I will look into it.
@Algorithm5838 you right
here is the pattern for a test
$1$ $1$
$1 $2 $3 $3
`$1` $2 $3 `$4`
$x$ $hello world$ $x$ $1 $2 $3 $4
$x$ $hello world$ $x$ $1 $2 $3 $4 $x$ $hello world$ $x$
$1 $2 $3 $4 $x$
$1 2 $3 $4 $5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Improve the implementation of the dollar sign escape to address the issues with LaTeX.
Update: Done and ready for merge.