├── .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 | [![npm](https://img.shields.io/npm/v/quill-paste-smart?style=for-the-badge)](https://www.npmjs.com/package/quill-paste-smart?activeTab=versions) 4 | [![npm bundle size](https://img.shields.io/bundlephobia/minzip/quill-paste-smart?color=%237400da&style=for-the-badge)](https://bundlephobia.com/package/quill-paste-smart) 5 | [![npm](https://img.shields.io/npm/dm/quill-paste-smart?style=for-the-badge)](https://www.npmjs.com/package/quill-paste-smart) 6 | [![NPM](https://img.shields.io/npm/l/quill-paste-smart?style=for-the-badge)](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` | Here you can add custom toolbar buttons with the associated tags and attributes that are allowed in relation to those buttons. | 110 | | customButtons.module | String | `undefined` | `string` | The module name used in the toolbar button definition | 111 | | customButtons.allowedTags | HTML tags | `undefined` | `Array` | The tags allowed when this custom button is present. | 112 | | customButtons.allowedAttr | HTML attributes | `undefined` | `Array` | The attributes allowed when this custom button is present. | 113 | | 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` | 114 | | 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 | 115 | | 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 `foo`. Note: This only works if there is nothing pasted except a valid URL. | 116 | | hooks | [DOMPurify Hooks](https://github.com/cure53/DOMPurify#hooks) | `undefined` | `Array` | 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](https://github.com/cure53/DOMPurify/tree/main/demos) from DOMPurify.
**BE AWARE**
Here you can mess up things. E.g. You could create an infinite loop by adding not allowed tags to the node. | 117 | | handleImagePaste | `function (File)` | `undefined` | `function (File)` | Here you can define custom behavior for handling images being pasted, you can use this to upload the image to a CDN rather than embedding | | 118 | | removeConsecutiveSubstitutionTags | `true` `false` | `undefined` | `Boolean` | If this setting is set to `true` the pasted content will have consecutive occurances of the chosen substitution element removed after pasting it. Otherwise the the pasted conntent will not be affected. Note this setting is in effect only when substituteBlockElements is not false. | 119 |
120 | 121 | ### CommonJS 122 | 123 | It is possible to use this module by including it though a ` 138 | 139 | 140 | 148 | 149 | 150 | ``` 151 | 152 | 153 |
154 | 155 | ### License 156 | This plugin is licensed under the terms of the [MIT License](https://github.com/Artem-Schander/quill-paste-smart/blob/master/LICENSE) 157 | (See LICENSE file for details). 158 | -------------------------------------------------------------------------------- /src/module.js: -------------------------------------------------------------------------------- 1 | import Quill from 'quill'; 2 | import DOMPurify from 'dompurify'; 3 | 4 | const Clipboard = Quill.import('modules/clipboard'); 5 | const Delta = Quill.import('delta'); 6 | 7 | class QuillPasteSmart extends Clipboard { 8 | constructor(quill, options) { 9 | super(quill, options); 10 | 11 | this.allowed = options.allowed; 12 | this.keepSelection = options.keepSelection; 13 | this.substituteBlockElements = options.substituteBlockElements; 14 | this.magicPasteLinks = options.magicPasteLinks; 15 | this.hooks = options.hooks; 16 | this.handleImagePaste = options.handleImagePaste; 17 | this.customButtons = options.customButtons; 18 | this.removeConsecutiveSubstitutionTags = options.removeConsecutiveSubstitutionTags; 19 | } 20 | 21 | onCapturePaste(e) { 22 | if (e.defaultPrevented || !this.quill.isEnabled()) return; 23 | 24 | e.preventDefault(); 25 | 26 | const range = this.quill.getSelection(); 27 | if (range == null) return; 28 | 29 | let text = e.clipboardData?.getData('text/plain'); 30 | let html = e.clipboardData?.getData('text/html'); 31 | let file = e.clipboardData?.items?.[0]; 32 | let delta = new Delta().retain(range.index).delete(range.length); 33 | 34 | const DOMPurifyOptions = this.getDOMPurifyOptions(); 35 | 36 | let plainText = false; 37 | let content = text; 38 | 39 | if ( 40 | !html && 41 | DOMPurifyOptions.ALLOWED_TAGS.includes('a') && 42 | this.isURL(text) && range.length > 0 && this.magicPasteLinks 43 | ) { 44 | content = this.quill.getText(range.index, range.length); 45 | delta = delta.insert(content, { 46 | link: text, 47 | }); 48 | } else if ( 49 | !html && 50 | DOMPurifyOptions.ALLOWED_TAGS.includes('img') && 51 | file && file.kind === 'file' && file.type.match(/^image\//i) 52 | ) { 53 | const image = file.getAsFile() 54 | 55 | if (this.handleImagePaste !== undefined) { 56 | this.handleImagePaste(image); 57 | } else { 58 | const reader = new FileReader() 59 | reader.onload = (e) => { 60 | this.quill.insertEmbed(range.index, 'image', e.target.result) 61 | // if required, manually update the selection after the file loads 62 | if (!this.keepSelection) this.quill.setSelection(range.index + 1) 63 | } 64 | reader.readAsDataURL(image) 65 | } 66 | } else { 67 | 68 | if (!html) { 69 | plainText = true; 70 | html = content; 71 | } 72 | 73 | // add hooks to accessible setttings 74 | if (typeof this.hooks?.beforeSanitizeElements === 'function') { 75 | DOMPurify.addHook('beforeSanitizeElements', this.hooks.beforeSanitizeElements); 76 | } 77 | if (typeof this.hooks?.uponSanitizeElement === 'function') { 78 | DOMPurify.addHook('uponSanitizeElement', this.hooks.uponSanitizeElement); 79 | } 80 | if (typeof this.hooks?.afterSanitizeElements === 'function') { 81 | DOMPurify.addHook('afterSanitizeElements', this.hooks.afterSanitizeElements); 82 | } 83 | if (typeof this.hooks?.beforeSanitizeAttributes === 'function') { 84 | DOMPurify.addHook('beforeSanitizeAttributes', this.hooks.beforeSanitizeAttributes); 85 | } 86 | if (typeof this.hooks?.uponSanitizeAttribute === 'function') { 87 | DOMPurify.addHook('uponSanitizeAttribute', this.hooks.uponSanitizeAttribute); 88 | } 89 | if (typeof this.hooks?.afterSanitizeAttributes === 'function') { 90 | DOMPurify.addHook('afterSanitizeAttributes', this.hooks.afterSanitizeAttributes); 91 | } 92 | if (typeof this.hooks?.beforeSanitizeShadowDOM === 'function') { 93 | DOMPurify.addHook('beforeSanitizeShadowDOM', this.hooks.beforeSanitizeShadowDOM); 94 | } 95 | if (typeof this.hooks?.uponSanitizeShadowNode === 'function') { 96 | DOMPurify.addHook('uponSanitizeShadowNode', this.hooks.uponSanitizeShadowNode); 97 | } 98 | if (typeof this.hooks?.afterSanitizeShadowDOM === 'function') { 99 | DOMPurify.addHook('afterSanitizeShadowDOM', this.hooks.afterSanitizeShadowDOM); 100 | } 101 | 102 | if (plainText) { 103 | content = DOMPurify.sanitize(html, DOMPurifyOptions); 104 | delta = delta.insert(content); 105 | } else { 106 | if (DOMPurifyOptions.ALLOWED_TAGS.includes('table')) { 107 | // Convert table headers to cells 108 | html = this.tableHeadersToCells(html); 109 | } else { 110 | // Convert rows and cells to block and inline content 111 | html = this.convertTableContent(html); 112 | } 113 | 114 | if (this.substituteBlockElements !== false) { 115 | let substitution; 116 | // html = DOMPurify.sanitize(html, { ...DOMPurifyOptions, ...{ RETURN_DOM: true, WHOLE_DOCUMENT: false } }); 117 | [html, substitution] = this.substitute(html, DOMPurifyOptions); 118 | content = html.innerHTML; 119 | if (this.removeConsecutiveSubstitutionTags) { 120 | content = this.collapseConsecutiveSubstitutionTags(content, substitution); 121 | } 122 | } else { 123 | content = DOMPurify.sanitize(html, DOMPurifyOptions); 124 | } 125 | delta = delta.concat(this.convert({ html: content })); 126 | } 127 | } 128 | 129 | this.quill.updateContents(delta, Quill.sources.USER); 130 | 131 | if (!plainText) { 132 | // move cursor 133 | delta = this.convert({ html: content }); 134 | } 135 | 136 | if (this.keepSelection) this.quill.setSelection(range.index, delta.length(), Quill.sources.SILENT); 137 | else this.quill.setSelection(range.index + delta.length(), Quill.sources.SILENT); 138 | this.quill.scrollSelectionIntoView(); 139 | DOMPurify.removeAllHooks(); 140 | } 141 | 142 | collapseConsecutiveSubstitutionTags(html, substitution) { 143 | // Remove all consecutive occurances of substitution (e.g.

) from html, include tags with only whitespace 144 | const parser = new DOMParser() 145 | const doc = parser.parseFromString(html, 'text/html'); 146 | const tags = doc.querySelectorAll(substitution); 147 | let removeNextTag = false; 148 | tags.forEach(tag => { 149 | if (!removeNextTag) { 150 | removeNextTag = true; 151 | return; 152 | } 153 | 154 | if (tag.firstChild === null || (tag.firstChild.nodeType === 3 && tag.firstChild.nodeValue.trim() === '')) { 155 | tag.parentNode.removeChild(tag); 156 | } else { 157 | removeNextTag = false; 158 | } 159 | }); 160 | return doc.body.innerHTML; 161 | } 162 | 163 | tableHeadersToCells(html) { 164 | // Quill table doesn't support header cells 165 | // Move first from to , convert all to 166 | const parser = new DOMParser() 167 | const doc = parser.parseFromString(html, 'text/html'); 168 | const tables = doc.querySelectorAll('table'); 169 | tables.forEach(table => { 170 | // Check if the table has a element 171 | const thead = table.querySelector('thead'); 172 | if (thead) { 173 | // Move the 's first child to be the first child of 174 | const tbody = table.querySelector('tbody'); 175 | if (tbody) { 176 | const firstRow = thead.querySelector('tr'); 177 | tbody.insertBefore(firstRow, tbody.firstChild); 178 | } 179 | } 180 | // Convert all elements to elements 181 | const thElements = table.querySelectorAll('th'); 182 | thElements.forEach(th => { 183 | const td = document.createElement('td'); 184 | td.innerHTML = th.innerHTML; 185 | th.parentNode.replaceChild(td, th); 186 | }); 187 | }); 188 | return `${doc.body.outerHTML}`; 189 | } 190 | 191 | convertTableContent(html) { 192 | const parser = new DOMParser() 193 | const doc = parser.parseFromString(html, 'text/html'); 194 | 195 | // Convert elements to

elements, concatenate td & th cell contents with inner space added 196 | doc.querySelectorAll('tr').forEach(tr => { 197 | tr.outerHTML = `

${Array.from(tr.querySelectorAll('td, th')).map(cell => cell.innerHTML).join(' ')}

` 198 | }); 199 | 200 | // Convert orphan td & th elements to their innerHTML plus trailing space 201 | doc.querySelectorAll('td, th').forEach(cell => { 202 | cell.outerHTML = `${cell.innerHTML} `; 203 | }); 204 | 205 | // Collapse thead, tbody, and tfoot elements to their innerHTML 206 | doc.querySelectorAll('thead, tbody, tfoot').forEach(rowContainers => { 207 | rowContainers.outerHTML = rowContainers.innerHTML; 208 | }); 209 | 210 | // Collapse table elements to their innerHTML 211 | doc.querySelectorAll('table').forEach(tableEle => { 212 | tableEle.outerHTML = tableEle.innerHTML; 213 | }); 214 | 215 | return `${doc.body.outerHTML}`; 216 | } 217 | 218 | getDOMPurifyOptions() { 219 | let tidy = {}; 220 | 221 | if (this.allowed?.tags) tidy.ALLOWED_TAGS = this.allowed.tags; 222 | if (this.allowed?.attributes) tidy.ALLOWED_ATTR = this.allowed.attributes; 223 | 224 | if (tidy.ALLOWED_TAGS === undefined || tidy.ALLOWED_ATTR === undefined) { 225 | let undefinedTags = false; 226 | if (tidy.ALLOWED_TAGS === undefined) { 227 | undefinedTags = true; 228 | tidy.ALLOWED_TAGS = ['p', 'br', 'span']; 229 | } 230 | 231 | let undefinedAttr = false; 232 | if (tidy.ALLOWED_ATTR === undefined) { 233 | undefinedAttr = true; 234 | tidy.ALLOWED_ATTR = ['class']; 235 | } 236 | 237 | const toolbar = this.quill.getModule('toolbar'); 238 | toolbar?.controls?.forEach((control) => { 239 | switch (control[0]) { 240 | case 'bold': 241 | if (undefinedTags) { 242 | tidy.ALLOWED_TAGS.push('b'); 243 | tidy.ALLOWED_TAGS.push('strong'); 244 | } 245 | break; 246 | 247 | case 'italic': 248 | if (undefinedTags) { 249 | tidy.ALLOWED_TAGS.push('i'); 250 | tidy.ALLOWED_TAGS.push('em'); 251 | } 252 | break; 253 | 254 | case 'underline': 255 | if (undefinedTags) { 256 | tidy.ALLOWED_TAGS.push('u'); 257 | } 258 | break; 259 | 260 | case 'strike': 261 | if (undefinedTags) { 262 | tidy.ALLOWED_TAGS.push('s'); 263 | } 264 | break; 265 | 266 | case 'color': 267 | case 'background': 268 | if (undefinedAttr) { 269 | tidy.ALLOWED_ATTR.push('style'); 270 | } 271 | break; 272 | 273 | case 'script': 274 | if (undefinedTags) { 275 | if (control[1].value === 'super') { 276 | tidy.ALLOWED_TAGS.push('sup'); 277 | } else if (control[1].value === 'sub') { 278 | tidy.ALLOWED_TAGS.push('sub'); 279 | } 280 | } 281 | break; 282 | 283 | case 'header': 284 | if (undefinedTags) { 285 | const detectAllowedHeadingTag = (value) => { 286 | if (value === '1') { 287 | tidy.ALLOWED_TAGS.push('h1'); 288 | } else if (value === '2') { 289 | tidy.ALLOWED_TAGS.push('h2'); 290 | } else if (value === '3') { 291 | tidy.ALLOWED_TAGS.push('h3'); 292 | } else if (value === '4') { 293 | tidy.ALLOWED_TAGS.push('h4'); 294 | } else if (value === '5') { 295 | tidy.ALLOWED_TAGS.push('h5'); 296 | } else if (value === '6') { 297 | tidy.ALLOWED_TAGS.push('h6'); 298 | } 299 | }; 300 | 301 | if (control[1].value) detectAllowedHeadingTag(control[1].value); 302 | else if (control[1].options && control[1].options.length) { 303 | [].forEach.call(control[1].options, (option) => { 304 | if (option.value) detectAllowedHeadingTag(option.value); 305 | }); 306 | } 307 | } 308 | break; 309 | 310 | case 'code-block': 311 | if (undefinedTags) { 312 | tidy.ALLOWED_TAGS.push('pre'); 313 | } 314 | if (undefinedAttr) { 315 | tidy.ALLOWED_ATTR.push('spellcheck'); 316 | } 317 | break; 318 | 319 | case 'list': 320 | if (undefinedTags) { 321 | if (control[1].value === 'ordered') { 322 | tidy.ALLOWED_TAGS.push('ol'); 323 | } else if (control[1].value === 'bullet') { 324 | tidy.ALLOWED_TAGS.push('ul'); 325 | } 326 | tidy.ALLOWED_TAGS.push('li'); 327 | } 328 | break; 329 | 330 | case 'link': 331 | if (undefinedTags) { 332 | tidy.ALLOWED_TAGS.push('a'); 333 | } 334 | if (undefinedAttr) { 335 | tidy.ALLOWED_ATTR.push('href'); 336 | tidy.ALLOWED_ATTR.push('target'); 337 | tidy.ALLOWED_ATTR.push('rel'); 338 | } 339 | break; 340 | 341 | case 'image': 342 | if (undefinedTags) { 343 | tidy.ALLOWED_TAGS.push('img'); 344 | } 345 | if (undefinedAttr) { 346 | tidy.ALLOWED_ATTR.push('src'); 347 | tidy.ALLOWED_ATTR.push('title'); 348 | tidy.ALLOWED_ATTR.push('alt'); 349 | tidy.ALLOWED_ATTR.push('height'); 350 | tidy.ALLOWED_ATTR.push('width'); 351 | } 352 | break; 353 | 354 | case 'video': 355 | if (undefinedTags) { 356 | tidy.ALLOWED_TAGS.push('iframe'); 357 | } 358 | if (undefinedAttr) { 359 | tidy.ALLOWED_ATTR.push('frameborder'); 360 | tidy.ALLOWED_ATTR.push('allowfullscreen'); 361 | tidy.ALLOWED_ATTR.push('src'); 362 | tidy.ALLOWED_ATTR.push('height'); 363 | tidy.ALLOWED_ATTR.push('width'); 364 | } 365 | break; 366 | 367 | case 'blockquote': 368 | if (undefinedTags) { 369 | tidy.ALLOWED_TAGS.push(control[0]); 370 | } 371 | break; 372 | 373 | case 'table': 374 | if (undefinedTags) { 375 | tidy.ALLOWED_TAGS.push('table'); 376 | tidy.ALLOWED_TAGS.push('tr'); 377 | tidy.ALLOWED_TAGS.push('td'); 378 | } 379 | break; 380 | } 381 | }); 382 | 383 | // support custom toolbar buttons from options 384 | if (toolbar?.controls) { 385 | this.customButtons?.forEach((button) => { 386 | if (toolbar.controls.some(control => control[0] === button.module)) { 387 | button.allowedTags?.forEach((tag) => { 388 | tidy.ALLOWED_TAGS.push(tag); 389 | }); 390 | button.allowedAttr?.forEach((attr) => { 391 | tidy.ALLOWED_ATTR.push(attr); 392 | }); 393 | } 394 | }); 395 | } 396 | } 397 | 398 | return tidy; 399 | } 400 | 401 | // replace forbidden block elements with a p tag 402 | substitute(html, DOMPurifyOptions) { 403 | let substitution; 404 | 405 | const headings = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']; 406 | const blockElements = [ 407 | 'p', 408 | 'div', 409 | 'section', 410 | 'article', 411 | 'fieldset', 412 | 'address', 413 | 'aside', 414 | 'blockquote', 415 | 'canvas', 416 | 'dl', 417 | 'figcaption', 418 | 'figure', 419 | 'footer', 420 | 'form', 421 | 'header', 422 | 'main', 423 | 'nav', 424 | 'noscript', 425 | 'ol', 426 | 'pre', 427 | 'ul', 428 | 'video', 429 | ]; 430 | const newLineElements = ['li', 'dt', 'dd', 'hr']; 431 | 432 | DOMPurify.addHook('uponSanitizeElement', (node, data, config) => { 433 | // check if current tag is a heading 434 | // - is it supported? 435 | // - no? - replace it with

and 436 | // ----------------- 437 | // check if current tag is a block element 438 | // - is it supported? 439 | // - no? - replace it with

440 | // ----------------- 441 | // check if current tag is a new line element 442 | // - is it supported? 443 | // - no? - remove the tag and append a
444 | 445 | // find possible substitution 446 | let i = 0; 447 | while (!substitution && i < 3) { 448 | if (DOMPurifyOptions.ALLOWED_TAGS.includes(blockElements[i])) substitution = blockElements[i]; 449 | ++i; 450 | } 451 | 452 | if (substitution && node.tagName && !DOMPurifyOptions.ALLOWED_TAGS.includes(node.tagName.toLowerCase())) { 453 | const tagName = node.tagName.toLowerCase(); 454 | if (headings.includes(tagName)) { 455 | node.innerHTML = `<${substitution}>${node.innerHTML}`; 456 | } else if (blockElements.includes(tagName)) { 457 | node.innerHTML = `<${substitution}>${node.innerHTML}`; 458 | } else if (newLineElements.includes(tagName)) { 459 | node.innerHTML = `${node.innerHTML}
`; 460 | } 461 | } 462 | }); 463 | 464 | html = DOMPurify.sanitize(html, { ...DOMPurifyOptions, ...{ RETURN_DOM: true, WHOLE_DOCUMENT: false } }); 465 | DOMPurify.removeAllHooks(); 466 | 467 | return [html, substitution]; 468 | } 469 | 470 | isURL(str) { 471 | const pattern = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/isu; 472 | return !!pattern.test(str); 473 | } 474 | } 475 | 476 | Quill.register('modules/clipboard', QuillPasteSmart, true); 477 | export default QuillPasteSmart; 478 | -------------------------------------------------------------------------------- /dist/quill-paste-smart.js: -------------------------------------------------------------------------------- 1 | /*! For license information please see quill-paste-smart.js.LICENSE.txt */ 2 | !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.QuillPasteSmart=t(require("quill")):e.QuillPasteSmart=t(e.Quill)}(self,(e=>(()=>{var t={838:function(e){e.exports=function(){"use strict";const{entries:e,setPrototypeOf:t,isFrozen:n,getPrototypeOf:o,getOwnPropertyDescriptor:r}=Object;let{freeze:i,seal:a,create:l}=Object,{apply:u,construct:s}="undefined"!=typeof Reflect&&Reflect;i||(i=function(e){return e}),a||(a=function(e){return e}),u||(u=function(e,t,n){return e.apply(t,n)}),s||(s=function(e,t){return new e(...t)});const c=S(Array.prototype.forEach),f=S(Array.prototype.pop),p=S(Array.prototype.push),d=S(String.prototype.toLowerCase),m=S(String.prototype.toString),h=S(String.prototype.match),T=S(String.prototype.replace),A=S(String.prototype.indexOf),g=S(String.prototype.trim),y=S(Object.prototype.hasOwnProperty),b=S(RegExp.prototype.test),E=(D=TypeError,function(){for(var e=arguments.length,t=new Array(e),n=0;n1?n-1:0),r=1;r2&&void 0!==arguments[2]?arguments[2]:d;t&&t(e,null);let i=o.length;for(;i--;){let t=o[i];if("string"==typeof t){const e=r(t);e!==t&&(n(o)||(o[i]=e),t=e)}e[t]=!0}return e}function v(e){for(let t=0;t/gm),U=a(/\${[\w\W]*}/gm),G=a(/^data-[\-\w.\u00B7-\uFFFF]/),B=a(/^aria-[\-\w]+$/),j=a(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),q=a(/^(?:\w+script|data):/i),Y=a(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),K=a(/^html$/i),X=a(/^[a-z][.\w]*(-[.\w]+)+$/i);var $=Object.freeze({__proto__:null,MUSTACHE_EXPR:H,ERB_EXPR:z,TMPLIT_EXPR:U,DATA_ATTR:G,ARIA_ATTR:B,IS_ALLOWED_URI:j,IS_SCRIPT_OR_DATA:q,ATTR_WHITESPACE:Y,DOCTYPE_NAME:K,CUSTOM_ELEMENT:X});const V=1,Q=3,Z=7,J=8,ee=9,te=function(){return"undefined"==typeof window?null:window};return function t(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:te();const o=e=>t(e);if(o.version="3.1.6",o.removed=[],!n||!n.document||n.document.nodeType!==ee)return o.isSupported=!1,o;let{document:r}=n;const a=r,u=a.currentScript,{DocumentFragment:s,HTMLTemplateElement:D,Node:S,Element:v,NodeFilter:H,NamedNodeMap:z=n.NamedNodeMap||n.MozNamedAttrMap,HTMLFormElement:U,DOMParser:G,trustedTypes:B}=n,q=v.prototype,Y=F(q,"cloneNode"),X=F(q,"remove"),ne=F(q,"nextSibling"),oe=F(q,"childNodes"),re=F(q,"parentNode");if("function"==typeof D){const e=r.createElement("template");e.content&&e.content.ownerDocument&&(r=e.content.ownerDocument)}let ie,ae="";const{implementation:le,createNodeIterator:ue,createDocumentFragment:se,getElementsByTagName:ce}=r,{importNode:fe}=a;let pe={};o.isSupported="function"==typeof e&&"function"==typeof re&&le&&void 0!==le.createHTMLDocument;const{MUSTACHE_EXPR:de,ERB_EXPR:me,TMPLIT_EXPR:he,DATA_ATTR:Te,ARIA_ATTR:Ae,IS_SCRIPT_OR_DATA:ge,ATTR_WHITESPACE:ye,CUSTOM_ELEMENT:be}=$;let{IS_ALLOWED_URI:Ee}=$,De=null;const Se=L({},[...O,...k,...w,...R,...x]);let Le=null;const ve=L({},[...M,...I,...P,...W]);let _e=Object.seal(l(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),Fe=null,Oe=null,ke=!0,we=!0,Ne=!1,Re=!0,Ce=!1,xe=!0,Me=!1,Ie=!1,Pe=!1,We=!1,He=!1,ze=!1,Ue=!0,Ge=!1,Be=!0,je=!1,qe={},Ye=null;const Ke=L({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]);let Xe=null;const $e=L({},["audio","video","img","source","image","track"]);let Ve=null;const Qe=L({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Ze="http://www.w3.org/1998/Math/MathML",Je="http://www.w3.org/2000/svg",et="http://www.w3.org/1999/xhtml";let tt=et,nt=!1,ot=null;const rt=L({},[Ze,Je,et],m);let it=null;const at=["application/xhtml+xml","text/html"];let lt=null,ut=null;const st=r.createElement("form"),ct=function(e){return e instanceof RegExp||e instanceof Function},ft=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!ut||ut!==e){if(e&&"object"==typeof e||(e={}),e=_(e),it=-1===at.indexOf(e.PARSER_MEDIA_TYPE)?"text/html":e.PARSER_MEDIA_TYPE,lt="application/xhtml+xml"===it?m:d,De=y(e,"ALLOWED_TAGS")?L({},e.ALLOWED_TAGS,lt):Se,Le=y(e,"ALLOWED_ATTR")?L({},e.ALLOWED_ATTR,lt):ve,ot=y(e,"ALLOWED_NAMESPACES")?L({},e.ALLOWED_NAMESPACES,m):rt,Ve=y(e,"ADD_URI_SAFE_ATTR")?L(_(Qe),e.ADD_URI_SAFE_ATTR,lt):Qe,Xe=y(e,"ADD_DATA_URI_TAGS")?L(_($e),e.ADD_DATA_URI_TAGS,lt):$e,Ye=y(e,"FORBID_CONTENTS")?L({},e.FORBID_CONTENTS,lt):Ke,Fe=y(e,"FORBID_TAGS")?L({},e.FORBID_TAGS,lt):{},Oe=y(e,"FORBID_ATTR")?L({},e.FORBID_ATTR,lt):{},qe=!!y(e,"USE_PROFILES")&&e.USE_PROFILES,ke=!1!==e.ALLOW_ARIA_ATTR,we=!1!==e.ALLOW_DATA_ATTR,Ne=e.ALLOW_UNKNOWN_PROTOCOLS||!1,Re=!1!==e.ALLOW_SELF_CLOSE_IN_ATTR,Ce=e.SAFE_FOR_TEMPLATES||!1,xe=!1!==e.SAFE_FOR_XML,Me=e.WHOLE_DOCUMENT||!1,We=e.RETURN_DOM||!1,He=e.RETURN_DOM_FRAGMENT||!1,ze=e.RETURN_TRUSTED_TYPE||!1,Pe=e.FORCE_BODY||!1,Ue=!1!==e.SANITIZE_DOM,Ge=e.SANITIZE_NAMED_PROPS||!1,Be=!1!==e.KEEP_CONTENT,je=e.IN_PLACE||!1,Ee=e.ALLOWED_URI_REGEXP||j,tt=e.NAMESPACE||et,_e=e.CUSTOM_ELEMENT_HANDLING||{},e.CUSTOM_ELEMENT_HANDLING&&ct(e.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(_e.tagNameCheck=e.CUSTOM_ELEMENT_HANDLING.tagNameCheck),e.CUSTOM_ELEMENT_HANDLING&&ct(e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(_e.attributeNameCheck=e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),e.CUSTOM_ELEMENT_HANDLING&&"boolean"==typeof e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements&&(_e.allowCustomizedBuiltInElements=e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),Ce&&(we=!1),He&&(We=!0),qe&&(De=L({},x),Le=[],!0===qe.html&&(L(De,O),L(Le,M)),!0===qe.svg&&(L(De,k),L(Le,I),L(Le,W)),!0===qe.svgFilters&&(L(De,w),L(Le,I),L(Le,W)),!0===qe.mathMl&&(L(De,R),L(Le,P),L(Le,W))),e.ADD_TAGS&&(De===Se&&(De=_(De)),L(De,e.ADD_TAGS,lt)),e.ADD_ATTR&&(Le===ve&&(Le=_(Le)),L(Le,e.ADD_ATTR,lt)),e.ADD_URI_SAFE_ATTR&&L(Ve,e.ADD_URI_SAFE_ATTR,lt),e.FORBID_CONTENTS&&(Ye===Ke&&(Ye=_(Ye)),L(Ye,e.FORBID_CONTENTS,lt)),Be&&(De["#text"]=!0),Me&&L(De,["html","head","body"]),De.table&&(L(De,["tbody"]),delete Fe.tbody),e.TRUSTED_TYPES_POLICY){if("function"!=typeof e.TRUSTED_TYPES_POLICY.createHTML)throw E('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if("function"!=typeof e.TRUSTED_TYPES_POLICY.createScriptURL)throw E('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');ie=e.TRUSTED_TYPES_POLICY,ae=ie.createHTML("")}else void 0===ie&&(ie=function(e,t){if("object"!=typeof e||"function"!=typeof e.createPolicy)return null;let n=null;const o="data-tt-policy-suffix";t&&t.hasAttribute(o)&&(n=t.getAttribute(o));const r="dompurify"+(n?"#"+n:"");try{return e.createPolicy(r,{createHTML:e=>e,createScriptURL:e=>e})}catch(e){return console.warn("TrustedTypes policy "+r+" could not be created."),null}}(B,u)),null!==ie&&"string"==typeof ae&&(ae=ie.createHTML(""));i&&i(e),ut=e}},pt=L({},["mi","mo","mn","ms","mtext"]),dt=L({},["foreignobject","annotation-xml"]),mt=L({},["title","style","font","a","script"]),ht=L({},[...k,...w,...N]),Tt=L({},[...R,...C]),At=function(e){p(o.removed,{element:e});try{re(e).removeChild(e)}catch(t){X(e)}},gt=function(e,t){try{p(o.removed,{attribute:t.getAttributeNode(e),from:t})}catch(e){p(o.removed,{attribute:null,from:t})}if(t.removeAttribute(e),"is"===e&&!Le[e])if(We||He)try{At(t)}catch(e){}else try{t.setAttribute(e,"")}catch(e){}},yt=function(e){let t=null,n=null;if(Pe)e=""+e;else{const t=h(e,/^[\r\n\t ]+/);n=t&&t[0]}"application/xhtml+xml"===it&&tt===et&&(e=''+e+"");const o=ie?ie.createHTML(e):e;if(tt===et)try{t=(new G).parseFromString(o,it)}catch(e){}if(!t||!t.documentElement){t=le.createDocument(tt,"template",null);try{t.documentElement.innerHTML=nt?ae:o}catch(e){}}const i=t.body||t.documentElement;return e&&n&&i.insertBefore(r.createTextNode(n),i.childNodes[0]||null),tt===et?ce.call(t,Me?"html":"body")[0]:Me?t.documentElement:i},bt=function(e){return ue.call(e.ownerDocument||e,e,H.SHOW_ELEMENT|H.SHOW_COMMENT|H.SHOW_TEXT|H.SHOW_PROCESSING_INSTRUCTION|H.SHOW_CDATA_SECTION,null)},Et=function(e){return e instanceof U&&("string"!=typeof e.nodeName||"string"!=typeof e.textContent||"function"!=typeof e.removeChild||!(e.attributes instanceof z)||"function"!=typeof e.removeAttribute||"function"!=typeof e.setAttribute||"string"!=typeof e.namespaceURI||"function"!=typeof e.insertBefore||"function"!=typeof e.hasChildNodes)},Dt=function(e){return"function"==typeof S&&e instanceof S},St=function(e,t,n){pe[e]&&c(pe[e],(e=>{e.call(o,t,n,ut)}))},Lt=function(e){let t=null;if(St("beforeSanitizeElements",e,null),Et(e))return At(e),!0;const n=lt(e.nodeName);if(St("uponSanitizeElement",e,{tagName:n,allowedTags:De}),e.hasChildNodes()&&!Dt(e.firstElementChild)&&b(/<[/\w]/g,e.innerHTML)&&b(/<[/\w]/g,e.textContent))return At(e),!0;if(e.nodeType===Z)return At(e),!0;if(xe&&e.nodeType===J&&b(/<[/\w]/g,e.data))return At(e),!0;if(!De[n]||Fe[n]){if(!Fe[n]&&_t(n)){if(_e.tagNameCheck instanceof RegExp&&b(_e.tagNameCheck,n))return!1;if(_e.tagNameCheck instanceof Function&&_e.tagNameCheck(n))return!1}if(Be&&!Ye[n]){const t=re(e)||e.parentNode,n=oe(e)||e.childNodes;if(n&&t)for(let o=n.length-1;o>=0;--o){const r=Y(n[o],!0);r.__removalCount=(e.__removalCount||0)+1,t.insertBefore(r,ne(e))}}return At(e),!0}return e instanceof v&&!function(e){let t=re(e);t&&t.tagName||(t={namespaceURI:tt,tagName:"template"});const n=d(e.tagName),o=d(t.tagName);return!!ot[e.namespaceURI]&&(e.namespaceURI===Je?t.namespaceURI===et?"svg"===n:t.namespaceURI===Ze?"svg"===n&&("annotation-xml"===o||pt[o]):Boolean(ht[n]):e.namespaceURI===Ze?t.namespaceURI===et?"math"===n:t.namespaceURI===Je?"math"===n&&dt[o]:Boolean(Tt[n]):e.namespaceURI===et?!(t.namespaceURI===Je&&!dt[o])&&!(t.namespaceURI===Ze&&!pt[o])&&!Tt[n]&&(mt[n]||!ht[n]):!("application/xhtml+xml"!==it||!ot[e.namespaceURI]))}(e)?(At(e),!0):"noscript"!==n&&"noembed"!==n&&"noframes"!==n||!b(/<\/no(script|embed|frames)/i,e.innerHTML)?(Ce&&e.nodeType===Q&&(t=e.textContent,c([de,me,he],(e=>{t=T(t,e," ")})),e.textContent!==t&&(p(o.removed,{element:e.cloneNode()}),e.textContent=t)),St("afterSanitizeElements",e,null),!1):(At(e),!0)},vt=function(e,t,n){if(Ue&&("id"===t||"name"===t)&&(n in r||n in st))return!1;if(we&&!Oe[t]&&b(Te,t));else if(ke&&b(Ae,t));else if(!Le[t]||Oe[t]){if(!(_t(e)&&(_e.tagNameCheck instanceof RegExp&&b(_e.tagNameCheck,e)||_e.tagNameCheck instanceof Function&&_e.tagNameCheck(e))&&(_e.attributeNameCheck instanceof RegExp&&b(_e.attributeNameCheck,t)||_e.attributeNameCheck instanceof Function&&_e.attributeNameCheck(t))||"is"===t&&_e.allowCustomizedBuiltInElements&&(_e.tagNameCheck instanceof RegExp&&b(_e.tagNameCheck,n)||_e.tagNameCheck instanceof Function&&_e.tagNameCheck(n))))return!1}else if(Ve[t]);else if(b(Ee,T(n,ye,"")));else if("src"!==t&&"xlink:href"!==t&&"href"!==t||"script"===e||0!==A(n,"data:")||!Xe[e])if(Ne&&!b(ge,T(n,ye,"")));else if(n)return!1;return!0},_t=function(e){return"annotation-xml"!==e&&h(e,be)},Ft=function(e){St("beforeSanitizeAttributes",e,null);const{attributes:t}=e;if(!t)return;const n={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:Le};let r=t.length;for(;r--;){const i=t[r],{name:a,namespaceURI:l,value:u}=i,s=lt(a);let p="value"===a?u:g(u);if(n.attrName=s,n.attrValue=p,n.keepAttr=!0,n.forceKeepAttr=void 0,St("uponSanitizeAttribute",e,n),p=n.attrValue,xe&&b(/((--!?|])>)|<\/(style|title)/i,p)){gt(a,e);continue}if(n.forceKeepAttr)continue;if(gt(a,e),!n.keepAttr)continue;if(!Re&&b(/\/>/i,p)){gt(a,e);continue}Ce&&c([de,me,he],(e=>{p=T(p,e," ")}));const d=lt(e.nodeName);if(vt(d,s,p)){if(!Ge||"id"!==s&&"name"!==s||(gt(a,e),p="user-content-"+p),ie&&"object"==typeof B&&"function"==typeof B.getAttributeType)if(l);else switch(B.getAttributeType(d,s)){case"TrustedHTML":p=ie.createHTML(p);break;case"TrustedScriptURL":p=ie.createScriptURL(p)}try{l?e.setAttributeNS(l,a,p):e.setAttribute(a,p),Et(e)?At(e):f(o.removed)}catch(e){}}}St("afterSanitizeAttributes",e,null)},Ot=function e(t){let n=null;const o=bt(t);for(St("beforeSanitizeShadowDOM",t,null);n=o.nextNode();)St("uponSanitizeShadowNode",n,null),Lt(n)||(n.content instanceof s&&e(n.content),Ft(n));St("afterSanitizeShadowDOM",t,null)};return o.sanitize=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=null,r=null,i=null,l=null;if(nt=!e,nt&&(e="\x3c!--\x3e"),"string"!=typeof e&&!Dt(e)){if("function"!=typeof e.toString)throw E("toString is not a function");if("string"!=typeof(e=e.toString()))throw E("dirty is not a string, aborting")}if(!o.isSupported)return e;if(Ie||ft(t),o.removed=[],"string"==typeof e&&(je=!1),je){if(e.nodeName){const t=lt(e.nodeName);if(!De[t]||Fe[t])throw E("root node is forbidden and cannot be sanitized in-place")}}else if(e instanceof S)n=yt("\x3c!----\x3e"),r=n.ownerDocument.importNode(e,!0),r.nodeType===V&&"BODY"===r.nodeName||"HTML"===r.nodeName?n=r:n.appendChild(r);else{if(!We&&!Ce&&!Me&&-1===e.indexOf("<"))return ie&&ze?ie.createHTML(e):e;if(n=yt(e),!n)return We?null:ze?ae:""}n&&Pe&&At(n.firstChild);const u=bt(je?e:n);for(;i=u.nextNode();)Lt(i)||(i.content instanceof s&&Ot(i.content),Ft(i));if(je)return e;if(We){if(He)for(l=se.call(n.ownerDocument);n.firstChild;)l.appendChild(n.firstChild);else l=n;return(Le.shadowroot||Le.shadowrootmode)&&(l=fe.call(a,l,!0)),l}let f=Me?n.outerHTML:n.innerHTML;return Me&&De["!doctype"]&&n.ownerDocument&&n.ownerDocument.doctype&&n.ownerDocument.doctype.name&&b(K,n.ownerDocument.doctype.name)&&(f="\n"+f),Ce&&c([de,me,he],(e=>{f=T(f,e," ")})),ie&&ze?ie.createHTML(f):f},o.setConfig=function(){ft(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),Ie=!0},o.clearConfig=function(){ut=null,Ie=!1},o.isValidAttribute=function(e,t,n){ut||ft({});const o=lt(e),r=lt(t);return vt(o,r,n)},o.addHook=function(e,t){"function"==typeof t&&(pe[e]=pe[e]||[],p(pe[e],t))},o.removeHook=function(e){if(pe[e])return f(pe[e])},o.removeHooks=function(e){pe[e]&&(pe[e]=[])},o.removeAllHooks=function(){pe={}},o}()}()},912:t=>{"use strict";t.exports=e}},n={};function o(e){var r=n[e];if(void 0!==r)return r.exports;var i=n[e]={exports:{}};return t[e].call(i.exports,i,i.exports,o),i.exports}o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(e,t)=>{for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{"use strict";o.r(r),o.d(r,{default:()=>b});var e=o(912),t=o.n(e),n=o(838),i=o.n(n);function a(e){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a(e)}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function u(e){for(var t=1;te.length)&&(t=e.length);for(var n=0,o=Array(t);n0&&this.magicPasteLinks)h=this.quill.getText(l.index,l.length),p=p.insert(h,{link:u});else if(!s&&d.ALLOWED_TAGS.includes("img")&&f&&"file"===f.kind&&f.type.match(/^image\//i)){var T=f.getAsFile();if(void 0!==this.handleImagePaste)this.handleImagePaste(T);else{var A=new FileReader;A.onload=function(e){a.quill.insertEmbed(l.index,"image",e.target.result),a.keepSelection||a.quill.setSelection(l.index+1)},A.readAsDataURL(T)}}else{var y,b,E,D,S,L,v,_,F;if(s||(m=!0,s=h),"function"==typeof(null===(y=this.hooks)||void 0===y?void 0:y.beforeSanitizeElements)&&i().addHook("beforeSanitizeElements",this.hooks.beforeSanitizeElements),"function"==typeof(null===(b=this.hooks)||void 0===b?void 0:b.uponSanitizeElement)&&i().addHook("uponSanitizeElement",this.hooks.uponSanitizeElement),"function"==typeof(null===(E=this.hooks)||void 0===E?void 0:E.afterSanitizeElements)&&i().addHook("afterSanitizeElements",this.hooks.afterSanitizeElements),"function"==typeof(null===(D=this.hooks)||void 0===D?void 0:D.beforeSanitizeAttributes)&&i().addHook("beforeSanitizeAttributes",this.hooks.beforeSanitizeAttributes),"function"==typeof(null===(S=this.hooks)||void 0===S?void 0:S.uponSanitizeAttribute)&&i().addHook("uponSanitizeAttribute",this.hooks.uponSanitizeAttribute),"function"==typeof(null===(L=this.hooks)||void 0===L?void 0:L.afterSanitizeAttributes)&&i().addHook("afterSanitizeAttributes",this.hooks.afterSanitizeAttributes),"function"==typeof(null===(v=this.hooks)||void 0===v?void 0:v.beforeSanitizeShadowDOM)&&i().addHook("beforeSanitizeShadowDOM",this.hooks.beforeSanitizeShadowDOM),"function"==typeof(null===(_=this.hooks)||void 0===_?void 0:_.uponSanitizeShadowNode)&&i().addHook("uponSanitizeShadowNode",this.hooks.uponSanitizeShadowNode),"function"==typeof(null===(F=this.hooks)||void 0===F?void 0:F.afterSanitizeShadowDOM)&&i().addHook("afterSanitizeShadowDOM",this.hooks.afterSanitizeShadowDOM),m)h=i().sanitize(s,d),p=p.insert(h);else{if(s=d.ALLOWED_TAGS.includes("table")?this.tableHeadersToCells(s):this.convertTableContent(s),!1!==this.substituteBlockElements){var O,k=function(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var o,r,i,a,l=[],u=!0,s=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;u=!1}else for(;!(u=(o=i.call(n)).done)&&(l.push(o.value),l.length!==t);u=!0);}catch(e){s=!0,r=e}finally{try{if(!u&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(s)throw r}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return c(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?c(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}(this.substitute(s,d),2);s=k[0],O=k[1],h=s.innerHTML,this.removeConsecutiveSubstitutionTags&&(h=this.collapseConsecutiveSubstitutionTags(h,O))}else h=i().sanitize(s,d);p=p.concat(this.convert({html:h}))}}this.quill.updateContents(p,t().sources.USER),m||(p=this.convert({html:h})),this.keepSelection?this.quill.setSelection(l.index,p.length(),t().sources.SILENT):this.quill.setSelection(l.index+p.length(),t().sources.SILENT),this.quill.scrollSelectionIntoView(),i().removeAllHooks()}}}},{key:"collapseConsecutiveSubstitutionTags",value:function(e,t){var n=(new DOMParser).parseFromString(e,"text/html"),o=n.querySelectorAll(t),r=!1;return o.forEach((function(e){r?null===e.firstChild||3===e.firstChild.nodeType&&""===e.firstChild.nodeValue.trim()?e.parentNode.removeChild(e):r=!1:r=!0})),n.body.innerHTML}},{key:"tableHeadersToCells",value:function(e){var t=(new DOMParser).parseFromString(e,"text/html");return t.querySelectorAll("table").forEach((function(e){var t=e.querySelector("thead");if(t){var n=e.querySelector("tbody");if(n){var o=t.querySelector("tr");n.insertBefore(o,n.firstChild)}}e.querySelectorAll("th").forEach((function(e){var t=document.createElement("td");t.innerHTML=e.innerHTML,e.parentNode.replaceChild(t,e)}))})),"".concat(t.body.outerHTML,"")}},{key:"convertTableContent",value:function(e){var t=(new DOMParser).parseFromString(e,"text/html");return t.querySelectorAll("tr").forEach((function(e){e.outerHTML="

".concat(Array.from(e.querySelectorAll("td, th")).map((function(e){return e.innerHTML})).join(" "),"

")})),t.querySelectorAll("td, th").forEach((function(e){e.outerHTML="".concat(e.innerHTML," ")})),t.querySelectorAll("thead, tbody, tfoot").forEach((function(e){e.outerHTML=e.innerHTML})),t.querySelectorAll("table").forEach((function(e){e.outerHTML=e.innerHTML})),"".concat(t.body.outerHTML,"")}},{key:"getDOMPurifyOptions",value:function(){var e,t,n={};if(null!==(e=this.allowed)&&void 0!==e&&e.tags&&(n.ALLOWED_TAGS=this.allowed.tags),null!==(t=this.allowed)&&void 0!==t&&t.attributes&&(n.ALLOWED_ATTR=this.allowed.attributes),void 0===n.ALLOWED_TAGS||void 0===n.ALLOWED_ATTR){var o,r=!1;void 0===n.ALLOWED_TAGS&&(r=!0,n.ALLOWED_TAGS=["p","br","span"]);var i=!1;void 0===n.ALLOWED_ATTR&&(i=!0,n.ALLOWED_ATTR=["class"]);var a,l=this.quill.getModule("toolbar");null==l||null===(o=l.controls)||void 0===o||o.forEach((function(e){switch(e[0]){case"bold":r&&(n.ALLOWED_TAGS.push("b"),n.ALLOWED_TAGS.push("strong"));break;case"italic":r&&(n.ALLOWED_TAGS.push("i"),n.ALLOWED_TAGS.push("em"));break;case"underline":r&&n.ALLOWED_TAGS.push("u");break;case"strike":r&&n.ALLOWED_TAGS.push("s");break;case"color":case"background":i&&n.ALLOWED_ATTR.push("style");break;case"script":r&&("super"===e[1].value?n.ALLOWED_TAGS.push("sup"):"sub"===e[1].value&&n.ALLOWED_TAGS.push("sub"));break;case"header":if(r){var t=function(e){"1"===e?n.ALLOWED_TAGS.push("h1"):"2"===e?n.ALLOWED_TAGS.push("h2"):"3"===e?n.ALLOWED_TAGS.push("h3"):"4"===e?n.ALLOWED_TAGS.push("h4"):"5"===e?n.ALLOWED_TAGS.push("h5"):"6"===e&&n.ALLOWED_TAGS.push("h6")};e[1].value?t(e[1].value):e[1].options&&e[1].options.length&&[].forEach.call(e[1].options,(function(e){e.value&&t(e.value)}))}break;case"code-block":r&&n.ALLOWED_TAGS.push("pre"),i&&n.ALLOWED_ATTR.push("spellcheck");break;case"list":r&&("ordered"===e[1].value?n.ALLOWED_TAGS.push("ol"):"bullet"===e[1].value&&n.ALLOWED_TAGS.push("ul"),n.ALLOWED_TAGS.push("li"));break;case"link":r&&n.ALLOWED_TAGS.push("a"),i&&(n.ALLOWED_ATTR.push("href"),n.ALLOWED_ATTR.push("target"),n.ALLOWED_ATTR.push("rel"));break;case"image":r&&n.ALLOWED_TAGS.push("img"),i&&(n.ALLOWED_ATTR.push("src"),n.ALLOWED_ATTR.push("title"),n.ALLOWED_ATTR.push("alt"),n.ALLOWED_ATTR.push("height"),n.ALLOWED_ATTR.push("width"));break;case"video":r&&n.ALLOWED_TAGS.push("iframe"),i&&(n.ALLOWED_ATTR.push("frameborder"),n.ALLOWED_ATTR.push("allowfullscreen"),n.ALLOWED_ATTR.push("src"),n.ALLOWED_ATTR.push("height"),n.ALLOWED_ATTR.push("width"));break;case"blockquote":r&&n.ALLOWED_TAGS.push(e[0]);break;case"table":r&&(n.ALLOWED_TAGS.push("table"),n.ALLOWED_TAGS.push("tr"),n.ALLOWED_TAGS.push("td"))}})),null!=l&&l.controls&&(null===(a=this.customButtons)||void 0===a||a.forEach((function(e){var t,o;l.controls.some((function(t){return t[0]===e.module}))&&(null===(t=e.allowedTags)||void 0===t||t.forEach((function(e){n.ALLOWED_TAGS.push(e)})),null===(o=e.allowedAttr)||void 0===o||o.forEach((function(e){n.ALLOWED_ATTR.push(e)})))})))}return n}},{key:"substitute",value:function(e,t){var n,o=["h1","h2","h3","h4","h5","h6"],r=["p","div","section","article","fieldset","address","aside","blockquote","canvas","dl","figcaption","figure","footer","form","header","main","nav","noscript","ol","pre","ul","video"],a=["li","dt","dd","hr"];return i().addHook("uponSanitizeElement",(function(e,i,l){for(var u=0;!n&&u<3;)t.ALLOWED_TAGS.includes(r[u])&&(n=r[u]),++u;if(n&&e.tagName&&!t.ALLOWED_TAGS.includes(e.tagName.toLowerCase())){var s=e.tagName.toLowerCase();o.includes(s)?e.innerHTML="<".concat(n,">").concat(e.innerHTML,""):r.includes(s)?e.innerHTML="<".concat(n,">").concat(e.innerHTML,""):a.includes(s)&&(e.innerHTML="".concat(e.innerHTML,"
"))}})),e=i().sanitize(e,u(u({},t),{RETURN_DOM:!0,WHOLE_DOCUMENT:!1})),i().removeAllHooks(),[e,n]}},{key:"isURL",value:function(e){return!!/^(?:(?:http[s\u017F]?|ftp):\/\/)(?:(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+(?::(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?@)?(?:(?!10(?:\.[0-9]{1,3}){3})(?!127(?:\.[0-9]{1,3}){3})(?!169\.254(?:\.[0-9]{1,3}){2})(?!192\.168(?:\.[0-9]{1,3}){2})(?!172\.(?:1[6-9]|2[0-9]|3[01])(?:\.[0-9]{1,3}){2})(?:[1-9][0-9]?|1[0-9][0-9]|2[01][0-9]|22[0-3])(?:\.(?:1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])){2}(?:\.(?:[1-9][0-9]?|1[0-9][0-9]|2[0-4][0-9]|25[0-4]))|(?:(?:(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+\x2D?)*(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)(?:\.(?:(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+\x2D?)*(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)*(?:\.(?:(?:[KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]){2,})))(?::[0-9]{2,5})?(?:\/(?:(?![\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uD800-\uDFFF\uFEFF])[\s\S]|[\uD800-\uDBFF][\uDC00-\uDFFF])*)?$/i.test(e)}}],r&&f(o.prototype,r),Object.defineProperty(o,"prototype",{writable:!1}),o;var o,r}(A);t().register("modules/clipboard",y,!0);const b=y})(),r})())); --------------------------------------------------------------------------------