Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

quill-paste-smart

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quill-paste-smart

Quill Extension to paste only supported HTML

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.9K
decreased by-79.37%
Maintainers
1
Weekly downloads
 
Created
Source

Quill Paste Smart

This plugin extends the default clipboard module of Quill.js to prevent users from pasting HTML that does not belong into the editor. To do so it looks into the toolbar configuration and decides which tags and attributes are allowed based on the possible formats.
However, you can also decide on your own, what is allowed.


Installation

You can install this plugin either with npm or with yarn.
Run one of the following commands from your projects root in a bash prompt.

npm i quill-paste-smart
# or: yarn add quill-paste-smart

Usage

To tell Quill to use this plugin instead of its own clipboard module you need to register it.

import Quill from 'quill';
import QuillPasteSmart from 'quill-paste-smart';

Quill.register('modules/clipboard', QuillPasteSmart, true);


Configuration

Out of the box this plugin will remove all HTML tags and attributes that are not available in the toolbar formats.
If you don't agree with the default settings, you can decide what is allowed by yourself.
Also I thought it could be useful to keep the pasted content selected after pasting, so there is a setting for it too.

A valid configuration could look like this:

const options = {
    theme: 'snow'
    modules: {
        clipboard: {
            allowed: {
                tags: ['a', 'b', 'strong', 'u', 's', 'i', 'p', 'br', 'ul', 'ol', 'li', 'span'],
                attributes: ['href', 'rel', 'target', 'class']
            },
            keepSelection: true,
        },
    },
};
new Quill('#editor', options);

CommonJS

It is possible to use this module by including it though a <script> tag. Here is a full example.


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Quill Paste Smart</title>
    <link href="https://unpkg.com/quill@latest/dist/quill.snow.css" rel="stylesheet">
</head>
<body>
    <div id="editor"></div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/quill/2.0.0-dev.4/quill.min.js"></script>
    <script src="https://unpkg.com/quill-paste-smart@latest/dist/index.js"></script>

    <script>
        Quill.register('modules/clipboard', QuillPasteSmart);
        var quill = new Quill('#editor', {
            theme: 'snow',
        });
    </script>
</body>
</html>

License

This plugin is licensed under the terms of the MIT License (See LICENSE file for details).

Keywords

FAQs

Package last updated on 15 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc