Thoughts on the future of web-based HTML editors

The ability of editing HTML content on the web is nothing new, we've all used it to write emails in Web-based email clients, post content on our blogs, adding content to web sites, etc.  Web sites usually do this using the execCommand API, with either iframes put into designMode, or contentEditable elements, and occasionally utilize things such as the DOM Range API and Selection API.

Things sound great, but in practice, they're not.  If you're a web developer, you know that almost nobody tries to use the above APIs directly, and instead everyone resorts to one of the web editor widgets.  The reason for that in my opinion is that there are numerous problems with how browsers implement HTML editing, and these problems cause real pain for web developers, and make it extremely tricky, if possible at all, to get a cross browser and interoperable HTML editing experience.  So, let's see where the problem lies.

  • Problems with the API.  The execCommand API was first added to IE 5.5 by Microsoft.  This API is very different to all other web APIs, and is in fact an adaptation of the IOleCommandTarget API in MSCOM.  This API is very hard to use, because:
    • It is unintuitive: you just issue commands, and you can't even control where the commands are going to end up affecting directly.
    • It is not extensible: you don't have any way to add your own editing commands in a seamless way.  You can't even query the browser to determine which sets of commands it supports.
    • It is not customizable: some of the commands might show a user interface component provided by the browser, and there is no way to disable that UI or change how it looks.
    • It is not comprehensive: some very important editing functions (like undo/redo lists and spell-checking) are not exposed via the API at all, so there is no way to integrate them into your web application.  You can't even be sure that those built-in facilities will even work if you're not careful enough (example: modifying the editable DOM tree in some browsers disables undo/redo functionality.)
  • Lack of specification.  Because web based editing was first added as a proprietary feature to IE, there is no specification defining how it should work.  Other browsers tried to come up with a compatible set of APIs, but that's unfortunately not even possible, because nobody really knows how IE works in every aspect, so nobody can aim to emulate its behavior correctly.  The lack of specification has created several real-world problems for both web developers and users:
    • Nobody knows what should happen after a command.  For example, when you issue a bold command, some browsers choose to wrap the selected text in a <b> tag, some use a <strong> tag, and some use CSS styles on a <span> element (and there are many more cases for what can happen when a bold command is issued.  This means that if you issue a set of editing commands in different browsers, the HTML markup generated can vary greatly.
    • Nobody knows how (and if) interoperability should happen.  Let's take the example of the bold command here.  Because different browsers tend to use different methods to make text bold, they usually have difficulty removing the bold style from some piece of text.  This is really frustrating for users, and there is no easy solution to this problem.
    • Nobody knows how keyboard commands should affect the editable area.  Pressing a key can have multiple results based on the position of selection/caret.  For example, pressing Enter can lead to text being deleted, injected, elements being deleted, injected, and it can modify the caret position in unexpected ways.
    • The default behavior of keyboard shortcuts are not specified.   For example, web browsers may choose to tie Ctrl/Cmd+B to the Bold command, but it's not possible for web pages to determine what these keyboard shortcuts do, and if they are even available (they might not be on localized versions of browsers, for example.)
    • Nobody knows how the browser should handle HTML data from external sources (such as pasting something inside the editor, or setting the innerHTML attribute.)
  • Poor quality of implementation.  Implementing an HTML editor can be extremely complex.  And it turns out that you can actually find bugs with all of the major browsers by just playing with a content editable element for a few minutes!

As you can see, the situation is not very good here.  We have some API which has a lot of problems in its own, and every browser has tried to implement it to some extent, but the behavior of each browser is different, and there is no specification which determines how a browser should implement this functionality.  What this means in practice for web developers is that getting a cross-browser web application which uses these APIs directly is extremely difficult to achieve, and that is why web developers prefer to use web editor widgets which have tried to abstract away as much of these problems as possible.

There have been some attempts at trying to add a common denominator of what different browsers do today into the HTML5 specification, but we need more comprehensive specification to be able to address all of the existing issues.

Mozilla has recently launched a mailing list for people interested in the current state and future of HTML editing in web browsers.  The list is called htmlediting-community.  We are looking for web developers, engineers working on browser engines, people interested in web based APIs and the future of HTML editing to join to this list, so that we can discuss the current issues with HTML editing in web browsers, and where we should be headed in terms of improvements to the web-based HTML editing experience for both users and developers.  Subscribe to this list here!

I've recently started to work on Mozilla's HTML editor implementation (which is called Midas).  I have some plans on how to attack the above problems from different aspects.  Some of the plans are laid out as the following.

  • Fixing some problems which are relatively easy to fix in the near future.  I think we should have both a short and long term plan, and we should try to make some improvements, especially those which can help web developers and users a lot.  I'm looking for feedback from web developers on what those issues are, so that I can come up with a list of things to fix hopefully for the next release of Firefox.
  • Trying to create a comprehensive specification which can be used to implement HTML editing consistently across browsers and platforms.  This specification should address the currently existing APIs and user interactions, and should also propose a new set of APIs which don't suffer from the basic problems I described above.  The new APIs should be extensible, customizable, intuitive and comprehensive.
  • Trying to write a set of cross-browser unit tests which can be used to test the implementation of both the existing and new APIs in different browsers.  The very important thing here is for the tests to work on multiple browsers, because I want the result of this work to be useful for other browser engines as well, so that we can all help move the web forward by providing a better HTML editing experience across browsers.  I've decided that I would try to extend the current BrowserScope RichText tests, so that we can use that work inside Mozilla and hopefully other browsers.
  • Trying to look into the best approach to move the HTML editor component for Mozilla forward.  At this point, I believe that rewriting the HTML editing support in JavaScript might be the best path to take here, because the existing code is extremely complex and fragile, and is not very well understood.  Also, implement this in JavaScript could have a few advantages, like making the less likely to cause crashes, more readable, and cleaner.  And maybe at some point we can actually consider taking the Mozilla-specific code and rewriting it for other web engines so that we can make the same code work in other browsers!

I'm still trying to figure out what needs to be done exactly in each part, and how to best tackle the problems.  I'd very much like to hear what the web has to say here.  If you're a web developer, web browser engineer, or even a simple user, please leave comments and share what you think.  I will be writing more about this topic as I give it more thoughts, so you can keep an eye on the related posts in the future.  Oh, and participation on the htmlediting-community mailing list is very much appreciated as well!

Trackback URL for this post:

http://ehsanakhgari.org/trackback/107

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

KompoZer, SeaMonkey, and mozilla-central

You might want to get in contact with Fabien from KompoZer as well, as we're trying to tie in his work into SeaMonkey/comm-central in the 1.9.3 timeframe, and he might have some patches against mozilla-central as well that he might want to land or work on.

Revelation!

Finally someone covers this topic again.

I have been trying to get this topic some attention for years. It astounds me that people talk about the web as some sort of read/write tool when there is no such thing as a decent richtextarea just the crappy old textarea.

HTML5? Useless unless it addresses this major hole in the web. It is incredible that browser vendors go off creating all sorts of graphic-card acceleration, SVG, canvas, JS threading ... you name it ... yet HTML still cannot perform the basic tasks of the average craptacular desktop text editor like Wordpad.

Please can someone take this article as a starting point and get a richtextarea tag into HTML5 or 6 as an alternative to textarea?!

Re: Revelation!

We will definitely try to submit our specification to be included in HTML5.  Before we do that, though, we should come up with a decent specification, and that's where you can help a lot!  Please join the mailing list and voice your opinion in the future discussions happening there.  Your feedback is really appreciated!

On the list

I've joined the mailing list, even though I really hate mailing lists as a form of communication :)

Haven't seen any traffic on it yet. Maybe I could start some.

Re: On the list

I've been waiting for more people to sign up.  I think I'll start the first discussion early next week.  Feel free to start any discussion in the interim, though!

Midas vs. SeaMonkey/Thunderbird composer

Is Midas the same code as the HTML editor that's in Thunderbird and SeaMonkey, that I hope will some day be improved by https://bugzilla.mozilla.org/show_bug.cgi?id=477840 ("Backport KompoZer to Composer")?

I think not because Midas seems mostly implemented by nsHTMLDocument.cpp and the fancy table support and such of Thunderbird is in a separate big editor/composer directory, but it's confusing.

I found two informative demos: http://www.mozilla.org/editor/midasdemo/ uses designmode and no contenteditable and creates a simple toolbar that invokes a lot of execCommand; http://html5demos.com/contenteditable has a contenteditable section but still sets designmode, and doesn't use execCommand (maybe because it doesn't do much).

Re: Midas vs. SeaMonkey/Thunderbird composer

Midas is the underlying HTML editor engine.  The contenteditable elements in Mozilla-based applications are based on it.  Thunderbird also uses it for editing messages.  SeaMonkey uses it to build a desktop HTML editor application (KompoZer is a bug-fix release of the stand-alone editor application in SeaMonkey which is called Composer.)
The demos you mentioned are both web demos, and that's what I care about the most, but any work done in this area can also be useful to applications such as Thunderbird, SeaMonkey or KompoZer as well.

It will be really very

It will be really very interesting to see the future web based Html.

Pingback

[...] the original post: Thoughts on the future of web-based HTML editors | Ehsan Akhgari Share and [...]

Pingback

[...] Thoughts on the future of web-based HTML editors | Ehsan Akhgari Share and [...]

Finally, the perfect idea

I am very interested, particularly in re-implementing the contenteditable behaviour in JavaScript. The current implementation causes too many problems ... particularly when text is created in one browser and edited in another.

Re: Finally, the perfect idea

Thanks for your enthusiasm!
Please join the mailing list, as we need to have a lot of voices in the initial stages to make sure that we don't make the same mistakes in another form in the early phases of the project.

Security

Having discovered 11 security-critical memory safety bugs in editor code, I'm thrilled that you're considering tossing out all that C++ and replacing it with JavaScript.

Re: Security

I hear your pain.  I think this is a good direction for us to move towards generally, to minimize the risk of security bugs which are mainly a result of the programming language used to write the code.

Signed Up!

I'm definitely interested in the future of web-based editors and how browsers will support their implementations, thanks for starting up the mailing list. My day job includes a lot of support, and hacking of the current editors for our users as they encounter a lot of the pitfalls you mention. Because of this, I started developing a jQuery based WYSIWYG, CMWysi, nearly a year ago now, that tries to better compensate for the current shortcomings while not slowing down the browser and effecting the user experience.

Hopefully the mailing list picks up and some groundwork can be laid for a more consistent implementation.

Signed Up!

Thanks a lot, Cody!  Your feedback will definitely be invaluable for us, looking forward to collaborate with you all on this issue.

Pingback

[...] the rest here: Thoughts on the future of web-based HTML editors | Ehsan Akhgari tags: clean-white, html, khmer, lists, nothing-new, our-lists, portal, post-content | [...]

Pingback

[...] the original post here: Thoughts on the future of web-based HTML editors | Ehsan Akhgari Posted in Web | Tags: all-used, content-on-our, content-on-the, html, nothing-new, [...]

Pingback

[...] the original post: Thoughts on the future of web-based HTML editors | Ehsan Akhgari Posted in Web | Tags: adding-content, content-on-our, execcommand, post-content, [...]

Pingback

[...] from: Thoughts on the future of web-based HTML editors | Ehsan Akhgari Posted in Web | Tags: adding-content, all-used, content-on-our, content-on-the, execcommand, [...]

Pingback

[...] the original post: Thoughts on the future of web-based HTML editors | Ehsan Akhgari Posted in Web | Tags: adding-content, all-used, content-on-our, content-on-the, execcommand, [...]

I'm interested

I'll be following this with some interest. I once tried (unsuccessfully) to extend Composer's HTML editing capabilities to include MathML. So any redesign which makes it easier to write XHTML - or better yet, allow for scripting to add other XML markup - I'm willing to help out on.

(Able to help out on is another story. The curse of having a day job is the lack of time to do other stuff.)

Re: I'm interested

Thanks for your comment, Alex!  Please make sure that you're subscribed to the list.  You can help a lot even just by providing your insight on the future discussions on the htmlediting-community mailing list.

Standard will take years...

... and meanwhile, when Microsoft is busy implementing it for IE12, Gecko and Webkit browsers would probably come up something smarted, HTML5 based. Bespin is already a step to right direction. One, shard, open, extensible implementation.

Why?

Why should browsers implement HTML editing? Why not just let the page implement it in javascript? Why is a standard required at all?

It seems to me that the "web editor widget" solution is just fine.

Why make anything native? Why

Why make anything native? Why not force web developers to write JS to load images? Why bother implementing the video and audio elements? Why do we need canvas?

HTML needs native support for simple web application basics to improve usability; help the web compete with alternative platforms like Flash and Silverlight; allow blogs comment authors to make more readable contributions; to genuinely open up the browser/web to word processing without requiring the resources of Google.

You may not know but the Google Docs software cost Google a big chunk of money and arguably it's still not as good as a dedicated word processor application. Furthermore Google's spent heaps of resources developing their web toolkit however that is only available to developers doing Java web apps!

Re: Why?

Web browsers are able to handle a number of things which are very hard (or impossible) for web pages to do in JavaScript, such as managing the caret, handling paste commands, fast handling of user input, etc.  Most web editor widgets are actually using an underlying content editable element in order to use those services.  What they usually end up implementing on their own are things like custom commands.  Some others actually bypass the built-in commands in order to make sure that they don't have to handle inconsistencies between different browser implementations.
The web platform is all about providing tools that authors can use to create rich web applications in a seamless way, and rich text editing is an essential part of this tool set.

What do you think of exposing

What do you think of exposing low-level "caret" and "paste" APIs to web pages? Then web library developers really could create editors from scratch, instead of having to meld their own features and constraints with high-level APIs.

Re: What do you think of exposing

I have been thinking about trying not to use any special privileges in the new HTML editor implementation, and only expose a small set of baseline APIs from the platform to make it possible.  I'm not still sure how we should expose this set of low-level APIs in a secure way to web pages.  I think I need to invest more thought into this.