8a6e554a1187e2d6572d1f146f18fa4f.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. ace.define("ace/mode/latex_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module){"use strict";
  2. var oop = require("../lib/oop");
  3. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  4. var LatexHighlightRules = function () {
  5. this.$rules = {
  6. "start": [{
  7. token: "comment",
  8. regex: "%.*$"
  9. }, {
  10. token: ["keyword", "lparen", "variable.parameter", "rparen", "lparen", "storage.type", "rparen"],
  11. regex: "(\\\\(?:documentclass|usepackage|input))(?:(\\[)([^\\]]*)(\\]))?({)([^}]*)(})"
  12. }, {
  13. token: ["keyword", "lparen", "variable.parameter", "rparen"],
  14. regex: "(\\\\(?:label|v?ref|cite(?:[^{]*)))(?:({)([^}]*)(}))?"
  15. }, {
  16. token: ["storage.type", "lparen", "variable.parameter", "rparen"],
  17. regex: "(\\\\begin)({)(verbatim)(})",
  18. next: "verbatim"
  19. }, {
  20. token: ["storage.type", "lparen", "variable.parameter", "rparen"],
  21. regex: "(\\\\begin)({)(lstlisting)(})",
  22. next: "lstlisting"
  23. }, {
  24. token: ["storage.type", "lparen", "variable.parameter", "rparen"],
  25. regex: "(\\\\(?:begin|end))({)([\\w*]*)(})"
  26. }, {
  27. token: "storage.type",
  28. regex: /\\verb\b\*?/,
  29. next: [{
  30. token: ["keyword.operator", "string", "keyword.operator"],
  31. regex: "(.)(.*?)(\\1|$)|",
  32. next: "start"
  33. }]
  34. }, {
  35. token: "storage.type",
  36. regex: "\\\\[a-zA-Z]+"
  37. }, {
  38. token: "lparen",
  39. regex: "[[({]"
  40. }, {
  41. token: "rparen",
  42. regex: "[\\])}]"
  43. }, {
  44. token: "constant.character.escape",
  45. regex: "\\\\[^a-zA-Z]?"
  46. }, {
  47. token: "string",
  48. regex: "\\${1,2}",
  49. next: "equation"
  50. }],
  51. "equation": [{
  52. token: "comment",
  53. regex: "%.*$"
  54. }, {
  55. token: "string",
  56. regex: "\\${1,2}",
  57. next: "start"
  58. }, {
  59. token: "constant.character.escape",
  60. regex: "\\\\(?:[^a-zA-Z]|[a-zA-Z]+)"
  61. }, {
  62. token: "error",
  63. regex: "^\\s*$",
  64. next: "start"
  65. }, {
  66. defaultToken: "string"
  67. }],
  68. "verbatim": [{
  69. token: ["storage.type", "lparen", "variable.parameter", "rparen"],
  70. regex: "(\\\\end)({)(verbatim)(})",
  71. next: "start"
  72. }, {
  73. defaultToken: "text"
  74. }],
  75. "lstlisting": [{
  76. token: ["storage.type", "lparen", "variable.parameter", "rparen"],
  77. regex: "(\\\\end)({)(lstlisting)(})",
  78. next: "start"
  79. }, {
  80. defaultToken: "text"
  81. }]
  82. };
  83. this.normalizeRules();
  84. };
  85. oop.inherits(LatexHighlightRules, TextHighlightRules);
  86. exports.LatexHighlightRules = LatexHighlightRules;
  87. });
  88. ace.define("ace/mode/folding/latex",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode","ace/range","ace/token_iterator"], function(require, exports, module){"use strict";
  89. var oop = require("../../lib/oop");
  90. var BaseFoldMode = require("./fold_mode").FoldMode;
  91. var Range = require("../../range").Range;
  92. var TokenIterator = require("../../token_iterator").TokenIterator;
  93. var keywordLevels = {
  94. "\\subparagraph": 1,
  95. "\\paragraph": 2,
  96. "\\subsubsubsection": 3,
  97. "\\subsubsection": 4,
  98. "\\subsection": 5,
  99. "\\section": 6,
  100. "\\chapter": 7,
  101. "\\part": 8,
  102. "\\begin": 9,
  103. "\\end": 10
  104. };
  105. var FoldMode = exports.FoldMode = function () { };
  106. oop.inherits(FoldMode, BaseFoldMode);
  107. (function () {
  108. this.foldingStartMarker = /^\s*\\(begin)|\s*\\(part|chapter|(?:sub)*(?:section|paragraph))\b|{\s*$/;
  109. this.foldingStopMarker = /^\s*\\(end)\b|^\s*}/;
  110. this.getFoldWidgetRange = function (session, foldStyle, row) {
  111. var line = session.doc.getLine(row);
  112. var match = this.foldingStartMarker.exec(line);
  113. if (match) {
  114. if (match[1])
  115. return this.latexBlock(session, row, match[0].length - 1);
  116. if (match[2])
  117. return this.latexSection(session, row, match[0].length - 1);
  118. return this.openingBracketBlock(session, "{", row, match.index);
  119. }
  120. var match = this.foldingStopMarker.exec(line);
  121. if (match) {
  122. if (match[1])
  123. return this.latexBlock(session, row, match[0].length - 1);
  124. return this.closingBracketBlock(session, "}", row, match.index + match[0].length);
  125. }
  126. };
  127. this.latexBlock = function (session, row, column, returnRange) {
  128. var keywords = {
  129. "\\begin": 1,
  130. "\\end": -1
  131. };
  132. var stream = new TokenIterator(session, row, column);
  133. var token = stream.getCurrentToken();
  134. if (!token || !(token.type == "storage.type" || token.type == "constant.character.escape"))
  135. return;
  136. var val = token.value;
  137. var dir = keywords[val];
  138. var getType = function () {
  139. var token = stream.stepForward();
  140. var type = token.type == "lparen" ? stream.stepForward().value : "";
  141. if (dir === -1) {
  142. stream.stepBackward();
  143. if (type)
  144. stream.stepBackward();
  145. }
  146. return type;
  147. };
  148. var stack = [getType()];
  149. var startColumn = dir === -1 ? stream.getCurrentTokenColumn() : session.getLine(row).length;
  150. var startRow = row;
  151. stream.step = dir === -1 ? stream.stepBackward : stream.stepForward;
  152. while (token = stream.step()) {
  153. if (!token || !(token.type == "storage.type" || token.type == "constant.character.escape"))
  154. continue;
  155. var level = keywords[token.value];
  156. if (!level)
  157. continue;
  158. var type = getType();
  159. if (level === dir)
  160. stack.unshift(type);
  161. else if (stack.shift() !== type || !stack.length)
  162. break;
  163. }
  164. if (stack.length)
  165. return;
  166. if (dir == 1) {
  167. stream.stepBackward();
  168. stream.stepBackward();
  169. }
  170. if (returnRange)
  171. return stream.getCurrentTokenRange();
  172. var row = stream.getCurrentTokenRow();
  173. if (dir === -1)
  174. return new Range(row, session.getLine(row).length, startRow, startColumn);
  175. else
  176. return new Range(startRow, startColumn, row, stream.getCurrentTokenColumn());
  177. };
  178. this.latexSection = function (session, row, column) {
  179. var stream = new TokenIterator(session, row, column);
  180. var token = stream.getCurrentToken();
  181. if (!token || token.type != "storage.type")
  182. return;
  183. var startLevel = keywordLevels[token.value] || 0;
  184. var stackDepth = 0;
  185. var endRow = row;
  186. while (token = stream.stepForward()) {
  187. if (token.type !== "storage.type")
  188. continue;
  189. var level = keywordLevels[token.value] || 0;
  190. if (level >= 9) {
  191. if (!stackDepth)
  192. endRow = stream.getCurrentTokenRow() - 1;
  193. stackDepth += level == 9 ? 1 : -1;
  194. if (stackDepth < 0)
  195. break;
  196. }
  197. else if (level >= startLevel)
  198. break;
  199. }
  200. if (!stackDepth)
  201. endRow = stream.getCurrentTokenRow() - 1;
  202. while (endRow > row && !/\S/.test(session.getLine(endRow)))
  203. endRow--;
  204. return new Range(row, session.getLine(row).length, endRow, session.getLine(endRow).length);
  205. };
  206. }).call(FoldMode.prototype);
  207. });
  208. ace.define("ace/mode/latex",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/latex_highlight_rules","ace/mode/behaviour/cstyle","ace/mode/folding/latex"], function(require, exports, module){"use strict";
  209. var oop = require("../lib/oop");
  210. var TextMode = require("./text").Mode;
  211. var LatexHighlightRules = require("./latex_highlight_rules").LatexHighlightRules;
  212. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  213. var LatexFoldMode = require("./folding/latex").FoldMode;
  214. var Mode = function () {
  215. this.HighlightRules = LatexHighlightRules;
  216. this.foldingRules = new LatexFoldMode();
  217. this.$behaviour = new CstyleBehaviour({ braces: true });
  218. };
  219. oop.inherits(Mode, TextMode);
  220. (function () {
  221. this.type = "text";
  222. this.lineCommentStart = "%";
  223. this.$id = "ace/mode/latex";
  224. this.getMatching = function (session, row, column) {
  225. if (row == undefined)
  226. row = session.selection.lead;
  227. if (typeof row == "object") {
  228. column = row.column;
  229. row = row.row;
  230. }
  231. var startToken = session.getTokenAt(row, column);
  232. if (!startToken)
  233. return;
  234. if (startToken.value == "\\begin" || startToken.value == "\\end") {
  235. return this.foldingRules.latexBlock(session, row, column, true);
  236. }
  237. };
  238. }).call(Mode.prototype);
  239. exports.Mode = Mode;
  240. }); (function() {
  241. ace.require(["ace/mode/latex"], function(m) {
  242. if (typeof module == "object" && typeof exports == "object" && module) {
  243. module.exports = m;
  244. }
  245. });
  246. })();