I need to write my own code editor in browser. I found CodeMirror but I don’t understand how to do this. I need simple code.
Can I use textarea or something else? (for example content editable). How to underline, colorize, auto complete the code?
Please, give me some advice. I will be very grateful.
I’ve read a book from O’Reilly, Douglas Crockford, about JS so I’ve some basics.
Check the html behind a code editor example page. Use WebKit’s (Safari/Chrome) “Inspect Element”.
As you can see there is a large div over a textarea that holds individual strings, so the user just gets the “illusion” he is typing in a textarea. The textarea is still there but it is not what you really are seeing.
If you want syntactical coloring you will need lexicographic analysis of the string, which is usually done by a lexer that outputs tokens. These tokens are caught by a process that collects them in individual div’s that have f.i. the same text color. Then that div overlays the textarea.
If you want to go deeper in the code you will also need semantic parsing and a lot of coffee to program all of that.
Good luck, do you know you’re taking on something big? And why would you reinvent this, it’s already been done superbly by others.