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

Error: Cannot handle unknown node raw when using with @mdx-js/mdx #125

Open
michaeloliverx opened this issue Nov 16, 2021 · 6 comments
Open
Labels
Bug Something isn't working Enhancement New feature or request You can do this The idea is well specified and good for a PR

Comments

@michaeloliverx
Copy link
Contributor

I am trying to use remark-shiki-twoslash with @mdx-js/mdx@2.0.0-rc.2 (v2) and have the following error:

Error: Cannot handle unknown node `raw`

Full details are on this issue mdx-js/mdx#1820

@orta
Copy link
Contributor

orta commented Nov 16, 2021

Cool, makes sense, you're welcome to take a look at switching to rehype raw 👍🏻

@cseas
Copy link

cseas commented Jan 5, 2023

I was getting this error when specifying filename in the markdown.

Changed

```ts:myFilename.ts

to

```ts

and this error went away.

@kasper573
Copy link

kasper573 commented Sep 7, 2023

If anyone else is struggling with this, and also tried going down the rehype-raw rabbit hole (and failed), I've made a workaround.

I created a remark plugin that you can add directly after remark-shiki-twoslash that will make it compatible with mdx v2:

// This is an excerpt from a @docusaurus/preset-classic docs configuration object
remarkPlugins: [
  require("remark-shiki-twoslash"),
  require("remark-html-to-jsx"),
],

remark-html-to-jsx finds any nodes with the type html (which is what remark-shiki-twoslash outputs) and converts that html into JSX nodes by using reacts dangerouslySetInnerHTML property. It's a total hack, but it works great for my needs. Figured I'd share:

https://github.com/ksandin/yas/blob/dcf62f7637f7a85f9ce1598851bc26d938314df5/packages/remark-html-to-jsx/index.js

@kamranayub
Copy link

Running into this now with Docusaurus v3 stable release. I will try to use @ksandin's workaround (it's not a published package, so need to bring it in manually).

@kamranayub
Copy link

So, I patched docusaurus-preset-shiki-twoslash using the remark-html-to-jsx idea like this:

// at the top
const remarkHtmlToJsx = require('./remark-html-to-jsx')

// in `addTwoslash`
a.beforeDefaultRemarkPlugins.push([twoslash, options], remarkHtmlToJsx)

And that does "fix" the error, but it appears the resulting HTML set is not processed through MDXComponents:

image

That div should really be CodeBlock, and so Twoslash does compile/run its logic but because the React component isn't used, there's only static HTML on the page without annotations/styles.

tonyxiao added a commit to tonyxiao/openSDKs that referenced this issue Dec 12, 2023
tonyxiao added a commit to tonyxiao/openSDKs that referenced this issue Dec 16, 2023
…for developing (#4)

* docs: mdx -> md with node-loader

* chore: eslint mdx file test imported component works

* docs: mdx is epic! Import real code into markdown files

* feat: Use `import()` to make our own mdxToMd that actually works w/o building and esbuild

* docs: remark-code-import and remark-shiki-twoslash working

But not together! See shikijs/twoslash#125 (comment)

* docs: Removed shiki does not work reliably. Table does though

* docs: Add remark toc

* docs: eslint-plugin-expect-type is daboom

Finally the right solution vs. markdown twoslash queries which is more appropriate in react/html context

* docs: Generate table of supported sdks via react!

* chore: Switching everything over to ESM

Can still ship cjs lib, but working in ESM

* chore: Fix linter issues

* fix: try to fix build

* chore: Force correct pre-install script

* fix: Jest test with esm modules

* chore: setup upterm to test

* fix: build commands by switching all to esm

* Revert "chore: setup upterm to test"

This reverts commit 4be5ed8.

* fix: missed apollo json

* Revert "Revert "chore: setup upterm to test""

This reverts commit 09e578d.

* fix: mdx build due to needing react-jsx

* Revert "Revert "Revert "chore: setup upterm to test"""

This reverts commit 58bded7.

* chore: Still publish cjs for now even if we fully work in esm

Don't want to have esm only package for now. Will have to dual publish
@Sainan
Copy link

Sainan commented May 14, 2024

So, this issue from 2021 means that docusaurus-preset-shiki-twoslash and remark-shiki-twoslash are currently completely unusable by anyone who dare use an up-to-date version of Docusaurus? Cool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Enhancement New feature or request You can do this The idea is well specified and good for a PR
Projects
None yet
Development

No branches or pull requests

6 participants