0

Is there a way how to paste formatted text to ckeditor without styles and preserving semantics?

For example this is what it pastes:

<h1 style="font-family: sans-serif; color: rgb(34, 34, 34); line-height: 18.2000007629395px;">An h1 header</h1>

<p style="color: rgb(34, 34, 34); font-family: sans-serif; font-size: small; line-height: 18.2000007629395px;">Paragraphs are separated by a blank line.</p>

<p style="color: rgb(34, 34, 34); font-family: sans-serif; font-size: small; line-height: 18.2000007629395px;">2nd paragraph.&nbsp;<em>Italic</em>,&nbsp;<strong>bold</strong>, and&nbsp;<code style="white-space: pre; background-color: rgb(238, 238, 238);">monospace</code>. Itemized lists look like:</p>

<ul style="color: rgb(34, 34, 34); font-family: sans-serif; font-size: small; line-height: 18.2000007629395px;">
    <li>this one</li>
    <li>that one</li>
    <li>the other one</li>
</ul>

But I want to paste this:

<h1>An h1 header</h1>

<p>Paragraphs are separated by a blank line.</p>

<p>2nd paragraph.&nbsp;<em>Italic</em>,&nbsp;<strong>bold</strong>, and&nbsp;<code>monospace</code>. Itemized lists look like:</p>

<ul>
    <li>this one</li>
    <li>that one</li>
    <li>the other one</li>
</ul>
Sergey Kuryanov
  • 6,114
  • 30
  • 52
ondrej
  • 967
  • 7
  • 26

1 Answers1

0

If you have the Advanced Content Filter enabled (should be enabled by default), then it will filter the pasted content according to what your editor's configuration allow. Read more in the Content Filtering guide.

However, if you disabled ACF for some reasons, or you want to filter the pasted content differently, then you can create your own CKEDITOR.filter instance and apply it to the pasted data. Read more in Apply CKEditor Advanced Content Filter to a string on how to apply the filter to HTML string.

Community
  • 1
  • 1
Reinmar
  • 21,729
  • 4
  • 67
  • 78