Git Product home page Git Product logo

draft-js-autolist-plugin's Introduction

Draft.js Auto-list Plugin

This is a plugin for the draft-js-plugins-editor, a plugin system that sits on top of Draft.js.

This plugin adds support for automatic unordered/ordered list creation within Facebook’s Draft.js editor based on the input text. It looks something like:

Auto-list creation in action

In short, the plugin will turn a sequence of Markdown-like lists into their actual HTML representation:

  • * will become an unordered list
  • - will become an unordered list
  • 1. will become an ordered list
  • 2. will become an ordered list
  • 123. will become an ordered list

You’ll notice that the plugin also enables support for breaking out of lists like you’d expect in a WYSIWYG editor. That is, if you press "Return" on an empty list item, the current block is turned back into a standard block type.

Usage

import createAutoListPlugin from 'draft-js-autolist-plugin'
const autoListPlugin = createAutoListPlugin()

This can then be passed into a draft-js-plugins-editor component:

import Editor from 'draft-js-plugins-editor'
// Within another React component
<Editor plugins={[autoListPlugin]}/>

Caveats

To ensure that we aren’t constantly querying the content of the editor, the plugin keeps track of the characters that are typed in order and only attempts to create a list if the full sequence matches the examples above. If make a mistake while typing a list it won’t create one. For example, the following sequence would fail (typed characters delineated by []:

[*][m][backspace][space]

Even though it would seem like a list should be created here (because the final visible sequence is * ), we don’t attempt to.

TODO

  • Allow the various list regexes to be overridden.
  • Add test coverage for, you know, the actual functionality within a Draft.js instance.

draft-js-autolist-plugin's People

Contributors

makenosound avatar tomconroy avatar

Watchers

 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.