🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

markdown-it-react-renderer

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

markdown-it-react-renderer

React renderer for Markdown-it

0.1.1
latest
Source
npm
Version published
Maintainers
1
Created
Source

Markdown React

Markdown to React Component converter.

This project uses Markdown parser from Markdown It library, but loosely supports its plugins.

Examples

Basic example

import MDReactComponent from 'markdown-react-js';

...

render() {
  return (
    <MDReactComponent text='Some text **with emphasis**.' />   
  );
}

or, using function instead of component:

import { mdReact } from 'markdown-react-js';

...

render() {
  return mdReact()('Some text **with emphasis**.');
}

Result:

<span>
  <p>
    Some text with <strong>emphasis</strong>.
  </p>
</span>

Using custom tags

const TAGS = {
  html: 'span', // root node, replaced by default
  strong: 'b',
  em: 'i'
}

...

render() {
  return (
    <MDReactComponent text='Some **bold** and *italic* text.' tags={TAGS} />   
  );
}

Result:

<span>
  <p>
    Some <b>bold</b> and <i>italic</i> text.
  </p>
</span>

Using custom component renderer

function handleIterate(Tag, props, children, level) {
  if (level === 1) {
    props = {
      ...props,
      className: 'first-level-class'
    };
  }

  if (Tag === 'a') {
    props = {
      ...props,
      className: 'link-class',
      href: props.href.replace('SOME_URL', 'http://example.com')
    };
  }

  return <Tag {...props}>{children}</Tag>;
}

...

render() {
  return (
    <MDReactComponent text='[This link](SOME_URL) has it’s own style.' onIterate={handleIterate} />   
  );
}

Result:

<span>
  <p class="first-level-class">
    <a href="http://example.com" class="link-class">This link</a> has it’s own style.
  </p>
</span>

Forked from

LICENSE

MIT

Keywords

markdown

FAQs

Package last updated on 07 Feb 2016

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