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

Update MDX, support version 1 and 2, as well as the multiple ASTs generated #689

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ChristianMurphy
Copy link
Contributor

@ChristianMurphy ChristianMurphy commented Dec 31, 2022

mdx version 1 and version 2 have different syntax trees, this PR allows both versions' syntax trees to be previewed.

In addition, mdx internally uses multiple syntax trees.

Version 1 has:

  • a markdown AST (mdast/remark)
  • an HTML AST (hast/rehype)

Version 2 has:

  • a markdown AST (mdast/remark)
  • an HTML AST (hast/rehype)
  • a JavaScript AST (esast/recma)

This updates AST Explorer to have a preview for all version 1 and version 2 ASTs.
As well as updates transformers to allow for transforms on both version 1 and version 2.

This also adds support for syntax extensions, supported in MDX version 2; including GFM, Math, Directives, and more.

/cc @silvenon, @remcohaszing, @wooorm


Screenshots

mdx 2 preview with mdx 2 transformer
mdx ast preview

parser list for mdx
parser list

mdx 2 settings/plugins
mdx settings view

mdx version 1 and version 2 have different syntax tree, this allows both
versions' syntax trees to be previewed.
In addition, mdx internally uses multiple syntax trees.
Version 1 has a markdown AST (mdast/remark) and an HTML AST (hast/rehype).
Version 2 has a markdown AST (mdast/remark), an HTML AST (hast/rehype), and a
JavaScript AST (esast/recma).

This updates AST Explorer to have a preview for all version 1 and
version 2 ASTs.
As well as updates transformers to allow for transforms on both version
1 and version 2.
Copy link

@remcohaszing remcohaszing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I really love astexplorer, but I miss MDX2 support

website/yarn.lock Show resolved Hide resolved
@wooorm
Copy link
Contributor

wooorm commented Dec 31, 2022

Any reason the old AST is still around? Why not drop it?

@remcohaszing
Copy link

I also wouldn't mind dropping the old AST

@ChristianMurphy
Copy link
Contributor Author

ChristianMurphy commented Dec 31, 2022

Any reason the old AST is still around? Why not drop it?

A couple reasons.

  1. there are still plugins out there for mdx 1, which could benefit from having a tool to help inspect ASTs
  2. ASTExplorer has some precedence with keeping multiple major versions of parsers. For example:

I'd also be fine with dropping it, but defaulted to keeping it.

@wooorm
Copy link
Contributor

wooorm commented Jan 1, 2023

Re 2: Old versions seems to be around to support old snippet links, they seem to be hidden: fad47c2

Re 1: MDX 0 and 1 ASTs, IMO, are more the “absence” of an AST. It’s mdast, but replaces a html node with a jsx node, with a slightly different regex. And it adds import/export nodes, which are similarly strings, with different regexes.
I don’t think it’s very interesting to look at this AST. Now that there are nodes for things in v2, I do think it gets interesting, and we could start versioning to keep snippet links alive?

@remcohaszing
Copy link

I suppose MDX 3 should be added by now too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants