JiHong88 / suneditor

Pure javascript based WYSIWYG html editor, with no dependencies.
http://suneditor.com
MIT License
1.74k stars 309 forks source link

Span tag is being wiped out on setContents #1328

Open censys-git opened 11 months ago

censys-git commented 11 months ago

I allow special text to be typed into the editor area (e.g. '@client') and on blur, I replace it with a span tag with attributes and the value associated with the "Client's Name" I am working on. I call them dynamic fields since SunEditor does not appear to support this. I set the span tag with attributes "class", "data-tag" and "title" to keep track that this is a dynamic field (in case for example the client name changes in settings, I can update throughout the document quickly).

I may not be doing this correctly, but because this is a pretty big text area being edited, I wait until blur and then call getContents to get the entire area of content and then do a global replace of the \@ tags with the span html. I then call setContents to reset the new HTML.

I console.log the replaced content with the span tags and it's all there, yet once I call setContents, the value from the span tags are all in the content but the span tags are completely wiped out! Gone. No tag what-so-ever. Why?

What am I not seeing that the span tag is wiped out? If I use a "em" tag or a "p" tag, it works fine and the tags and attributes remain, but not with a "span" tag. Why? Makes no sense. Hope one of the more experienced SunEditor folks can help enlighten me.

lhguerra commented 4 days ago

I'm having a similar issue when trying to write a span directly in code view, I type it, then switch to normal view then to code view again, all its attrs are gone and the span became a p