1. What is MDX?
MDX is a markup language that lets you use JSX (basically HTML and React). Currently, its version is MDX 2.
You can import components, like interactive charts or alerts, and embed them within your content.
This makes writing long-form content with components a blast 🚀.
You can learn more about MDX here.
This entire document is written in MDX.
2. How to setup environment for writing Markdown / MDX
You can write Markdown / MDX in any text editor you prefer. I would personally bias towards VSCode, but you can use any text editor you like. You can learn more about VSCode here.
2.1. Install VSCode
Start by downloading VSCode here.
2.2. Install VSCode Extensions
You can install VSCode extensions by clicking on the extension icon on the left side of the screen.
List of extensions I am using:
You can install as many extensions as you like. I would recommend you to install the ones I listed above. If you are not using or stop using them, consider uninstalling or disabling them to improve your overall VSCode performance or just create multiple VSCode profiles to manage your extensions.
3. Markdown First
MDX is Markdown first. This means that you can write Markdown and embed JSX components inside it. It is a fundmental knowledge to know how to write Markdown before jumping into MDX.
3.1. Basic Markdown Syntax
- Heading title or subtitle
- Paragraph a block of text
- Bold important text
- Italic emphasized text
- Blockquote a section that is quoted from another source
- Ordered List an ordered list
- Unordered List an unordered (bulleted) list
- Code a piece of computer code
- Horizontal Rule a thematic break in an HTML page
- Link a hyperlink, which is used to link from one page to another.
- Image embed an image in an HTML page
- Escaping escape characters which would otherwise have special meaning in Markdown’s formatting syntax
3.2. Markdown Extended Syntax
- Table an HTML table
- Table Alignments an HTML table with alignment
- Footnote define a footnote, which is used to give additional information about a topic
- Heading Ids a heading id, which is used to link to a heading
- Definition Lists a definition list, which is a list of terms, with a definition of each term
- Strikethrough strikethrough, which usually indicates a deletion in the document
- Task Lists a task list, which is used to represent the tasks needed to be done
4. Moving to MDX
Moving from Markdown to MDX may seem like a significant leap, but with the right approach, it becomes a seamless transition.
4.1. Introduction to JSX
Here's a rundown of the fundamental JSX syntax:
Let's break it down. Here are writing a functional component called HelloWorld
that returns a <div>Hello World</div>
. It has click event that logs Vola!
to the console when clicked.
Key to take away here is you can write <div>Hello World</div>
inside a javascript and that's the beauty of JSX syntax.
By applying the same concept, you can start writing MDX.
4.2. Importing Components
You can enhance your MDX documents by importing and using components from other files. Here's how:
Suppose you have a component called HelloWorld in a file named hello-world.jsx within a components folder:
You can easily import and use this component in your MDX document as follows:
By importing and incorporating components, you can extend the functionality of your MDX content and create more dynamic and interactive documents.
5. Conclusion
In this guide, we've uncovered the power of MDX, bridging Markdown's simplicity with JSX's interactivity. MDX empowers you to create engaging content by seamlessly integrating components into your documents. Whether you're writing documentation, blog posts, or educational materials, MDX offers a creative canvas to bring your ideas to life. Embrace MDX, combine Markdown and JSX, and watch your content flourish.
Happy writing!