-
-
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
SVGs fail with unhelpful error messages #1197
Comments
MDX support JSX, not HTML. So comments or other non-JSX things will fail. There are ways online to turn SVG into JSX. |
Hmm. I didn't consider that. https://www.markdownguide.org/basic-syntax/#html says its up to the application to determine whether html tags are allowed in markdown. The https://mdxjs.com/getting-started#mdx page says you support the https://daringfireball.net/projects/markdown/syntax which says:
For my problem, it mostly works, except for the HTML comment and xml namespaces. I'm using the https://github.com/baerrach/gatsby-remark-plantuml to convert code blocks annotated with Do you have suggestions for how to solve this problem? |
I see it as |
Work around for mdx-js/mdx#1197
svgr looks like it takes an svg on disk to rewrite it into a JSX component. That's not going to solve my problem. I have a markdown file with a code block that contains plantuml code. I am using a remark plugin to transform that into an SVG. Perhaps I need to look at the transformation chain more closely and stop trying to hack it. This worked for gatsby-transformer-remark and I thought I could just get away with doing the same with gatsby-plugin-mdx. |
I see that you are the author of gatsby-remark-plantuml. Unfortunately, due to the way you wrote the plugin, it indeed does not work with MDX. The remark, rehype, and unified ecosystem is built around syntax trees, but you are injecting an HTML node: https://github.com/baerrach/gatsby-remark-plantuml/blob/6dbbd4971a52993131f573deb348cb9a1a9724b4/index.js#L237-L240, which will fail here because MDX does not understand a string of HTML. Here is a project that does stuff similarly to what you are doing, but around math: https://github.com/remarkjs/remark-math. That may be of inspiration? |
Thanks. There appears to be some different between gatstby-remark plugins and pure remark plugins. At least the last bit of the page https://www.gatsbyjs.org/packages/gatsby-remark-graphviz/ seems to indicate this but doesn't elaborate on why. https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-remark-graphviz/src/index.js is probably a good source of cut-n-paste for me. |
Thanks for your help. I can see that https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-remark-graphviz/src/index.js is doing exactly what I am already doing, so its not a good example. It looks like I need to write a second mdx-js version that renders the svg as compatible JSX. Unfortunately I don't have the time, or desire, to work out how to do that correctly. I'll go back to plain markdown support and hope that someone else comes along who want's MDX support and plantuml and is willing do submit a pull request. |
Subject of the issue
An inline svg fails with error messages that don't help trouble shoot the problem.
Your environment
Steps to reproduce
I've tried creating a codesandbox link https://codesandbox.io/s/mdx-js-and-svgs-0cvso
The problem will be that the "content/blog/test-1" and "content/blog/test-2" failures stop the gatsby site from being created correctly.
You'll need to manually fiddle with those to see "content/blog/test-3" working.
I've included the failing svg here and the steps taken to get it to work.
Failing SVG
This svg is generated by plantuml but its simple enough to see where the problems are.
This fails with the error
unknown: Unexpected token (8:1063)
and a stack trace.Unfortunately because the HTML is not pretty printed its hard to determine the problem.
Using Pretty Printed HTML
If I pretty-print the svg to become
Then the stack trace shows
Clearly marking the html comment as the problem.
Removing the HTML Comment
With the html comment removed the svg becomes:
the error becomes
Removing the XML namespaces
With the xml namespace removed the svg becomes:
And the svg is rendered correctly.
Expected behaviour
The svg should be rendered even if it contains html inline comments and xml namespaces.
Actual behaviour
mdx-js fails with errors.
The text was updated successfully, but these errors were encountered: