For the context of my question (coding the MELT monitor, alpha stage GPLv3) see this & that question.
I'm targeting recent HTML5 browsers only (e.g. Firefox 38 or 42, recent Chrome 47, perhaps the latest Safari or Opera...). So I don't care about IE9 and I don't care about browsers before 2014.
I want to code a syntax-directed editor with a Web interface, so my MELT monitor is a specialized Web server program using libonion
. I don't want to use existing Web WYSIWYG because my model is an abstract syntax tree, not a syntax-colorized sequence of lines (or part of some HTML5 DOM).
I'm hesitating between a canvas-based code, and a DOM-based approach:
Canvas approach (à la https://github.com/danielearwicker/carota ...) pros:
- dealing with everything myself
- no limitations on event, contenteditable,
- ability to mix graphics & text
cons:
- have to draw and layout everything, painful (but doable)
- browser clipboard is very painful (copy & paste):
DOM based approach (à la MCE? CodeMirror?) pros:
- the browser is doing the layout
- the clipboard & cut&paste might be easier
cons:
- contenteditable does not really work (why contenteditable is terrible)
- event handling is messy. Can't figure out what are every possible user actions.
Question:
What is the exact principle behind MCE & CodeMirror and most WYSIWYG web "editors"? Browser input reading is complex... But is having a hidden <textarea>
to catch keyboard event working in practice for recent browsers (limited to post 2014 browsers)? Is there some established practice or reference? (I don't even know what to search on the web).
<iframe>
has been mentioned in a comment, but I am not sure to understand the relation (in particular iframes and events...). What is the role of iframe (e.g. in tinymce, iframe seems apparently central, but I don't understand why and what for).