Sunday, March 26, 2023
Learning Code
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#
No Result
View All Result
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#
No Result
View All Result
Learning Code
No Result
View All Result
Home JavaScript

Removing unwanted characters in HTML Editor – JavaScript – SitePoint Forums

learningcode_x1mckf by learningcode_x1mckf
December 17, 2022
in JavaScript
0
Removing unwanted characters in HTML Editor – JavaScript – SitePoint Forums
74
SHARES
1.2k
VIEWS
Share on FacebookShare on Twitter


javascript7:

<script src="https://cdn.quilljs.com/2.0.0-dev.2/quill.js"></script>

That’s the Quill library.

javascript7:

Not conversant in “matcher”.

Me neither, actually. I simply did a little bit of looking out and that was what got here up.

Nonetheless, right here’s one thing of a proof:

Quill has an idea of modules, which permit Quill’s conduct and performance to be personalized. The Clipboard module is required by Quill and doesn’t must be included explicitly.

The Clipboard handles copy, lower and paste between Quill and exterior functions. This has an API which permits us to customise this behaviour. We will do that with matchers and the addMatcher methodology.

// Initialize Quill
const quill = new Quill('#editor', 
  ...


// Add a matcher
quill.cliboard.addMatcher(selector, (node, delta) => 
  // Code to customise the clipboard conduct right here
);

For an outline of what matchers, nodes and deltas are, please seek advice from the Clipboard module’s docs (linked above).

By following the docs and examples I discovered on Stack Overflow, I used to be capable of get the next matcher to work for me and to strip out any formatting on paste:

quill.clipboard.addMatcher (Node.ELEMENT_NODE, (node, delta) => 
  const plaintext = node.innerText;
  const Delta = Quill.import('delta');
  return new Delta().insert(plaintext);
);

Right here is the whole code with the intention to run it in context. I took the setup code from Quill’s quick start page.

<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="utf-8">
  <title>Quill clipboard demo</title>
  <hyperlink href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
</head>
<physique>

  <div id="editor">
    <p>Hiya World!</p>
    <p>Some preliminary <sturdy>daring</sturdy> textual content</p>
    <p><br></p>
  </div>

  <script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
  <script>
    const quill = new Quill('#editor', 
      theme: 'snow',
    );

    quill.clipboard.addMatcher (Node.ELEMENT_NODE, (node, delta) => 
      const plaintext = node.innerText;
      const Delta = Quill.import('delta');
      return new Delta().insert(plaintext);
    );
  </script>
</physique>
</html>

To see the demo in motion attempt copy/pasting any formatted textual content (from this thread, for instance). With the matcher lively, it needs to be inserted as plain textual content. If you happen to delete the matcher, it ought to retain its formatting.



Source link

You might also like

Hackers Inject Weaponized JavaScript (JS) on 51,000 Websites – GBHackers

4 Ways to Remove a Specific Item From a JavaScript Array – MUO – MakeUseOf

Toolkit Allows JavaScript Devs to Program Embedded Devices – The New Stack

Share30Tweet19
learningcode_x1mckf

learningcode_x1mckf

Recommended For You

Hackers Inject Weaponized JavaScript (JS) on 51,000 Websites – GBHackers

by learningcode_x1mckf
March 25, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

Hackers Inject Weaponized JavaScript (JS) on 51,000 Websites  GBHackers Source link

Read more

4 Ways to Remove a Specific Item From a JavaScript Array – MUO – MakeUseOf

by learningcode_x1mckf
March 24, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

4 Ways to Remove a Specific Item From a JavaScript Array  MUO - MakeUseOf Source link

Read more

Toolkit Allows JavaScript Devs to Program Embedded Devices – The New Stack

by learningcode_x1mckf
March 23, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

Toolkit Allows JavaScript Devs to Program Embedded Devices  The New Stack Source link

Read more

Select data value from grandparent div? – JavaScript – SitePoint

by learningcode_x1mckf
March 23, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

Select data value from grandparent div? - JavaScript  SitePoint Source link

Read more

How to Handle Errors in JavaScript – Programming – MUO – MakeUseOf

by learningcode_x1mckf
March 23, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

How to Handle Errors in JavaScript - Programming  MUO - MakeUseOf Source link

Read more
Next Post
Java Application Development Services That Are Guaranteed to Take Your Business to the Next Level

Java Application Development Services That Are Guaranteed to Take Your Business to the Next Level

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related News

Building Systems With Classes – Real Python

Building Systems With Classes – Real Python

February 7, 2023
Rust Users Rejoice! Chromium Adds Support For The Better C++

Rust Users Rejoice! Chromium Adds Support For The Better C++

January 24, 2023
How to Update Object Key Values Using Javascript

How to Update Object Key Values Using Javascript

October 17, 2022

Browse by Category

  • C#
  • C++
  • Java
  • JavaScript
  • Python
  • Swift

RECENT POSTS

  • 2023 Java roadmap for developers – TheServerSide.com
  • YS Jagan launches Ragi Java in Jagananna Gorumudda, says focused on intellectual development of students – The Hans India
  • Disadvantages of Java – TheServerSide.com

CATEGORIES

  • C#
  • C++
  • Java
  • JavaScript
  • Python
  • Swift

© 2022 Copyright Learning Code

No Result
View All Result
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#

© 2022 Copyright Learning Code

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?