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

Elaborate on importing markdown #10542

Closed
1 of 2 tasks
jackrabbit128 opened this issue Oct 2, 2024 · 2 comments · Fixed by #10545
Closed
1 of 2 tasks

Elaborate on importing markdown #10542

jackrabbit128 opened this issue Oct 2, 2024 · 2 comments · Fixed by #10545
Labels
documentation The issue is related to the documentation of Docusaurus

Comments

@jackrabbit128
Copy link
Contributor

Have you read the Contributing Guidelines on issues?

Description

As absolute beginners in writing MDX, we were stumped by how to import markdown content in a .mdx file, even after reading the documentation.

Particularly confusing was how the name of the thing to import was derived from the file name.
In the documentation linked above

import PartialExample from './_markdown-partial-example.mdx';

where does PartialExample come from?

After too much trial and error, we determined that the name between import and from can in fact be anything, but its first letter must be uppercase:

  • import test from 'test.mdx'; did not work
  • import Test from 'test.mdx'; did work
  • import Anything from 'test.mdx'; also worked

This is implicitly shown in the documentation page, but we still don't understand why it behaves like that. I believe test.mdx is turned into javascript eventually, so presumably it exports some symbol/object/... How is it even possible that we can import this using any old name? Why does it need to start with uppercase?

Could you describe this more explicitly in the documentation?

I would create a PR, but I lack the terminology and understanding.

Self-service

  • I'd be willing to address this documentation request myself.
@jackrabbit128 jackrabbit128 added documentation The issue is related to the documentation of Docusaurus status: needs triage This issue has not been triaged by maintainers labels Oct 2, 2024
@Josh-Cena
Copy link
Collaborator

Josh-Cena commented Oct 2, 2024

This is just how JavaScript works: a default import can be imported with any name. It must be uppercase because that's how JSX works (lowercase for intrinsic elements, uppercase for components). There's nothing either MDX- or Docusaurus-specific here.

I will not object a one line addition saying "you can name the component anything you like but it must be capitalized".

@jackrabbit128
Copy link
Contributor Author

Must be shocking, a user that doesn't know the basics of javascript 😅

I'll create a PR to add the one line.

Josh-Cena added a commit that referenced this issue Oct 2, 2024
* docs: clarify component naming for markdown import (#10542)

* Apply review suggestion

Co-authored-by: Joshua Chen <[email protected]>

* Update website/docs/guides/markdown-features/markdown-features-react.mdx

---------

Co-authored-by: Joshua Chen <[email protected]>
@slorber slorber removed the status: needs triage This issue has not been triaged by maintainers label Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation The issue is related to the documentation of Docusaurus
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants