Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Way to highlight code in textarea with jquery?

Is there any good and logical ways to highlight code inside textarea via jQuery? If there is, please share.

like image 467
Martti Laine Avatar asked Jul 21 '10 16:07

Martti Laine


3 Answers

You could use CodeMirror http://codemirror.net/

...a versatile text editor implemented in JavaScript for the browser. It is specialized for editing code, and comes with a number of language modes and addons that implement more advanced editing functionality.

A rich programming API and a CSS theming system are available for customizing CodeMirror to fit your application, and extending it with new functionality...

like image 106
garpo Avatar answered Nov 14 '22 00:11

garpo


No, there isn't. You can apply styles to the entire textarea, but not part of the text in it.

You would need something that works as a replacement for the textarea, here is a list of some.

like image 36
Guffa Avatar answered Nov 14 '22 01:11

Guffa


You can highlight a part of a text with the follow search code:

<script type="text/javascript">
    $(document).ready(function() {
        $("textarea").highlightTextarea({
              words: ["first word","an other word"]
        });
    });
</script>

Find more about highlighting in a textarea on Highlight text into a textarea

like image 1
Raymond van Os Avatar answered Nov 14 '22 02:11

Raymond van Os