Reputation: 12995
Is there any good and logical ways to highlight code inside textarea via jQuery? If there is, please share.
Upvotes: 12
Views: 14834
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
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
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
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