views:

37

answers:

2

Hello, I am using contenteditable attribute for a purpose of my own WYSIWYG editor. Most of the problems I solved myself, however one I can't figure out.

Contenteditable is acting little weird, because my editor generates XHTML code and as soon as I insert this code in contenteditable element, it modifies it to non-XHTML code, e.g.:

<h1>headline</h1><br />some text

modifies to:

<H1>headline</H1><BR>some text

There are more changes made by browser (I am using Google Chrome 7), but I think this example is good enough.

Is there a way how to change behaviour of contenteditable in Chrome, either not to touch the inserted code or to turn on "XHTML mode" ?

A: 

Serving the document with a content-type of application/xhtml+xml should turn on XML mode.

David Dorward
I've tried your advice, however, another problem shows up. Since the document is not 100% XHTML valid, Chrome instead of rendering it, it shows error message about document not beeing valid. Document is not valid, because the editor previously produced not-valid code and it will probably happen in the future too. So I can't risk, that non-valid page will result in error page to show up, users wouldn't appreciate that :-) So do you think there is no other way to turn on contenteditable XHTML mode or turn its modifying behaviour off ?
Frodik
A: 

Webkit is quite crappy with regards to the way that it handles contentEditable, you'll have to write a lot of code just for it.

You can look at the code existing in other editors like CKEditor and TinyMCE to see how nasty it can get.

AlfonsoML
Well, right now I am using PHP for post-processing input from my WYSIWYG editor to fix what contenteditable changes. Most of it are regex replacements, etc.. It works but I am not satisfied with this, I would like the contenteditable element to stop modifying the source code or do it in XHTML-mode.
Frodik