| 1 |
ace.define("ace/ext/static-css",["require","exports","module"], function(require, exports, module){module.exports = ".ace_static_highlight {\n font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'Source Code Pro', 'source-code-pro', 'Droid Sans Mono', monospace;\n font-size: 12px;\n white-space: pre-wrap\n}\n\n.ace_static_highlight .ace_gutter {\n width: 2em;\n text-align: right;\n padding: 0 3px 0 0;\n margin-right: 3px;\n contain: none;\n}\n\n.ace_static_highlight.ace_show_gutter .ace_line {\n padding-left: 2.6em;\n}\n\n.ace_static_highlight .ace_line { position: relative; }\n\n.ace_static_highlight .ace_gutter-cell {\n -moz-user-select: -moz-none;\n -khtml-user-select: none;\n -webkit-user-select: none;\n user-select: none;\n top: 0;\n bottom: 0;\n left: 0;\n position: absolute;\n}\n\n\n.ace_static_highlight .ace_gutter-cell:before {\n content: counter(ace_line, decimal);\n counter-increment: ace_line;\n}\n.ace_static_highlight {\n counter-reset: ace_line;\n}\n"; |
| 2 |
|
| 3 |
}); |
| 4 |
|
| 5 |
ace.define("ace/ext/static_highlight",["require","exports","module","ace/edit_session","ace/layer/text","ace/ext/static-css","ace/config","ace/lib/dom","ace/lib/lang"], function(require, exports, module){"use strict"; |
| 6 |
var EditSession = require("../edit_session").EditSession; |
| 7 |
var TextLayer = require("../layer/text").Text; |
| 8 |
var baseStyles = require("./static-css"); |
| 9 |
var config = require("../config"); |
| 10 |
var dom = require("../lib/dom"); |
| 11 |
var escapeHTML = require("../lib/lang").escapeHTML; |
| 12 |
var Element = (function () { |
| 13 |
function Element(type) { this.className; |
| 14 |
this.type = type; |
| 15 |
this.style = {}; |
| 16 |
this.textContent = ""; |
| 17 |
} |
| 18 |
Element.prototype.cloneNode = function () { |
| 19 |
return this; |
| 20 |
}; |
| 21 |
Element.prototype.appendChild = function (child) { |
| 22 |
this.textContent += child.toString(); |
| 23 |
}; |
| 24 |
Element.prototype.toString = function () { |
| 25 |
var stringBuilder = []; |
| 26 |
if (this.type != "fragment") { |
| 27 |
stringBuilder.push("<", this.type); |
| 28 |
if (this.className) |
| 29 |
stringBuilder.push(" class='", this.className, "'"); |
| 30 |
var styleStr = []; |
| 31 |
for (var key in this.style) { |
| 32 |
styleStr.push(key, ":", this.style[key]); |
| 33 |
} |
| 34 |
if (styleStr.length) |
| 35 |
stringBuilder.push(" style='", styleStr.join(""), "'"); |
| 36 |
stringBuilder.push(">"); |
| 37 |
} |
| 38 |
if (this.textContent) { |
| 39 |
stringBuilder.push(this.textContent); |
| 40 |
} |
| 41 |
if (this.type != "fragment") { |
| 42 |
stringBuilder.push("</", this.type, ">"); |
| 43 |
} |
| 44 |
return stringBuilder.join(""); |
| 45 |
}; |
| 46 |
return Element; |
| 47 |
}()); |
| 48 |
var simpleDom = { |
| 49 |
createTextNode: function ( textContent, element) { |
| 50 |
return escapeHTML(textContent); |
| 51 |
}, |
| 52 |
createElement: function ( type) { |
| 53 |
return new Element(type); |
| 54 |
}, |
| 55 |
createFragment: function () { |
| 56 |
return new Element("fragment"); |
| 57 |
} |
| 58 |
}; |
| 59 |
var SimpleTextLayer = function () { |
| 60 |
this.config = {}; |
| 61 |
this.dom = simpleDom; |
| 62 |
}; |
| 63 |
SimpleTextLayer.prototype = TextLayer.prototype; |
| 64 |
var highlight = function (el, opts, callback) { |
| 65 |
var m = el.className.match(/lang-(\w+)/); |
| 66 |
var mode = opts.mode || m && ("ace/mode/" + m[1]); |
| 67 |
if (!mode) |
| 68 |
return false; |
| 69 |
var theme = opts.theme || "ace/theme/textmate"; |
| 70 |
var data = ""; |
| 71 |
var nodes = []; |
| 72 |
if (el.firstElementChild) { |
| 73 |
var textLen = 0; |
| 74 |
for (var i = 0; i < el.childNodes.length; i++) { |
| 75 |
var ch = el.childNodes[i]; |
| 76 |
if (ch.nodeType == 3) { |
| 77 |
textLen += ch.data.length; |
| 78 |
data += ch.data; |
| 79 |
} |
| 80 |
else { |
| 81 |
nodes.push(textLen, ch); |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
else { |
| 86 |
data = el.textContent; |
| 87 |
if (opts.trim) |
| 88 |
data = data.trim(); |
| 89 |
} |
| 90 |
highlight.render(data, mode, theme, opts.firstLineNumber, !opts.showGutter, function (highlighted) { |
| 91 |
dom.importCssString(highlighted.css, "ace_highlight", true); |
| 92 |
el.innerHTML = highlighted.html; |
| 93 |
var container = el.firstChild.firstChild; |
| 94 |
for (var i = 0; i < nodes.length; i += 2) { |
| 95 |
var pos = highlighted.session.doc.indexToPosition(nodes[i]); |
| 96 |
var node = nodes[i + 1]; |
| 97 |
var lineEl = container.children[pos.row]; |
| 98 |
lineEl && lineEl.appendChild(node); |
| 99 |
} |
| 100 |
callback && callback(); |
| 101 |
}); |
| 102 |
}; |
| 103 |
highlight.render = function (input, mode, theme, lineStart, disableGutter, callback) { |
| 104 |
var waiting = 1; |
| 105 |
var modeCache = EditSession.prototype.$modes; |
| 106 |
if (typeof theme == "string") { |
| 107 |
waiting++; |
| 108 |
config.loadModule(['theme', theme], function (m) { |
| 109 |
theme = m; |
| 110 |
--waiting || done(); |
| 111 |
}); |
| 112 |
} |
| 113 |
var modeOptions; |
| 114 |
if (mode && typeof mode === "object" && !mode.getTokenizer) { |
| 115 |
modeOptions = mode; |
| 116 |
mode = modeOptions.path; |
| 117 |
} |
| 118 |
if (typeof mode == "string") { |
| 119 |
waiting++; |
| 120 |
config.loadModule(['mode', mode], function (m) { |
| 121 |
if (!modeCache[ (mode)] || modeOptions) |
| 122 |
modeCache[ (mode)] = new m.Mode(modeOptions); |
| 123 |
mode = modeCache[ (mode)]; |
| 124 |
--waiting || done(); |
| 125 |
}); |
| 126 |
} |
| 127 |
function done() { |
| 128 |
var result = highlight.renderSync(input, mode, theme, lineStart, disableGutter); |
| 129 |
return callback ? callback(result) : result; |
| 130 |
} |
| 131 |
return --waiting || done(); |
| 132 |
}; |
| 133 |
highlight.renderSync = function (input, mode, theme, lineStart, disableGutter) { |
| 134 |
lineStart = parseInt(lineStart || 1, 10); |
| 135 |
var session = new EditSession(""); |
| 136 |
session.setUseWorker(false); |
| 137 |
session.setMode(mode); |
| 138 |
var textLayer = new SimpleTextLayer(); |
| 139 |
textLayer.setSession(session); |
| 140 |
Object.keys(textLayer.$tabStrings).forEach(function (k) { |
| 141 |
if (typeof textLayer.$tabStrings[k] == "string") { |
| 142 |
var el = simpleDom.createFragment(); |
| 143 |
el.textContent = textLayer.$tabStrings[k]; |
| 144 |
textLayer.$tabStrings[k] = el; |
| 145 |
} |
| 146 |
}); |
| 147 |
session.setValue(input); |
| 148 |
var length = session.getLength(); |
| 149 |
var outerEl = simpleDom.createElement("div"); |
| 150 |
outerEl.className = theme.cssClass; |
| 151 |
var innerEl = simpleDom.createElement("div"); |
| 152 |
innerEl.className = "ace_static_highlight" + (disableGutter ? "" : " ace_show_gutter"); |
| 153 |
innerEl.style["counter-reset"] = "ace_line " + (lineStart - 1); |
| 154 |
for (var ix = 0; ix < length; ix++) { |
| 155 |
var lineEl = simpleDom.createElement("div"); |
| 156 |
lineEl.className = "ace_line"; |
| 157 |
if (!disableGutter) { |
| 158 |
var gutterEl = simpleDom.createElement("span"); |
| 159 |
gutterEl.className = "ace_gutter ace_gutter-cell"; |
| 160 |
gutterEl.textContent = ""; |
| 161 |
lineEl.appendChild(gutterEl); |
| 162 |
} |
| 163 |
textLayer.$renderLine(lineEl, ix, false); |
| 164 |
lineEl.textContent += "\n"; |
| 165 |
innerEl.appendChild(lineEl); |
| 166 |
} |
| 167 |
outerEl.appendChild(innerEl); |
| 168 |
return { |
| 169 |
css: baseStyles + theme.cssText, |
| 170 |
html: outerEl.toString(), |
| 171 |
session: session |
| 172 |
}; |
| 173 |
}; |
| 174 |
module.exports = highlight; |
| 175 |
module.exports.highlight = highlight; |
| 176 |
|
| 177 |
}); (function() { |
| 178 |
ace.require(["ace/ext/static_highlight"], function(m) { |
| 179 |
if (typeof module == "object" && typeof exports == "object" && module) { |
| 180 |
module.exports = m; |
| 181 |
} |
| 182 |
}); |
| 183 |
})(); |
| 184 |
|