MDX and React
MDX allows React components inside Markdown making it more interactive:
export const Highlight = ({children, color}) => (
<span
style={{
backgroundColor: color,
borderRadius: '20px',
color: '#fff',
padding: '10px',
cursor: 'pointer',
}}
onClick={() => {
alert(`You clicked the color ${color} with label ${children}`)
}}>
{children}
</span>
);
This is <Highlight color="#25c2a0">Docusaurus green</Highlight> !
This is <Highlight color="#1877F2">Facebook blue</Highlight> !
This is Docusaurus green !
This is Facebook blue !
Custom Highlight
To render the custom highlights:
import React, { type ReactNode } from "react";
export default function Highlight({
children,
color,
}: {
children: ReactNode;
color: string;
}): JSX.Element {
return (
<span
style={{
backgroundColor: color,
borderRadius: "15px",
color: "#fff",
padding: '0.5rem',
}}
>
{children}
</span>
);
}
And some <Highlight color="#1877F2">custom markup</Highlight>
- #1da1f2 <Highlight color="#1da1f2">Primary color</Highlight>
And so on..
-
And some custom markup
-
#1da1f2 Primary color
-
#878787 Secondary color
-
#41B883 Fresh Green
Icons
Font Awesome
Font Awesome Icons. The file MDXComponents.tsx
or MDXComponents.js
should be present in the src/theme
folder.
- npm
- Yarn
- pnpm
npm install --save @fontawesome/fontawesome-svg-core @fontawesome/free-solid-svg-icons @fortawesome/react-fontawesome
yarn add @fontawesome/fontawesome-svg-core @fontawesome/free-solid-svg-icons @fortawesome/react-fontawesome
pnpm add @fontawesome/fontawesome-svg-core @fontawesome/free-solid-svg-icons @fortawesome/react-fontawesome
- npm
- Yarn
- pnpm
npm install --save @fontawesome/free-regular-svg-icons @fontawesome/free-brands-svg-icons
yarn add @fontawesome/free-regular-svg-icons @fontawesome/free-brands-svg-icons
pnpm add @fontawesome/free-regular-svg-icons @fontawesome/free-brands-svg-icons
- JavaScript
- TypeScript
import React from "react";
// Import the original mapper
import MDXComponents from "@theme-original/MDXComponents";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { library } from "@fortawesome/fontawesome-svg-core";
import { fab } from "@fortawesome/free-brands-svg-icons";
import { fas } from "@fortawesome/free-solid-svg-icons";
library.add(fab, fas);
export default {
...MDXComponents,
FAIcon: FontAwesomeIcon, // Make the FontAwesomeIcon component available in MDX as <icon />.
};
import React from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { library } from "@fortawesome/fontawesome-svg-core";
import { fab } from "@fortawesome/free-brands-svg-icons";
import { fas } from "@fortawesome/free-solid-svg-icons";
import MDXComponents from "@theme-original/MDXComponents";
import Code from '@theme/MDXComponents/Code';
library.add(fab, fas);
interface Components {
[key: string]: React.ComponentType<any>;
}
const components: Components = {
...MDXComponents,
FAIcon: FontAwesomeIcon,
Code,
};
export default components;
- JavaScript
- TypeScript
import React from "react";
// Import the original mapper
import MDXComponents from "@theme-original/MDXComponents";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { library } from "@fortawesome/fontawesome-svg-core";
import { fab } from "@fortawesome/free-brands-svg-icons";
import { fas } from "@fortawesome/free-solid-svg-icons";
library.add(fab, fas);
export default {
...MDXComponents,
FAIcon: FontAwesomeIcon, // Make the FontAwesomeIcon component available in MDX as <icon />.
};
import React from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { library } from "@fortawesome/fontawesome-svg-core";
import { fab } from "@fortawesome/free-brands-svg-icons";
import { fas } from "@fortawesome/free-solid-svg-icons";
import MDXComponents from "@theme-original/MDXComponents";
import Code from '@theme/MDXComponents/Code';
library.add(fab, fas);
interface Components {
[key: string]: React.ComponentType<any>;
}
const components: Components = {
...MDXComponents,
FAIcon: FontAwesomeIcon,
Code,
};
export default components;
<FAIcon icon="fa-brands fa-github" size="3x" />
<FAIcon icon="fa-brands fa-x-twitter" size="3x" />
<FAIcon icon="fa-brands fa-youtube" size="3x" />
<FAIcon icon="fa-brands fa-linkedin" size="3x" />
<FAIcon icon="fa-brands fa-python" size="3x" />
<FAIcon icon="fa-brands fa-js" size="3x" />
<FAIcon icon="fa-brands fa-react" size="3x" />
Custom Admonitions
To render these custom admonition in your .mdx
, put import Admonition from "@theme/Admonition";
JSX
Use plugins to introduce shorter syntax for the most commonly used JSX elements in your project.
Use plugins to introduce shorter syntax for the most commonly used JSX elements in your project.
Use plugins to introduce shorter syntax for the most commonly used JSX elements in your project.
Use plugins to introduce shorter syntax for the most commonly used JSX elements in your project.
Swizzle
Custom tip
This is a security warning
This is a security warning
The quick credit.
Discord
Discord
Release Test
HTML Embeds
<pre>
<b>Input: </b>1 2 3 4{'\n'}
<b>Output: </b>"366300745"{'\n'}
</pre>
Input: 1 2 3 4 Output: "366300745"