<html lang="en">
<head>
<title>ACE in Action</title>
<style type="text/css" media="screen">
#e1 {
position: absolute;
top: 0;
right: 0;
bottom: 50%;
left: 0;
}
#e2 {
position: absolute;
top: 50%;
right: 0;
bottom: 0;
left: 0;
margin:0
}
</style>
</head>
<body>
<div id="e1">
function foo(items) {
var x = "All this is syntax highlighted";
return x;
}
first second editor
</div>
<pre id="e2">
{
"keyword": "first|items|editor"
}
</pre>
<script src="https://ajaxorg.github.io/ace-builds/src/ace.js"></script>
<script>
define("DynHighlightRules", [], function(require, exports, module) {
"use strict";
var oop = require("ace/lib/oop");
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
var DynHighlightRules = function() {
this.setKeywords = function(kwMap) {
this.keywordRule.onMatch = this.createKeywordMapper(kwMap, "identifier")
}
this.keywordRule = {
regex : "\\w+",
onMatch : function() {return "text"}
}
this.$rules = {
"start" : [
{
token: "string",
start: '"',
end: '"',
next: [{ token : "constant.language.escape.lsl", regex : /\\[tn"\\]/}]
},
this.keywordRule
]
};
this.normalizeRules()
};
oop.inherits(DynHighlightRules, TextHighlightRules);
exports.DynHighlightRules = DynHighlightRules;
});
var editor = ace.edit("e1");
editor.setTheme("ace/theme/solarized_light");
var TextMode = require("ace/mode/text").Mode;
var dynamicMode = new TextMode();
dynamicMode.HighlightRules = require("DynHighlightRules").DynHighlightRules;
editor.session.setMode(dynamicMode);
var editor2 = ace.edit("e2");
editor2.setTheme("ace/theme/solarized_dark");
editor2.session.setMode("ace/mode/json")
editor2.on("input", function() {
dynamicMode.$highlightRules.setKeywords(JSON.parse(editor2.getValue()))
editor.session.bgTokenizer.start(0)
})()
</script>
</body>
</html>
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |