573b79a51fa9a0e40000dd478d13f4d7.js 7.5 KB

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