├── .gitignore
├── dist
├── quill-paste-smart.js.LICENSE.txt
└── quill-paste-smart.js
├── webpack.config.js
├── LICENSE
├── package.json
├── README.md
└── src
└── module.js
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .idea/
3 | .vscode/
4 | .vs
5 |
6 | node_modules
7 | *.log
8 | package-lock.json
9 | yarn.lock
10 | logs/
11 |
--------------------------------------------------------------------------------
/dist/quill-paste-smart.js.LICENSE.txt:
--------------------------------------------------------------------------------
1 | /*! @license DOMPurify 3.1.6 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.1.6/LICENSE */
2 |
--------------------------------------------------------------------------------
/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 |
3 | const config = {
4 | entry: './src/module.js',
5 | output: {
6 | filename: 'quill-paste-smart.js',
7 | path: path.resolve(__dirname, 'dist'),
8 | library: 'QuillPasteSmart',
9 | libraryTarget: 'umd',
10 | },
11 | optimization: {
12 | minimize: true,
13 | },
14 | target: 'web',
15 | mode: 'production',
16 | externals: {
17 | quill: {
18 | commonjs: 'quill',
19 | commonjs2: 'quill',
20 | amd: 'quill',
21 | root: 'Quill',
22 | },
23 | },
24 | module: {
25 | rules: [
26 | {
27 | test: /\.js$/,
28 | include: [path.resolve(__dirname, 'src/')],
29 | exclude: /(node_modules)/,
30 | use: {
31 | loader: 'babel-loader',
32 | options: {
33 | presets: [['@babel/preset-env', { modules: false }]],
34 | },
35 | },
36 | },
37 | ],
38 | },
39 | };
40 |
41 | module.exports = config;
42 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Artem Schander
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "quill-paste-smart",
3 | "version": "2.0.0",
4 | "description": "Quill Extension to paste only supported HTML",
5 | "main": "dist/quill-paste-smart.js",
6 | "devDependencies": {
7 | "@babel/core": "^7.24.7",
8 | "@babel/plugin-proposal-class-properties": "^7.18.6",
9 | "@babel/preset-env": "^7.24.7",
10 | "babel-loader": "^9.1.3",
11 | "webpack": "^5.92.1",
12 | "webpack-cli": "^5.1.4"
13 | },
14 | "scripts": {
15 | "build": "webpack"
16 | },
17 | "repository": {
18 | "type": "git",
19 | "url": "git+https://github.com/Artem-Schander/quill-paste-smart.git"
20 | },
21 | "keywords": [
22 | "quill",
23 | "editor",
24 | "content",
25 | "clipboard",
26 | "paste",
27 | "tidy"
28 | ],
29 | "author": "Artem Schander",
30 | "license": "MIT",
31 | "bugs": {
32 | "url": "https://github.com/Artem-Schander/quill-paste-smart/issues"
33 | },
34 | "homepage": "https://github.com/Artem-Schander/quill-paste-smart",
35 | "dependencies": {
36 | "dompurify": "^3.1.6"
37 | },
38 | "peerDependencies": {
39 | "quill": "^2.0.2"
40 | },
41 | "eslintConfig": {
42 | "extends": "eslint:recommended",
43 | "parserOptions": {
44 | "ecmaVersion": 6,
45 | "sourceType": "module",
46 | "ecmaFeatures": {
47 | "impliedStrict": true
48 | }
49 | },
50 | "rules": {
51 | "eqeqeq": [
52 | 2,
53 | "allow-null"
54 | ],
55 | "no-unused-vars": [
56 | 1,
57 | {
58 | "vars": "local",
59 | "args": "none"
60 | }
61 | ],
62 | "no-console": 0
63 | },
64 | "env": {
65 | "browser": true,
66 | "node": true
67 | }
68 | },
69 | "files": [
70 | "dist/"
71 | ]
72 | }
73 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Quill Paste Smart
2 |
3 | [](https://www.npmjs.com/package/quill-paste-smart?activeTab=versions)
4 | [](https://bundlephobia.com/package/quill-paste-smart)
5 | [](https://www.npmjs.com/package/quill-paste-smart)
6 | [](https://github.com/Artem-Schander/quill-paste-smart/blob/master/LICENSE)
7 |
8 | This plugin extends the default clipboard module of [Quill.js](https://github.com/quilljs/quill) 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.
9 | However, you can also decide on your own, what is allowed.
10 |
11 |
12 |
13 | ### Installation
14 |
15 | You can install this plugin either with [npm](https://www.npmjs.com/) or with [yarn](https://yarnpkg.com/).
16 | Run one of the following commands from your projects root in a bash prompt.
17 |
18 | ```bash
19 | npm i quill-paste-smart
20 | # or: yarn add quill-paste-smart
21 | ```
22 |
23 | If you are using Quill v1, you must also install the [v1](https://github.com/Artem-Schander/quill-paste-smart/tree/legacy) of this package
24 |
25 | ```bash
26 | npm i quill-paste-smart@^1
27 | # or: yarn add quill-paste-smart@^1
28 | ```
29 |
30 |
31 |
32 | ### Usage
33 |
34 | Since this plugin registers itself, it is sufficient to just import it.
35 |
36 | ```javascript
37 | import Quill from 'quill';
38 | import 'quill-paste-smart';
39 | ```
40 |
41 |
42 |
43 | ### Demos
44 |
45 | * Vanilla JS
46 | * [ES6](https://il56g.csb.app/)
47 | * [CommonJS](https://8rw3l.csb.app/)
48 | * Vue
49 | * [surmon-china/vue-quill-editor](https://bk79f.csb.app/)
50 | * React
51 | * [zenoamaro/react-quill](https://3di00.csb.app/)
52 | * [gtgalone/react-quilljs](https://h3tut.csb.app/)
53 |
54 |
55 |
56 | ### Configuration
57 |
58 | Out of the box this plugin will remove all HTML tags and attributes that are not available in the toolbar formats.
59 | If you don't agree with the default settings, you can decide what is allowed by yourself.
60 | Also I thought it could be useful to keep the pasted content selected after pasting, so there is a setting for it too.
61 |
62 | A valid configuration could look like this:
63 |
64 | ```javascript
65 | const options = {
66 | theme: 'snow',
67 | modules: {
68 | clipboard: {
69 | allowed: {
70 | tags: ['a', 'b', 'strong', 'u', 's', 'i', 'p', 'br', 'ul', 'ol', 'li', 'span'],
71 | attributes: ['href', 'rel', 'target', 'class']
72 | },
73 | customButtons: [
74 | {
75 | module: 'quillEmbeds',
76 | allowedTags: ['embed'],
77 | allowedAttr: ['width', 'height'],
78 | }
79 | ],
80 | keepSelection: true,
81 | substituteBlockElements: true,
82 | magicPasteLinks: true,
83 | hooks: {
84 | uponSanitizeElement(node, data, config) {
85 | console.log(node);
86 | },
87 | },
88 |
89 | handleImagePaste(image) {
90 | console.log("Image file pasted", image);
91 | },
92 | removeConsecutiveSubstitutionTags: true
93 | },
94 | },
95 | };
96 | new Quill('#editor', options);
97 | ```
98 |
99 | > :raised_hand: **Probably you don't need a custom configuration.**
100 | > You could stick with the default settings by completely omit the `clipboard` object in your quill options.
101 |
102 |
103 | #### Configuration Object
104 |
105 | | key | valid values | default value | type | description |
106 | | :---------------------- | :----------------------------------------------------------: | :-----------: | :---------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
107 | | allowed.tags | HTML tags | `undefined` | `Array` | 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 |
108 | | allowed.attributes | HTML attributes | `undefined` | `Array` | 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 |
109 | | customButtons | Array of button description objects | `undefined` | `Array