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

mdjsx-loader

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdjsx-loader

> A markdown loader with embedded jsx

  • 2.0.3
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
5
increased by150%
Maintainers
1
Weekly downloads
 
Created
Source

mdjsx-loader

A markdown loader with embedded jsx

Rationale

We wanted an expressive way to write markdown documentation for a react style-guide.

Configuration

Add this loader to your preferred filetypes. We use the .md extension.

// In webpack.config.js

module.exports = {
  /* Omitted */
  module: {
    loaders: [
      {
        test: /\.md$/,
        loaders: ['babel', 'mdjsx']
      }
    ]
  }
}

Notice the dependency on the babel loader. That is because the mdjsx loader creates an es6 module with jsx syntax.

Import

mdjsx-loader exports two values.

import Component, { attributes } from 'my-md-file.md';

Component // a react component which includes the compiled markdown and react components
attributes // the front-matter attributes from the markdown file

Syntax

$imports special front-matter attributes allows you to import any javascript module

---
$imports:
  '{ A, B }': 'module1'
  '* as C': 'module2'
  D: 'module3'
---

### My title

Use imported react components

<A>
  <D />
  <C.X>
    Hello there
  </C.X>
</A>

$attributes special variable gives you access to all front-matter attributes (except for the $imports)

---
propA: 'Hello World'
---

### My title

Use front-matter attributes

<span>{$attributes.propA}</span>

$props special variable gives you access to the component props.

in md file

# Hello world
<span>{$props.content}</span>

consumer

import Component from 'my-md-file.md';
import ReactDom from 'react-dom';

ReactDom.render(
  document.getElementById('root'),
  <Component content="This will be interpolated in span" />
)

FAQs

Package last updated on 10 Jul 2017

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