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

[DRAFT] RFC: Api change for mdx/md file parsing #5960

Closed
1 of 2 tasks
armano2 opened this issue Nov 16, 2021 · 6 comments
Closed
1 of 2 tasks

[DRAFT] RFC: Api change for mdx/md file parsing #5960

armano2 opened this issue Nov 16, 2021 · 6 comments
Labels
proposal This issue is a proposal, usually non-trivial change

Comments

@armano2
Copy link
Contributor

armano2 commented Nov 16, 2021

note: this is early draft

Have you read the Contributing Guidelines on issues?

Description

Problem
In current architecture there is no way to change parser/implementation of parser

  • each of plugins require its own implementation of md/mdx parser
  • there is no way to change default behavior of parser
  • md files are not properly supported
  • there is no way to author plugin that changes how markdown files are parsed across website

Solution

  • remove custom parsing code from each plugin and all remark/mdx configurations out of them
  • create new package @docosaurus/plugin-mdx that is used as "fallback" md/x file parsing

related issues: #5757 #4029

Has this been requested on Canny?

No response

Motivation

support for simple md files

API design

No response

Have you tried building it?

No response

Self-service

  • I'd be willing to contribute this feature to Docusaurus myself.
@armano2 armano2 added feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. status: needs triage This issue has not been triaged by maintainers labels Nov 16, 2021
@Josh-Cena
Copy link
Collaborator

Yeah, our Markdown infra is quite messy (also #4625)... We have an mdx-loader to load the MD files, a fallback loader when importing Markdown from outside the plugin, and a linkifier in each plugin because only the plugin knows how the MD file is mapped to URL paths. I think we should have a global protocol so plugins can communicate about the file -> URL mapping. I'm aware of the challenges the ts-eslint website is facing

@Josh-Cena Josh-Cena added proposal This issue is a proposal, usually non-trivial change and removed feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. status: needs triage This issue has not been triaged by maintainers labels Nov 17, 2021
@slorber
Copy link
Collaborator

slorber commented Nov 17, 2021

each of plugins require its own implementation of md/mdx parser

Yes, there's a lot of boilerplate atm for plugin authors atm and we should provide better utils to factorize that

there is no way to change default behavior of parser

Yes, we should decouple more from MDX. For example, if your parser emits some kind of MD AST and you want to be able to render it with a runtime lib, this must be possible.

We should:

  • not assume that the content prop is a React component
  • allow to plugin a renderer of content
  • provide a custom parsing hook with unknown return type.

md files are not properly supported

MDX 2 seems to improve on CommonMark compatibility, if this is what you mean:
https://mdxjs.com/blog/v2/#architectural-improvements

there is no way to author plugin that changes how markdown files are parsed across website

Related to #4625

@slorber
Copy link
Collaborator

slorber commented Nov 17, 2021

I think we should have a global protocol so plugins can communicate about the file -> URL mapping.

Yes, we need some kind of reverse URL mapping. Currently, one plugin cannot link to another by using md file paths, which is confusing.

@armano2
Copy link
Contributor Author

armano2 commented Nov 17, 2021

MDX 2 seems to improve on CommonMark compatibility, if this is what you mean: https://mdxjs.com/blog/v2/#architectural-improvements

yes its better but MDX 2 removed support for html comments <!-- -->

@armano2
Copy link
Contributor Author

armano2 commented Nov 19, 2021

i just relalased that this is a duplicate of #3018

@Josh-Cena
Copy link
Collaborator

Well, I feel like this is a mix of #4625, #3018, and what I'm going to implement in #5568

@armano2 armano2 closed this as completed Dec 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue is a proposal, usually non-trivial change
Projects
None yet
Development

No branches or pull requests

3 participants