npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sakrat91/quill-paste-smart

v1.4.9

Published

Quill Extension to paste only supported HTML

Downloads

2

Readme

Quill Paste Smart

npm npm bundle size npm NPM

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

Since this plugin registers itself, it is sufficient to just import it.

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

Demos

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,
            substituteBlockElements: true,
            magicPasteLinks: true,
            hooks: {
                uponSanitizeElement(node, data, config) {
                    console.log(node);
                },
            },
        },
    },
};
new Quill('#editor', options);

:raised_hand: Probably you don't need a custom configuration.
You could stick with the default settings by completely omit the clipboard object in your quill options.

Configuration Object

| key | valid values | default value | type | description | |:------| :------: | :------: | :------: |:------| | allowed.tags | HTML tags | undefined | Array<string> | Here you can define any HTML tag that should be allowed to be pasted. If this setting is not specified, allowed tags are determined by possible formats in the toolbar | | allowed.attributes | HTML attributes | undefined | Array<string> | Here you can define any HTML attributes that should be allowed to be pasted. If this setting is not specified, allowed attributes are determined by possible formats in the toolbar | | substituteBlockElements | true false | true | Boolean | If this setting is set to true all forbidden block type tags will be substituted by one of the allowed tags p/div/section | | keepSelection | true false | false | Boolean | If this setting is set to true the pasted content will be selected after pasting it. Otherwise the cursor will be placed right after the pasted content | | magicPasteLinks | true false | false | Boolean | If this setting is set to true pasted URLs over selected text will be converted to an a tag. Example: If you select the word foo and paste the URL https://foo.bar/ the result will be <a href="https://foo.bar/">foo</a>. Note: This only works if there is nothing pasted except a valid URL. | | hooks | DOMPurify Hooks | undefined | Array<function> | Here you can define any of the DOMPurify hooks. This can be handy if you need to cusomtize the HTML sanitizer. For more information see the hook demos from DOMPurify.BE AWAREHere you can mess up things. E.g. You could create an infinite loop by adding not allowed tags to the node. |

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://unpkg.com/quill@latest/dist/quill.js"></script>
    <script src="https://unpkg.com/quill-paste-smart@latest/dist/quill-paste-smart.js"></script>

    <script>
        var quill = new Quill('#editor', {
            theme: 'snow',
            modules: {
                toolbar: ['bold', 'italic', 'underline', 'link'],
            }
        });
    </script>
</body>
</html>

License

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