-
Notifications
You must be signed in to change notification settings - Fork 238
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
Is it possible to escape HTML so I can use MDX in descriptions? #993
Comments
Hi @Preston-Landers, thanks for reporting this issue...we do in fact whitelist tags/elements using a regex pattern, mainly to url encode special chars that could otherwise be confused with JSX and cause compilation errors. That said, I am wondering if this strategy makes much sense because it does force us to limit MDX support, including all the built-in Docusaurus MDX components and even custom components. My first inclination is to revisit whether the escapes are even necessary, or if we should rather lean more on users to handle escaping or MDX formatting on their own. Interested to hear your thoughts. And yes, it really is a shame the |
Thanks for the reply. I think it probably does make sense to escape tags by default. I was wondering if there was a way to escape / bypass that, in case I know what I'm doing (spoiler: I don't). At least for my use cases, there's a certain amount of repeated content fragments that show up in my OpenAPI description fields and I was hoping to DRY them by putting them in a nice MDX component. That was my goal, anyway. I am not familiar with the source of this project but next week I can look into whether a pull request is feasible, but it would be good if a more knowledgeable developer could weigh in on the advisability of this. |
So I was thinking about this a bit more. I forked the repo and found the While that does seem to work, it doesn't get me all the way to my ultimate goal. The problem is the import statement. I'm not super familiar with this stuff, but it appears that the import statement must not be indented within MDX files otherwise it won't be executed as an import. But in these MDX blocks being emitted for the OpenAPI items, the block containing the import will be indented, so the compiler fails with unknown component. I think there might be a few potential solutions to that but I haven't fully explored them. Perhaps something to do with the markdownGenerators feature? Maybe I can use that to make my desired components be imported automatically. I assume there's no other existing functionality for a "global component import"? Any thoughts are welcome. Thanks! |
OK so I found what I think will be a cleaner solution, at least for me, which is simply a post-processing step in between the output of this plugin and the Docusaurus compilation step. I wrote a script that looks for blocks like this:
In my script I remove the block markers, dedent the whole block, and un-escape the < and > chars. That seems to do the trick, at lest for my goals. I can post my script here later. Or maybe the discussion forums would be a better place. |
Just pinging to say that I have the exact same issue. In previous version the clean did not exist and we used this extensively to render custom component or import other pages from the OpenAPI description. Would it be possible to add a parameter to disable the description cleaning for instance ? |
For what it's worth, here's that script I mentioned. This can be run as a post-processing step in between docusaurus-openapi-docs and the main docusaurus build, to un-escape "RAW" blocks. This lets you include custom components in an OpenAPI spec and have it rendered out in the site. https://gist.github.com/Preston-Landers/6f65b0b0e264eb02e71e5c7dee3813f8 |
Thank you but, for my use case I only needed to escape |
This is sort of related to #1012 except it's the inverse problem. We introduced escaping to avoid MDX parsing issues, but now that we're CSR it may no longer be necessary. Still, we'll need to test whether inline HTML/JSX like this will work. |
I want to reuse a common component (MDX) in several areas of my OpenAPI spec as shown in the example below.
The
<b>
tags are getting passed through, but the<
in<UnderConstruction />
is getting transformed to< UnderConstruction />
, which of course makes the component not render as desired. And<blink>
doesn't work, sadly. So it seems like maybe there's a whitelist of allowed tags.Is there an escape hatch if I want to get crazy and put MDX components in my OpenAPI description fields?
Gets translated to this MDX:
The text was updated successfully, but these errors were encountered: