Git Product home page Git Product logo

quill-autoformat's Introduction

Quill Autoformat

Module for transforming and formatting text as you type or paste in Quill. Using RegExp to find and trigger transformations for text such as links, mentions, hashtags or emojis. Out of the box support for:

  • Links
  • Hashtags
  • Mentions

Note: Requires Quill 2.0

Usage

To add quill-autoformat to your Quill, simply add the javascript after quill or import it in your project. Use the provided quill-formats or define your own parchments.

<body>
  ...
  <form action="#" method="get">
    <div id="editor-container"></div>
  </form>
  ...
  <script src="/path/to/quill.min.js"></script>
  <script src="/path/to/quill-autoformat.js"></script>
  <script>
    var editor = new Quill('#editor-container', {
      modules: {
        autoformat: true
      }
    });
  </script>
  ...
</body>

Transforms

You can specify as many transforms as you like, just give each transform a unique name. Three transforms are enabled by default; hashtag, mention and link. Just set the default types to false to disable them or change any property you like to a custom value.

Each transform may have the following properties:

transform: {
   trigger:     RegExp, // RegExp for matching text input characters to trigger the match. Defaults to /./ which is matching any character
   find:        RegExp, // Global RegExp to search for in the text
   extract:     RegExp, // Additional RegExp to finetune and override the found text match
   transform:   String || Function, // String or function passed to String.replace() to rewrite find/extract results
   insert:      String || {...}, // Insert name string or embed insert object.
   format:      String || {...} // Format name string or attributes object.
 }

Reference

Default Options

Specify one option or more to override defaults.

var editor = new Quill('#editor-container', {
  modules: {
    autoformat: {
      hashtag: {
        trigger: /[\s.,;:!?]/,
        find: /(?:^|\s)#[^\s.,;:!?]+/i,
        extract: /#([^\s.,;:!?]+)/i,
        transform: '$1',
        insert: 'hashtag'
      },
      mention: {
        trigger: /[\s.,;:!?]/,
        find: /(?:^|\s)@[^\s.,;:!?]+/i,
        extract: /@([^\s.,;:!?]+)/i,
        transform: '$1',
        insert: 'mention'
      },
      link: {
        trigger: /[\s]/,
        find: /https?:\/\/[\S]+|(www\.[\S]+)/gi,
        transform: function (value, noProtocol) { // value == match[0], noProtocol == match[1]
          return noProtocol ? "http://" + value : value;
        },
        format: 'link'
      }
    }
  }
});

quill-autoformat's People

Contributors

klasjersevi 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.