The State of contenteditable
The markup produced by wysiwyg editors is atrocious. Its littered with style attributes and often is not even valid HTML (missing closing tags, overlapping styling, etc). Are there any established solutions to the problems introduced by contenteditable
? If not, how can I go about creating one?
Invalid HTML
For instance, after entering an unordered list followed by a line of text into a popular rich text editor I am presented with the following HTML:
<ul><li>foo</li><li>bar</li></ul><div>baz
Where did the div
tag come from? Why doesn't it get closed? Why not a paragraph - properly closed, of course? Is this preventable?
Non-Semantic HTML
Another editor produced the following:
<p style="font-size:11pt; line-height:115%; margin:0pt 0pt 0pt 36pt; text-indent:-18pt"><span style="color:#000000; font-family:Arial; font-size:11pt; font-style:normal; font-weight:normal; text-decoration:none">●</span><span style="font:7.0pt 'Times New Roman'"> </span><span style="color:#000000; font-family:Arial; font-size:11pt; font-style:normal; font-weight:normal; text-decoration:none">Lorem</span></p><p style="font-size:11pt; line-height:115%; margin:0pt 0pt 0pt 36pt; text-indent:-18pt"><span style="color:#000000; font-family:Arial; font-size:11pt; font-style:normal; font-weight:normal; text-decoration:none">●</span><span style="font:7.0pt 'Times New Roman'"> </span><span style="color:#000000; font-family:Arial; font-size:11pt; font-style:normal; font-weight:normal; text-decoration:none">ipsum</span></p>
This is valid markup, but it's semantically horrible! Instead of a styled unordered list, the editor has inserted literal bullet characters. As a developer, I have no idea what to do with the markup contenteditable
has produced. As far as styling goes, it's utterly useless.
Substitutions
Up until recently, I have been using Markdown as a tool for generating semantically correct HTML from users. However, Markdown lacks certain features that my users are asking for (ease of use for non-techies, image positioning, etc). After looking for a wysiwyg editor that will produce valid, semantic markup for several weeks, I've found that contenteditable
makes this impossible. Is someone somewhere talking about solutions to these issues? How can I get involved.
[Update] Clarification
I suppose I wasn't completely clear up front. I'm not asking for ways to get around contenteditable
's problems. I've found lots of those, including most of the ones mentioned below. What I'm trying to find is the root cause of these issues. Why is contenteditable
so broken? Is it due to technical problems or legacy code issues? Moreover, what is being done to fix it and where is this work being done?
[Update] Google Docs
The HTML in the second example above came from the Google Docs Editor. However, as AlfonsoML points out below, Google Docs does not use contenteditable
in their editor. Their technique is explained here.