Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Clipboard module docs #2808

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 23 additions & 2 deletions docs/docs/modules/clipboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ quill.clipboard.addMatcher('B', function(node, delta) {

### dangerouslyPasteHTML

Inserts content represented by HTML snippet into editor at a given index. The snippet is interpreted by Clipboard [matchers](#addMatcher), which may not produce the exactly input HTML. If no insertion index is provided, the entire editor contents will be overwritten. The [source](/docs/api/#events) may be `"user"`, `"api"`, or `"silent"`.
Inserts content represented by HTML snippet into editor at a given index, and sets the window focus to the Quill editor at that index. The snippet is interpreted by Clipboard [matchers](#addMatcher), which may not produce the exactly input HTML. If no insertion index is provided, the entire editor contents will be overwritten. The [source](/docs/api/#events) may be `"user"`, `"api"`, or `"silent"`.

Improper handling of HTML can lead to [cross site scripting (XSS)](https://www.owasp.org/index.php/Cross-site_Scripting_(XSS)) and failure to sanitize properly is both notoriously error-prone and a leading cause of web vulnerabilities. This method follows React's example and is aptly named to ensure the developer has taken the necessary precautions.

Expand All @@ -56,9 +56,30 @@ dangerouslyPasteHTML(index: Number, html: String, source: String = 'api')
quill.setText('Hello!');

quill.clipboard.dangerouslyPasteHTML(5, '&nbsp;<b>World</b>');
// Editor is now '<p>Hello&nbsp;<strong>World</strong>!</p>';
// Editor is now '<p>Hello&nbsp;<strong>World</strong>!</p>' and has the input focus captured.
```

### convert

Converts a string of text or HTML to a [Delta](/docs/delta/). This is used by `dangerouslyPasteHTML` and all the same warnings apply.

**Methods**

```javascript
convert({text: String}) => Delta
convert({html: String}) => Delta
```

**Examples**

```javascript
const html = '<p>Set HTML content <i>without</i> changing focus</p>'
const delta = quill.clipboard.convert(html);
quill.setContents(delta);
// Editor is now '<p>Set HTML content <i>without</i> changing focus</p>' and has not changed focus;
```



## Configuration

Expand Down