suneditor icon indicating copy to clipboard operation
suneditor copied to clipboard

How to keep original html or adjust SunEditor's standardized html function?

Open conquerorvn opened this issue 5 years ago • 11 comments

Hi SunEditor, When add html to the editor, SunEditor will standardize the html by adding some tags, removing the attributes of some tags, especially the <img> and <table>. For my project, I need SunEditor to keep the original Html? or adjust SunEditor's standardized html function? Could you give me some guide.

conquerorvn avatar Dec 12 '20 02:12 conquerorvn

Yes, interested in this one too, it also does this with the <div> tags, although managed to force a class that i can alter through a CSS file, in my instance I want to put a background image or color to a <div> .

dreamsight avatar Dec 13 '20 13:12 dreamsight

Sorry, for the late reply.😢 The __se__tag class prevents subtag changes. can you show me the you html string?

JiHong88 avatar Dec 27 '20 10:12 JiHong88

Is there a solution to this problem?

cscxj avatar Oct 19 '22 07:10 cscxj

@JiHong88 My html:

<table>
  <tr>
    <td>
      <a href="#">link</a>
    </td>
  </tr>
</table>

After standardization:

<table>
  <tbody>
    <tr>
      <td>
        <div><a href="#">link</a></div>
      </td>
    </tr>
  </tbody>
</table>

cscxj avatar Oct 19 '22 07:10 cscxj

@cscxj Currently, That format is a forced format. Can't chang.

JiHong88 avatar Oct 19 '22 08:10 JiHong88

@JiHong88 not sure if this is related but im trying to add attributes in code view but when i toggle back in it disappears

<h1 id="my-anchor">Introduction<h1>

abdulkarim-ogaji avatar Nov 07 '22 10:11 abdulkarim-ogaji

@AbdulkarimOgaji You can use the attributesWhitelist option. ex)

attributesWhitelist: {
'all': 'style|data-.+', // Apply to all tags
input': 'checked|name' // Apply to input tag
 '???': '*' // "*" === all attributes
}

JiHong88 avatar Nov 08 '22 20:11 JiHong88

I tried that snippet above as well, and it does work for the style attribute, but not class. I assume that's because class is part of the native attributes and it conflicts if allowed in the whitelist so using this:

'all': 'class|style',

This code wouldn't actually work for class just style. Is that assumption correct?

eklect avatar Sep 06 '23 04:09 eklect

It seems the "class" attribute always gets removed even with 'all': '*' Is there any workaround for this?

glrph avatar Mar 28 '24 14:03 glrph

https://github.com/JiHong88/suneditor/issues/1320

As of 2.46.3, you should be able to use strictMode: false option, no? Maybe this issue can be closed?

aburd avatar Jul 16 '24 03:07 aburd