medium-editor icon indicating copy to clipboard operation
medium-editor copied to clipboard

Pasting with cleanPastedHTML: true removes divs from all text

Open oznek opened this issue 10 years ago • 9 comments

When pasting a text from an article, medium editor is removing all embeded images added with medium-editor-insert-plugin, which are figures surrounded by divs.

el.querySelectorAll('a,p,div,br') pass all text (and not only pasted text) to filterCommonBlocks, which removes the div. Is this the expected behavior?

Medium editor should not consider all text around the pasted code as already valid?

oznek avatar May 27 '15 20:05 oznek

Would you mind giving a bit more context/examples about this issue? What HTML are you trying to paste and what is the resulting HTML? Apologies, but I'm having trouble understanding what you were seeing.

nmielnik avatar May 27 '15 21:05 nmielnik

Sorry for the delay.

medium-editor-insert-plugin inserts a div for images or embeds. Having this text in editor, for instance:

<p>Paragraph</p>
<div class="medium-insert-images"><figure>
    <img src="image.jpg" alt="">
</figure></div>

When I paste an HTML code (e.g. a simple paragraph with a A link tag), the figure div disappears.

oznek avatar Jun 10 '15 19:06 oznek

Could you tell us which option do you enable for the paste extension?

j0k3r avatar Jun 10 '15 19:06 j0k3r

I'm using these configs:

  paste:{
    forcePlainText: false,
    cleanPastedHTML: true,
    cleanAttrs: ['class', 'style', 'dir'],
    cleanTags: ['br', 'meta', 'body', 'section', 'aside', 'article',
      'span', 'h1', 'h2', 'font']
  },

oznek avatar Jun 10 '15 21:06 oznek

@oznek Could you check again with the last release (5.6.2) ? We've fixed few things related to pastes html.

j0k3r avatar Aug 12 '15 13:08 j0k3r

@j0k3r not working. filterCommonBlocks still clean up divs with only images inside. ( textContent or innerText returns empty string ).

evgeniypetrov avatar Aug 28 '15 00:08 evgeniypetrov

I got the same problem. filterCommonBlocks function remove all div elements which contain images.

sunmenghua avatar Feb 05 '18 03:02 sunmenghua

Same problem here. I'm trying to paste text with images from medium.com but the images (inside a div) are always remove

Lwdthe1 avatar Jul 19 '19 00:07 Lwdthe1

the problem still exists, i updated code if (/^\s*$/.test(el.textContent) && el.parentNode) { -----> if (/^\s*$/.test(el.textContent) && el.parentNode && !el.querySelector('img')) {

wgm89 avatar Jun 29 '20 06:06 wgm89