[READ-ONLY] Mirror of https://github.com/Schniz/draft-js-create-inline-style-plugin. Handle Draft.js' inline styles as if they were controlled by strategies 馃挜
0

Configure Feed

Select the types of activity you want to include in your feed.

JavaScript 69.2%
Other 30.8%
2 1 0

Clone this repository

https://tangled.org/schlez.in/draft-js-create-inline-style-plugin https://tangled.org/did:plc:eabdiyuk6ouhmeroa3ccjdht
git@tangled.org:schlez.in/draft-js-create-inline-style-plugin git@tangled.org:did:plc:eabdiyuk6ouhmeroa3ccjdht

For self-hosted knots, clone URLs may differ based on your setup.



README.md

draft-js-create-inline-style-plugin#

Creates a new plugin for using inline styles as decorators.

Demo

WAT#

Currently, There is no way of using nested decorators, but using decorators is so fun. So the proposed solution is to handle Draft.js' inline styles as if they were controlled by decorators.

Installation 馃崝#

npm install --save draft-js-create-inline-style-plugin

Usage:#

import React from 'react';
import Editor from 'draft-js-plugins-editor';
import findWithRegex from 'find-with-regex';
import createInlineStylePlugin from 'draft-js-create-inline-style-plugin';

const STAR_REGEX = /\*.+\*/g;
const TILDE_REGEX = /~.+~/g;

const kindOfMarkdownPlugin = createInlineStylePlugin([{
	strategy: (contentBlock, callback) => findWithRegex(STAR_REGEX, contentBlock, callback),
	styles: ['BOLD']
}, {
	strategy: (contentBlock, callback) => findWithRegex(TILDE_REGEX, contentBlock, callback),
	styles: ['UNDERLINE']
}]);

const MyEditor = ({ editorState, onChange }) => (
  <div>
    <Editor
      editorState={ editorState }
      onChange={ onChange }
      plugins={ [kindOfMarkdownPlugin] }
    />
  </div>
);

export default MyEditor;