-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Backslash sometimes inserted when using $ in text #606
Comments
This ended up being due to prettier. I'd set it up to run on pre-commit and missed the fact that it was also formatting .mdx files 🤦♂ Sorry to waste your time. |
I'm going to reopen since MDX output is in fact different than remark's. It's a bug in the template literal escaping that we'll need to address. |
Just to be clear, it was Prettier that did the extra escape, not Remark. I
switched to MDX and accidentally had Prettier format my .mdx file in the
same commit, and incorrectly attributed the inserted backslash to the
Remark-MDX switch.
…On Fri, Jun 21, 2019, 9:54 AM John Otander ***@***.***> wrote:
Reopened #606 <#606>.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#606?email_source=notifications&email_token=AAPLJZBANLAMLUDBNNWOUM3P3TMRJA5CNFSM4HY33TUKYY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOSDORAVY#event-2430406743>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAPLJZDEEMAYFCVHGWOWQXDP3TMRJANCNFSM4HY33TUA>
.
|
Should mdx handle $ and remove the \ when output, since $ must be escaped due to math support - see prettier/prettier#6213. |
Yeah, ultimately we should detect the presence of In the ideal world Prettier wouldn't add the |
I even tried something like |
Prettier escapes all "$" characters that aren't used for inline math. This ensures MDX doesn't double escape the "\$", otherwise "\$" ends up rendered in the document. Closes #606
* Don't double escape "$" characters that are alread escaped Prettier escapes all "$" characters that aren't used for inline math. This ensures MDX doesn't double escape the "\$", otherwise "\$" ends up rendered in the document. Closes #606 * Use proper negative lookahead regex * Add more tests around dollar escaping * Make eslint happy
Sorry to comment on a closed issue but I'm still seeing MDX render {
"name": "tailwind-jobs",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"@mdx-js/loader": "^1.6.1",
"@next/mdx": "^9.4.0",
"@tailwindcss/ui": "^0.3.0",
"autoprefixer": "^9.7.6",
"next": "9.4.0",
"postcss-nesting": "^7.0.1",
"react": "16.13.1",
"react-dom": "16.13.1",
"tailwindcss": "^1.4.6"
}
} Is there a dependency I need to explicitly add that I'm missing, to make sure I'm actually grabbing a recent enough version to get this fix? |
Hey @johno Is this still being worked on? Still having the |
Putting the text inside a p tag has prevented Prettier from adding a the
|
Hey @lourd - I'm having the same issue (pre-commit hook w/ Prettier). How did you prevent Prettier from doing this? Thanks in advance! |
This PR changes the internals of the core `@mdx-js/mdx` package to generate a JavaScript syntax tree instead of a string. This fixes escaping issues such as #1219. It makes `mdx-hast-to-jsx` much more palatable. It also prevents several Babel parses. It paves the way for passing in Babel plugins, which is useful for users, but also for us to compile to `React.createElement`, `_jsx`, or Vue’s `h` calls directly and make MDX’s output directly usable. * `babel-plugin-apply-mdx-type-props`: add `parentType` * `mdx`: use `rehype-minify-whitespace` to remove superfluous whitespace * `mdx`: use `hast-util-to-estree` to transform hast to estree * `mdx`: use `estree-to-babel` to transform estree to Babel * `mdx`: generate estree/Babel instead of strings * `mdx`: use `@babel/generator` to serialize Babel AST * `vue`: stop supporting the react transform: (it doesn’t make sense) * `vue`: fix support for props to components Related to GH-741. Related to GH-1152. Closes GH-606. Closes GH-1028. Closes GH-1219.
This PR changes the internals of the core `@mdx-js/mdx` package to generate a JavaScript syntax tree instead of a string. This fixes escaping issues such as #1219. It makes `mdx-hast-to-jsx` much more palatable. It also prevents several Babel parses. It paves the way for passing in Babel plugins, which is useful for users, but also for us to compile to `React.createElement`, `_jsx`, or Vue’s `h` calls directly and make MDX’s output directly usable. * `babel-plugin-apply-mdx-type-props`: add `parentType` * `mdx`: use `rehype-minify-whitespace` to remove superfluous whitespace * `mdx`: use `hast-util-to-estree` to transform hast to estree * `mdx`: use `estree-to-babel` to transform estree to Babel * `mdx`: generate estree/Babel instead of strings * `mdx`: use `@babel/generator` to serialize Babel AST * `vue`: stop supporting the react transform: (it doesn’t make sense) * `vue`: fix support for props to components Related to GH-741. Related to GH-1152. Closes GH-606. Closes GH-1028. Closes GH-1219.
This PR changes the internals of the core `@mdx-js/mdx` package to generate a JavaScript syntax tree instead of a string. This fixes escaping issues such as #1219. It makes `mdx-hast-to-jsx` much more palatable. It also prevents several Babel parses. It paves the way for passing in Babel plugins, which is useful for users, but also for us to compile to `React.createElement`, `_jsx`, or Vue’s `h` calls directly and make MDX’s output directly usable. * `babel-plugin-apply-mdx-type-props`: add `parentType` * `mdx`: use `rehype-minify-whitespace` to remove superfluous whitespace * `mdx`: use `hast-util-to-estree` to transform hast to estree * `mdx`: use `estree-to-babel` to transform estree to Babel * `mdx`: generate estree/Babel instead of strings * `mdx`: use `@babel/generator` to serialize Babel AST * `vue`: stop supporting the react transform: (it doesn’t make sense) * `vue`: fix support for props to components Related to GH-741. Related to GH-1152. Closes GH-606. Closes GH-1028. Closes GH-1219. Closes GH-1382. Reviewed-by: Christian Murphy <[email protected]>
This PR changes the internals of the core `@mdx-js/mdx` package to generate a JavaScript syntax tree instead of a string. This fixes escaping issues such as #1219. It makes `mdx-hast-to-jsx` much more palatable. It also prevents several Babel parses. It paves the way for passing in Babel plugins, which is useful for users, but also for us to compile to `React.createElement`, `_jsx`, or Vue’s `h` calls directly and make MDX’s output directly usable. * `babel-plugin-apply-mdx-type-props`: add `parentType` * `mdx`: use `rehype-minify-whitespace` to remove superfluous whitespace * `mdx`: use `hast-util-to-estree` to transform hast to estree * `mdx`: use `estree-to-babel` to transform estree to Babel * `mdx`: generate estree/Babel instead of strings * `mdx`: use `@babel/generator` to serialize Babel AST * `vue`: stop supporting the react transform: (it doesn’t make sense) * `vue`: fix support for props to components Related to GH-741. Related to GH-1152. Closes GH-606. Closes GH-1028. Closes GH-1219. Closes GH-1382. Reviewed-by: Christian Murphy <[email protected]>
As prettier has finally been fixed to not re-add it. See: * prettier/prettier#6213 * mdx-js/mdx#606
If anyone else runs into this problem like I did today, here's how I fixed it. I needed prettier to stop adding in the backslash. I first started looking in the prettier settings to see if I could turn off the math portion but that ended up being a dead end. I realized that I needed to tell prettier to simply ignore it. I first tried to my prettier ignore file: https://media.lauraleeflores.com/llu5D48j that works however it will ignore the page completely and that was not ideal for me. The solution that worked was to simply ignore a portion of the file. You can learn more about that here: https://prettier.io/docs/en/ignore.html Mine is an mdx file so this is how I ignored it: https://media.lauraleeflores.com/YEuR1dYj I hope that helps someone who runs into the same problem. |
Is there any plan on fixing this for For example, in a MDX file:
Prettier automatically changes it to:
Which breaks MDX parsers -- this is no longer a valid Javascript/JSX expression. Using Prettier's recommended Thanks |
The |
To add (or explicitly clarify): The JS in braces are a new MDX 2 thing. So, we just added support for them. Now other tools have to support them too! |
I noticed that on some parts of my portfolio site (made with gatsby and gatsby-mdx), there are extra backslashes being inserted in some places where dollar signs are used. For example:
\$
— there are 6 occurrences on the page. There are 12 usages of$
, though — not every $ is preceded by a backslash.It only started happening when I switched from Remark to MDX. I didn't notice it when I did the initial switch.
Environment
Steps to reproduce
Clone my portfolio repo, https://github.com/lourd/descioli-design, and run it. No additional configuration needed.
Expected behaviour
No extra backslashes.
Actual behaviour
Extra backslashes
The text was updated successfully, but these errors were encountered: