mode-tex.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. ace.define("ace/mode/tex_highlight_rules",[], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var lang = require("../lib/lang");
  5. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  6. var TexHighlightRules = function(textClass) {
  7. if (!textClass)
  8. textClass = "text";
  9. this.$rules = {
  10. "start" : [
  11. {
  12. token : "comment",
  13. regex : "%.*$"
  14. }, {
  15. token : textClass, // non-command
  16. regex : "\\\\[$&%#\\{\\}]"
  17. }, {
  18. token : "keyword", // command
  19. regex : "\\\\(?:documentclass|usepackage|newcounter|setcounter|addtocounter|value|arabic|stepcounter|newenvironment|renewenvironment|ref|vref|eqref|pageref|label|cite[a-zA-Z]*|tag|begin|end|bibitem)\\b",
  20. next : "nospell"
  21. }, {
  22. token : "keyword", // command
  23. regex : "\\\\(?:[a-zA-Z0-9]+|[^a-zA-Z0-9])"
  24. }, {
  25. token : "paren.keyword.operator",
  26. regex : "[[({]"
  27. }, {
  28. token : "paren.keyword.operator",
  29. regex : "[\\])}]"
  30. }, {
  31. token : textClass,
  32. regex : "\\s+"
  33. }
  34. ],
  35. "nospell" : [
  36. {
  37. token : "comment",
  38. regex : "%.*$",
  39. next : "start"
  40. }, {
  41. token : "nospell." + textClass, // non-command
  42. regex : "\\\\[$&%#\\{\\}]"
  43. }, {
  44. token : "keyword", // command
  45. regex : "\\\\(?:documentclass|usepackage|newcounter|setcounter|addtocounter|value|arabic|stepcounter|newenvironment|renewenvironment|ref|vref|eqref|pageref|label|cite[a-zA-Z]*|tag|begin|end|bibitem)\\b"
  46. }, {
  47. token : "keyword", // command
  48. regex : "\\\\(?:[a-zA-Z0-9]+|[^a-zA-Z0-9])",
  49. next : "start"
  50. }, {
  51. token : "paren.keyword.operator",
  52. regex : "[[({]"
  53. }, {
  54. token : "paren.keyword.operator",
  55. regex : "[\\])]"
  56. }, {
  57. token : "paren.keyword.operator",
  58. regex : "}",
  59. next : "start"
  60. }, {
  61. token : "nospell." + textClass,
  62. regex : "\\s+"
  63. }, {
  64. token : "nospell." + textClass,
  65. regex : "\\w+"
  66. }
  67. ]
  68. };
  69. };
  70. oop.inherits(TexHighlightRules, TextHighlightRules);
  71. exports.TexHighlightRules = TexHighlightRules;
  72. });
  73. ace.define("ace/mode/matching_brace_outdent",[], function(require, exports, module) {
  74. "use strict";
  75. var Range = require("../range").Range;
  76. var MatchingBraceOutdent = function() {};
  77. (function() {
  78. this.checkOutdent = function(line, input) {
  79. if (! /^\s+$/.test(line))
  80. return false;
  81. return /^\s*\}/.test(input);
  82. };
  83. this.autoOutdent = function(doc, row) {
  84. var line = doc.getLine(row);
  85. var match = line.match(/^(\s*\})/);
  86. if (!match) return 0;
  87. var column = match[1].length;
  88. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  89. if (!openBracePos || openBracePos.row == row) return 0;
  90. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  91. doc.replace(new Range(row, 0, row, column-1), indent);
  92. };
  93. this.$getIndent = function(line) {
  94. return line.match(/^\s*/)[0];
  95. };
  96. }).call(MatchingBraceOutdent.prototype);
  97. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  98. });
  99. ace.define("ace/mode/tex",[], function(require, exports, module) {
  100. "use strict";
  101. var oop = require("../lib/oop");
  102. var TextMode = require("./text").Mode;
  103. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  104. var TexHighlightRules = require("./tex_highlight_rules").TexHighlightRules;
  105. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  106. var Mode = function(suppressHighlighting) {
  107. if (suppressHighlighting)
  108. this.HighlightRules = TextHighlightRules;
  109. else
  110. this.HighlightRules = TexHighlightRules;
  111. this.$outdent = new MatchingBraceOutdent();
  112. this.$behaviour = this.$defaultBehaviour;
  113. };
  114. oop.inherits(Mode, TextMode);
  115. (function() {
  116. this.lineCommentStart = "%";
  117. this.getNextLineIndent = function(state, line, tab) {
  118. return this.$getIndent(line);
  119. };
  120. this.allowAutoInsert = function() {
  121. return false;
  122. };
  123. this.$id = "ace/mode/tex";
  124. }).call(Mode.prototype);
  125. exports.Mode = Mode;
  126. });
  127. (function() {
  128. ace.require(["ace/mode/tex"], function(m) {
  129. if (typeof module == "object" && typeof exports == "object" && module) {
  130. module.exports = m;
  131. }
  132. });
  133. })();