Giter Site home page Giter Site logo

react-marked-markdown's Introduction

Travis branch npm version npm

React Marked Markdown

A react components package that helps you use Markdown easily.


Writing in Markdown is an amazing experience. Setting up all components and parser is kind of a pain.

Basic Usage

  • Install with npm install --save react-marked-markdown
  • Import component(s) you want
import {  MarkdownPreview  } from 'react-marked-markdown';

MarkdownPreview

Basic Markdown view

Display Markdown is really easy with MarkdownPreview component.

Here is a simple example :

import React from 'react';

import { MarkdownPreview } from 'react-marked-markdown';

const Post = ({ post }) => (
  <div>
    <h1>{ post.title }</h1>
    <MarkdownPreview value={ post.content }/>
  </div>
);

export default Post;

Options

Behind the scenes, react-marked-markdown uses marked as Markdown parser. So all marked options are available here.

Here is an example with default options :

<MarkdownPreview
  value="# Hey !"
  markedOptions={{
    gfm: true,
    tables: true,
    breaks: false,
    pedantic: false,
    sanitize: true,
    smartLists: true,
    smartypants: false
   }} />

A list of options can be found here.

Syntax highlighting

react-marked-markdown supports syntax highlighting with highlight.js

CSS Classes

All react-marked-markdown components are unstyled, meaning that you can style them as you want like every others React elements.

<MarkdownPreview className="ui post content" value="#Hey !" />

LiveMarkdownTextarea

LiveMarkdownTextarea allows you to write Markdown in a textarea and see a preview of what you are writing.

<LiveMarkdownTextarea
  placeholder="Enter your comment here."
  className="row"
  inputClassName="field column"
  previewClassName="column comment-preview"
/>

Create your own Markdown Editor

You can even create your own Markdown Editor with MarkdownPreview and MarkdownInput components.

As an example here is the code of LiveMarkdownTextarea component. Note that there is also a clear() method that we can call from parent component to clear the editor.

class LiveMarkdownTextarea extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      value: props.defaultValue ? props.defaultValue : '',
    };
  }
  handleTextChange(e) {
    this.setState({ value: e.target.value });
    if (this.props.onTextChange) {
      this.props.onTextChange(e.target.value);
    }
  }
  clear() {
    this.setState({ value: '' });
  }
  render() {
    const {
      placeholder,
      className,
      inputClassName,
      previewClassName,
    } = this.props;
    const { value } = this.state;
    return (
      <section className={ className }>
        <MarkdownInput
          placeholder={ placeholder }
          onChange={ this.handleTextChange.bind(this) }
          value={ value }
          className={ inputClassName }
        />

        <MarkdownPreview
          value={ value }
          className={ previewClassName }
        />
      </section>
    );
  }
}

react-marked-markdown's People

Contributors

vincent-p avatar greenkeeperio-bot avatar thsm avatar

Watchers

James Cloos avatar  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.