storypioneers / kirby-wysiwyg

WYSIWYG panel field for Kirby CMS
Other
125 stars 16 forks source link

Wild <span> elements in medium-editor output #1

Closed JonasDoebertin closed 9 years ago

JonasDoebertin commented 9 years ago

Sometimes, when copy and pasting text inside the editor, there are some wild <span> elements being added. As they randomly have line-height and font-size inline styles attached, they might break the pages design.

dgdsp commented 9 years ago

an option would be to convert to plaintext via innerTEXT, cf. http://stackoverflow.com/questions/6899659/remove-formatting-from-a-contenteditable-div

JonasDoebertin commented 9 years ago

The way the field works is that everytime the user modifies the content within the editor, the whole content is mirrored into a hidden textarea. This happens, since the medium editor uses a contenteditable <div> and the panel doesn't know how to save these. The panel will save the textarea as the field value instead.

So I guess we have to filter through the textarea and remove all <span> elements (only the tags, not the content). The easiest way would be to do this server side, once the user hits the "Save" button. We can't just remove all HTML, since the editor allows for some formatting options that Markdown just don't support, like subscript, superscript, del, ins and mark tags. They are embedded as inline html (which is explicitly allowed in Markdown).

I'll prepare something tomorrow.

JonasDoebertin commented 9 years ago

Fixed with 2b9fe86365530b160a16673bf402ce43ec9a931a.