Home

Awesome

MarkPlus

<img src="https://markpluslabs.github.io/react-markplus/icon.svg" alt="icon" width="256" height="256"/>

A React markdown editor and previewer.

Demos

Installation

yarn add react-markplus

Usage

import MarkPlus from 'react-markplus';

<MarkPlus markdown="# Hello world!" />;

markdown

Initial markdown text to load into the editor.

<MarkPlus markdown="# Hello world!" />

Default value is ''.

onChange

A callback function to be invoked automatically when markdown text changes.

<MarkPlus
  onChange={(markdown) => {
    console.log('markdown text changed to:', markdown);
  }}
/>

Default value is () => {}.

onPreviewChange

A callback function to be invoked automatidally when preview html changes.

<MarkPlus
  onPreviewChange={(html) => {
    console.log('preview html changed to:', html);
  }}
/>

Default value is () => {}.

toolbar

Show, hide or remove toolbar.

<MarkPlus toolbar="show" />

3 possible values:

Default value: show.

mode

Display editor, preview or both.

<MarkPlus mode="both" />

3 possible values:

Default value: both.

theme

Overall theme: light, dark or auto:

<MarkPlus theme="auto" />

3 possible values:

Default value: auto.

toolbarItems

You may configure the toolbar freely.

<MarkPlus toolbarItems={['about', '|', 'bold', 'italic']} />

A toolbar item could be either a string or a ReactElement. For toolbar items included with library, you may just specify a string. For your own custom toolbar items, please specify a ReactElement.

Included toolbar Items

Default toolbar items

import { defaultToolbarItems } from 'react-markplus';

Its value is:

[
  'about',
  '|',
  'bold',
  'italic',
  'strikethrough',
  'underline',
  'mark',
  '|',
  'emoji',
  'fontawesome',
  '|',
  'quote',
  'unordered-list',
  'ordered-list',
  'unchecked-list',
  'checked-list',
  '|',
  'link',
  'image',
  'code',
  'table',
  '|',
  'math',
  'mermaid',
  'chartjs',
];

You may add or remote items from it to customize your own toolbar.

Custom toolbar item

Here is a sample to create and insert a custom toolbar item:

<MarkPlus
  toolbarItems={[
    'about',
    '|',
    <i
      key="preferences"
      title="Preferences"
      className="fa fa-cog"
      onClick={() => {
        console.log('Todo: display a preferences modal');
      }}
    ></i>,
  ]}
/>