Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mdx-js/runtime

Package Overview
Dependencies
Maintainers
4
Versions
178
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mdx-js/runtime

Parse and render MDX in a runtime environment

  • 2.0.0-ci.35
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
4
Weekly downloads
 
Created
Source

@mdx-js/runtime

Build Downloads Sponsors Backers Chat

A React component that evaluates MDX.

:warning: warning: this is not the preferred way to use MDX since it introduces a substantial amount of overhead and dramatically increases bundle sizes. It must not be used with user input that isn’t sandboxed.

Install

npm:

npm install @mdx-js/runtime

yarn:

yarn add @mdx-js/runtime

Use

Say we have the following scripts, example.jsx:

Props

The MDX Runtime component accepts two props:

NameDescription
componentsGlobally available components for the runtime
scopeVariables that are accessible in the JSX portion of the document
remarkPluginsArray of remark plugins

Example code

import React from 'react'
import {renderToString} from 'react-dom/server'
import MDX from '@mdx-js/runtime'

// Custom components:
const components = {
  h1: props => <h1 style={{color: 'tomato'}} {...props} />,
  Demo: () => <p>This is a demo component</p>
}

// Data available in MDX:
const scope = {
  somethingInScope: 1
}

// The MDX:
const children = `
# Hello, world!

{1 + somethingInScope}

<Demo />

<div>Here is the scope variable: {some}</div>
`

const result = renderToString(
  <MDX components={components} scope={scope} children={children} />
)

console.log(result)

Now, building, bundling, and finally running it, yields:

<h1 style="color:tomato">Hello, world!</h1>
2
<p>This is a demo component</p>

Contribute

See Contributing on mdxjs.com for ways to get started. See Support for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Compositor and Vercel

Keywords

FAQs

Package last updated on 07 Sep 2021

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc