开发者

Way to highlight code in textarea with jquery?

开发者 https://www.devze.com 2023-01-08 11:59 出处:网络
Is there any good and logical ways to highlight code inside textarea via jQuery? If there is, 开发者_运维技巧please share.You could use CodeMirror http://codemirror.net/

Is there any good and logical ways to highlight code inside textarea via jQuery? If there is, 开发者_运维技巧please share.


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


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.


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


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.


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号