How to preformat inside textarea

I was wondering if it is possible to pre-format the text that is inside the text box. Right now I have textarea code that I want to add syntax highlighting as well as add linenumbers, so I'm trying to wrap text inside a pre tag. Is this right or should I do something completely different?

<textarea id="conversation" class="codebox" style="font-family:courier;">
<pre class="brush: js;">//  Start typing...</pre>
</textarea>
+5
source share
3 answers

textareacannot display content as you want, they only display text. I would suggest an editor in the browser. Good CodeMirror , which is pretty easy to use:

HTML

<textarea id="code" name="code">
// Demo code (the actual new parser character stream implementation)

function StringStream(string) {
  this.pos = 0;
  this.string = string;
}
...
</textarea>

Javascript

var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    matchBrackets: true
});

And CodeMirror inserts an editable block with this content into a new editor.

. Wikipedia Javascript.

+3

textarea , , , cols. , wrap=off.

textarea . , textarea .

0

Having a Pre tag contains a text box in Chrome

0
source

All Articles