title: Don't keep inline styles or tag attributes in clipboard when user copies text content from a contentEditable
body: <p>HTML divs with <code>contentEditable</code> keep any styles applied to the text when a user highlights and copies.</p>
  <p>I have a <code>contentEditable</code> div where text inside the div becomes decorated with underlines via inline styles on spans of text. Currently if a user highlights the text and copies, if they later paste it into another contentEditable - for example, Gmail's email compose box - it keeps the underlines.</p>
  <p>So for example, a line of text may look like (in the DOM):</p>
  <pre><code>&lt;span class=&quot;underline&quot; 
   id=&quot;id-1&quot; 
   style=&quot;box-shadow: white 0px 0px 0px 0px inset, 
   rgb(1, 2, 3) 0px -2px 0px 0px inset; 
   background-color: transparent;&quot;&gt;This is an example.&lt;/span&gt;
  </code></pre>
  <p>And once it has been copied and then pasted into Gmail, it's added to the DOM as:</p>
  <pre><code>&lt;span class=&quot;gmail-underline&quot; 
   id=&quot;gmail-id-1&quot; 
   style=&quot;box-shadow: white 0px 0px 0px 0px inset, 
   rgb(1, 2, 3) 0px -2px 0px 0px inset; 
   background-color: transparent;&quot;&gt;This is an example.&lt;/span&gt;
  </code></pre>
  <p>Which means within Gmail's editor, which is also contentEditable, the underline from the original div remains.</p>
  <p>Gmail does some processing here to add <code>gmail-</code> to the <code>id</code> and <code>class</code>, but the point is, that data was available on the clipboard.</p>
  <p>How can I make it so that when a user does a regular copy from the original div, highlighting the text and pressing CTRL+C or right click-&gt; copy, they only get the text (i.e. <code>innerText</code>) in the div and none of the markup is retained?</p>
  <p>This appears to only be an issue copying between contentEditables - if the above sentence were copied to, say, Microsoft Word, it would just be &quot;This is an example.&quot;, no HTML around it.</p>
  <p>I believe something can be done with intercepting copy events and possibly using <code>document.execCommand</code> to copy, but am not sure how to do it. I've seen similar questions about <em>pasting</em> into contentEditables, but haven't found anything about stopping it at the source when copying.</p>