As I understand it, an element with contentEditable="true"
is some kind of WYSIWYG HTML editor. It generates relevant HTML tags corresponding to the command issued.
For example, if one selects text and then presses Ctrl+B, the selected text is placed between <b></b>
tags.
I need to have no style tags in the resulting text. How does one suppress, hijack or control the behavior of those commands?
Other things I could do:
contentEditable
at all but a textarea
instead. But among other things, contentEditable
makes it really easy to highlight the paragraph that is being edited. That's much more difficult to do with a textarea
.Probably the best landing page resource for contentEditable is here:
http://blog.whatwg.org/the-road-to-html-5-contenteditable
Basically, what it boils down to is this: You can not reconfigure the key codes themselves – they always exist, and they're different depending on localizations of browsers.
However, you can intercept the keyboard commands using JavaScript, an example of which can be seen here:
http://www.openjs.com/scripts/events/keyboard_shortcuts/shortcut.js
I've been playing around with contentEditable lately with mixed success. Some things just tend to work better than others, and have mixed results across browser. If all you really want is an editor for contentEditable block elements, try taking a look at aloha editor.