Socket
Socket
Sign inDemoInstall

@mdx-js/mdx

Package Overview
Dependencies
141
Maintainers
4
Versions
209
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @mdx-js/mdx

Parse MDX and transpile to JSX


Version published
Weekly downloads
2.7M
increased by1.4%
Maintainers
4
Install size
7.32 MB
Created
Weekly downloads
 

Package description

What is @mdx-js/mdx?

The @mdx-js/mdx package is a Markdown processor powered by JSX and React. It allows you to write JSX in your Markdown documents and render them as React components. This enables the embedding of dynamic content within static Markdown files, combining the simplicity of Markdown with the power of React.

What are @mdx-js/mdx's main functionalities?

Writing JSX in Markdown

Allows embedding JSX directly in your Markdown files, which can then be transformed into React components.

import React from 'react'
import { MDXProvider } from '@mdx-js/react'
import { mdx } from '@mdx-js/mdx'

const mdxContent = `
# Hello, MDX!

Some **bold** text and a component:

<MyComponent />
`

const MyComponent = () => <div>My Custom Component</div>

const run = async () => {
  const jsx = await mdx(mdxContent)
  // Now you can render the jsx with your preferred method
}

run()

Customizing Markdown components

Enables overriding default HTML tags with custom React components for a more personalized rendering of Markdown content.

import React from 'react'
import { MDXProvider } from '@mdx-js/react'

const components = {
  h1: props => <h1 style={{ color: 'tomato' }} {...props} />,
  p: props => <p style={{ fontSize: '18px' }} {...props} />
}

const MarkdownContent = () => (
  <MDXProvider components={components}>
    <YourMDXContent />
  </MDXProvider>
)

Using MDX files as pages in a React application

Facilitates the use of MDX files as if they were React components, making it easy to integrate them into a React application as pages or parts of pages.

import React from 'react'
import { MDXProvider } from '@mdx-js/react'
import YourMDXPage from './YourMDXPage.mdx'

const App = () => (
  <MDXProvider>
    <YourMDXPage />
  </MDXProvider>
)

Other packages similar to @mdx-js/mdx

Readme

Source

@mdx-js/mdx

Build Status lerna Chat

MDX implementation using remark.

Installation

npm:

npm i -S @mdx-js/mdx

Usage

const mdx = require('@mdx-js/mdx')

const result = await mdx(`
# Hello, MDX

I <3 Markdown and JSX
`)

console.log(result)

Yields:

export default ({components, ...props}) => (
  <MDXTag name="wrapper" components={components}>
    <MDXTag name="h1" components={components}>{`Hello, MDX`}</MDXTag>
    <MDXTag name="p" components={components}>{`I <3 Markdown and JSX`}</MDXTag>
  </MDXTag>
)

Contribute

See the Support and Contributing guidelines on the MDX website for ways to (get) help.

This project has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.

License

MIT © Compositor and Vercel

Keywords

FAQs

Last updated on 01 Dec 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc