Socket
Socket
Sign inDemoInstall

remark-mdx

Package Overview
Dependencies
30
Maintainers
4
Versions
125
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    remark-mdx

remark plugin to add support for mdx


Version published
Weekly downloads
3.1M
decreased by-2.13%
Maintainers
4
Created
Weekly downloads
 

Package description

What is remark-mdx?

The remark-mdx npm package is a plugin for remark, a markdown processor powered by plugins part of the unified collective. It enables MDX syntax in markdown documents processed by remark. MDX is an authorable format that lets you seamlessly write JSX in your markdown documents. This package allows you to parse and serialize MDX files, making it possible to use MDX with the remark ecosystem.

What are remark-mdx's main functionalities?

Parsing MDX syntax

This feature allows you to parse strings of MDX and transform them into a markdown abstract syntax tree (AST).

const remark = require('remark');
const remarkMdx = require('remark-mdx');

remark().use(remarkMdx).processSync('<h1>Hello, MDX!</h1>').toString();

Serializing MDX

This feature enables you to serialize the markdown AST back into a string of MDX, which can then be saved to a file or processed further.

const remark = require('remark');
const remarkMdx = require('remark-mdx');
const vfile = require('to-vfile');

const file = vfile.readSync('example.mdx');
const result = remark().use(remarkMdx).processSync(file).toString();
console.log(result);

Other packages similar to remark-mdx

Readme

Source

remark-mdx

Build Downloads Size Sponsors Backers Chat

remark plugin to support MDX (Markdown 💛 JSX).

This isn’t useful on its own, you’ll probably want to do combine it with other plugins or do tree traversal yourself to compile to things!

It’s used in MDXjs.

Install

npm:

npm install remark-mdx

Use

Say we have the following file, example.md:

# Hello, {data.to}

<Body>
{message}
</Body>

Best, {data.from}

And our script, example.js, looks as follows:

var vfile = require('to-vfile')
var report = require('vfile-reporter')
var unified = require('unified')
var parse = require('remark-parse')
var stringify = require('remark-stringify')
var mdx = require('remark-mdx')

unified()
  .use(parse, {position: false})
  .use(stringify)
  .use(mdx)
  .use(debug)
  .process(vfile.readSync('example.md'), function (err, file) {
    if (err) throw err
    console.log(String(file))
  })

function debug() {
  return console.dir
}

Now, running node example yields:

{
  type: 'root',
  children: [
    {
      type: 'heading',
      depth: 1,
      children: [
        {type: 'text', value: 'Hello, '},
        {type: 'mdxSpanExpression', value: 'data.to'}
      ]
    },
    {
      type: 'mdxBlockElement',
      name: 'Body',
      attributes: [],
      children: [{type: 'mdxBlockExpression', value: 'message'}]
    },
    {
      type: 'paragraph',
      children: [
        {type: 'text', value: 'Best, '},
        {type: 'mdxSpanExpression', value: 'data.from'}
      ]
    }
  ]
}
# Hello, {data.to}

<Body>
  {
    message
  }
</Body>

Best, {data.from}

API

remark().use(mdx[, options])

Plugin to add support for MDX.

Security

Use of remark-mdx does not involve rehype (hast) or user content so there are no openings for cross-site scripting (XSS) attacks.

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, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer

Keywords

FAQs

Last updated on 27 Jul 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