Giter Site home page Giter Site logo

react-showdown's Introduction

react-showdown Build status Test coverage Dependency Status

Render React components within markdown and markdown as React components!

Features

Installation

npm install --save react-showdown

Use as React component

Really simple markdown example with ES6/JSX:

import { Markdown } from 'react-showdown';

render: () => {
    var markdown = '# Hello\n\nMore content...';
    return <Markdown markup={ markdown } />
}

Use a React component and use it within the markdown with ES6/JSX:

import { Markdown } from 'react-showdown';

const MyComponent extends Component {
	render() {
		return React.createElement(this.props.tag, null, this.props.children);
	}
};

render: () => {
    var markdown = '# Hello\n\n<MyComponent tag="strong">More Content...</MyComponent>';
    return <Markdown markup={ markdown } components={{ MyComponent }} />
}

Use the converter

Really simple markdown example:

var Converter = require('react-showdown').Converter;
var converter = new Converter();

var markdown = '# Hello\n\nMore content...';
var reactElement = converter.convert(markdown);

Use a React component and use it within the markdown:

var MyComponent = React.createClass({
	render: function() {
		return React.createElement(this.props.tag, null, this.props.children);
	}
});

var Converter = require('react-showdown').Converter;
var converter = new ReactShowdown.Converter({ components: { 'MyComponent': MyComponent }});

var markdown = '# Hello\n\n<MyComponent tag="strong">More Content...</MyComponent>';
var reactElement = converter.convert(markdown);

Available props / converter options

Converter options will be pushed forward to the showdown converter, please checkout the valid options section.

Just the components option is managed by this converter. It define the component name (tag name) to component React class definition (instance of React.createClass) mapping. See example above.

Credits

Project is based on the markdown parser Showdown and the "forgiving" htmlparser2.

Alternatives

react-showdown's People

Contributors

jerolimov avatar azaeres avatar justin-lau avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.