I'd like to syntax highlight more than a dozen small snippets of code and then make them editable with ACE Editor by clicking on them, since I think it would be much faster than setting up the full editor for each. I see there's a simple command for setting up an ACE editor:
<div id="editor">some text</div>
<script src="src/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
window.onload = function() {
var editor = ace.edit("editor");
};
</script>
Is there a simple way to call into the API to just highlight the text without setting up the editor? The ideal API would take in some text and return HTML with tags that could be used for highlighting. I'm aware there are specialized highlighting libraries for JavaScript, but I would like to try using the same highlighter both for text that's being displayed and text that's being edited.
Open Notepad++ once again, go back to the language menu, and at the bottom between "Define your language" and "User-Defined" you should find "choicescript". Select it and and your code should automatically be highlighted.
To get the entered value from the ACE editor, we can use the getValue method. And to set the value of the editor, we can use the setValue method. Then we can write the following JavaScript code to get and set the editor value: const editor = ace.
Editing documents with millions of lines as fast as small docs. Syntax highlighting in 45 languages including JavaScript, Java, C#, C, C++, Clojure, Go, Groovy, JSON, Scala, Ruby, XML, and others. Emacs, Vi key bindings. Support for TextMate themes.
Highlight the word:
var range = new Range(rowStart, columnStart, rowEnd, columnEnd);
var marker = editor.getSession().addMarker(range,"ace_selected_word", "text");
Remove the highlighted word:
editor.getSession().removeMarker(marker);
Highlight the line:
editor.getSession().addMarker(range,"ace_active_line","background");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With