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

Details tag with tables or table syntax not correctly rendered after modifying AST and converting back to Markdown #1

Closed
4 tasks done
niravbhuva99 opened this issue Mar 2, 2024 · 18 comments
Labels
👀 no/external This makes more sense somewhere else 👎 phase/no Post cannot or will not be acted on

Comments

@niravbhuva99
Copy link

niravbhuva99 commented Mar 2, 2024

Initial checklist

Affected packages and versions

I have tested this issue using the latest version of the relevant packages.

Link to runnable example

runnable example

Steps to reproduce

  1. Include a table or table syntax within a <details> tag in Markdown.
  2. Convert Markdown to AST.
  3. Make modifications to the AST.(optional)
  4. Convert the modified AST back to Markdown.
  5. Observe that the <details> tag with the table or table syntax does not render correctly.

When modifying the Abstract Syntax Tree (AST) and converting it back to Markdown, the <details> tag containing either tables or table syntax is not rendered correctly. This issue arises specifically when converting Markdown to AST, making modifications, and then converting back to Markdown. The <details> tag fails to render as expected in the presence of table syntax within it.

Expected behavior

The <details> tag with the table or table syntax should render properly after converting the modified AST back to Markdown.

Actual behavior

Behavior with Table Syntax

Screenshot 2024-03-02 at 22 13 21

Behavior with Table Syntax Inside Details Tag

Screenshot 2024-03-02 at 22 10 40

Affected runtime and version

[email protected]

Affected package manager and version

"micromark-extension-mdxjs": "^3.0.0", "mdast-util-mdx": "^3.0.0", "mdast-util-from-markdown": "^2.0.0", "mdast-util-to-markdown": "^2.1.0", "@mdx-js/mdx": "^3.0.1", "@mdx-js/mdxast": "^1.1.1"

Affected OS and version

macOs

Build and bundle tools

No response

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Mar 2, 2024
@wooorm
Copy link
Member

wooorm commented Mar 3, 2024

Hey!

I think your previewer is wrong. You use a markdown previewer. It doesn’t render MDX 2+ properly.

@mdx-js/mdxast is ancient and archived and deprecated, don’t use it.

Your example looks fine. Both the input and output MDX are perfect.

Your screenshots don’t include details?
And what are you modifying? I don’t see anything in your linked example doing that.

@wooorm wooorm added the 🙉 open/needs-info This needs some more info label Mar 3, 2024

This comment has been minimized.

@niravbhuva99
Copy link
Author

Thank you for your reply

I changed the previewer, but the result remains the same. I want the Markdown to render the same result before and after the modification. The modification involves changing the link node. The modification process itself seems to be working fine; however, the issue lies in the Markdown rendering after converting the modified AST back to Markdown.

Markdown renders before the modification

Screenshot 2024-03-03 at 16 20 50

Markdown renders after the modification

Screenshot 2024-03-03 at 16 22 39

One observation is that it adds an extra line.

@wooorm
Copy link
Member

wooorm commented Mar 3, 2024

I want the Markdown [...]

[...] back to Markdown

This project isn’t about markdown. This is MDX. There is a real difference. Don’t use MDX things if you want markdown.

[...] to render the same result before and after the modification.

ASTs don’t work like that. ASTs are not CSTs.

The modification process itself seems to be working fine;

Which one? Your code does not modify.

the issue lies in the Markdown rendering after converting the modified AST back to Markdown.

That is not an issue. That’s how MDX works. You’re asking about XY problems and not providing code. Please explain your actual question. Please provide more info.

IMG_4335

@niravbhuva99
Copy link
Author

How can I convert MDX to AST and AST to MDX?

Is this the right method?
Screenshot 2024-03-03 at 17 03 23

@wooorm
Copy link
Member

wooorm commented Mar 3, 2024

Yes. Use .mdx as an extension though

@niravbhuva99
Copy link
Author

Now please clone this repository and run 'npm install'. After that, execute the 'index.js' file. This will generate the 'processes.mdx' file. Open the file with MDX Preview

@ChristianMurphy
Copy link
Member

@niravbhuva99 put your example in a sandbox.
Like https://stackblitz.com/ or https://codesandbox.io/

Nobody wants to run an unvetted executable on their machine, it's a security nightmare.

@niravbhuva99
Copy link
Author

here is the example

@ChristianMurphy
Copy link
Member

@niravbhuva99 you are generating a .md extension instead of .mdx.
Other than the extension, the generated file looks valid and it renders the same in https://mdxjs.com/playground/ as the original file did.

@wooorm
Copy link
Member

wooorm commented Mar 3, 2024

You're asking about a previewer. I don't know this previewer. This tools seems broken. If it's broken, ask the folks working on that tool. For us here: why do you care about some random preview tool? What do you actually want to do? MDX, markdown? What is your root problem?

@niravbhuva99
Copy link
Author

@ChristianMurphy Do you know which previewer the MDXjs playground uses?

@ChristianMurphy
Copy link
Member

@niravbhuva99 the MDX website uses MDX to render the preview https://github.com/mdx-js/mdx/blob/8f754f707207915bd34c3af8f9064e367c125a58/docs/_asset/editor.jsx

That doesn't answer the question what are you using and trying to do?

@niravbhuva99
Copy link
Author

I'm currently working with netlify-cms. My aim is to be able to preview MDX components embedded in my pages directly within Netlify CMS. I am also modifying the link nodes and then converting them back to MDX. It seems that after this modification, some of the MDX content does not render as expected.

@niravbhuva99
Copy link
Author

I am using a package called netlify-cms-widget-mdx.

@ChristianMurphy
Copy link
Member

ChristianMurphy commented Mar 4, 2024

It is broken because netlify-cms-widget-mdx uses mdx-scoped-runtime (https://github.com/karolis-sh/gatsby-mdx/blob/80de7cbdb1b514ade5266da086ab5490d3441ee4/packages/netlify-cms-widget-mdx/package.json#L26).
mdx-scoped-runtime uses MDX version 0 (alpha and unmaintained for years, https://github.com/karolis-sh/gatsby-mdx/blob/80de7cbdb1b514ade5266da086ab5490d3441ee4/packages/mdx-scoped-runtime/package.json#L26), we're on version 3 currently.

Ask netlify-cms-widget-mdx to update to use the latest MDX.

@ChristianMurphy ChristianMurphy closed this as not planned Won't fix, can't repro, duplicate, stale Mar 4, 2024
@ChristianMurphy ChristianMurphy added the 👀 no/external This makes more sense somewhere else label Mar 4, 2024

This comment has been minimized.

@ChristianMurphy ChristianMurphy removed 🙉 open/needs-info This needs some more info 🤞 phase/open Post is being triaged manually labels Mar 4, 2024

This comment has been minimized.

@github-actions github-actions bot added the 👎 phase/no Post cannot or will not be acted on label Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👀 no/external This makes more sense somewhere else 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

3 participants