Martti Laine
Martti Laine

Reputation: 12995

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.

Upvotes: 12

Views: 14834

Answers (5)

user5781320
user5781320

Reputation:

i was looking too for a live syntax coloring best solution so i found a working , ancient software(2007) that is older than textarea(witch is working too) :

1.Codepress

https://sourceforge.net/projects/codepress/files/

then in index.html the line 117 replaced with

<textarea spellcheck="false" id="codepress2" class="codepress javascript linenumbers-off" style="width:700px;height:200px;" wrap="off">

will had live syntax coloring like notepad++ / editplus in web meaning small code could be "repainted" , "reforget" to this age ...

it's up to you ...

2.MIT LDT =minimalist syntax coloring
https://github.com/kueblc/LDT

..all tests i did are in a custom apache php 8.1 mariadb custom server (remote buggy/spies free) so these two works fine!

so the answer is : in case you open to recoding something these can be recoded in jquery with the author accept (check the licenses for more info)

Upvotes: 0

elo80ka
elo80ka

Reputation: 15885

If by code, you mean SQL, PHP etc., take a look at Codepress. It's a real-time, syntax highlighting editor, written in Javascript.

Edit:

If you'd prefer a more modern and actively-maintained alternative, you should look at Ace.

Upvotes: 1

garpo
garpo

Reputation: 221

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...

Upvotes: 22

Raymond van Os
Raymond van Os

Reputation: 191

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

Upvotes: 1

Guffa
Guffa

Reputation: 700860

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.

Upvotes: 4

Related Questions