tex_highlight_rules.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * tex_highlight_rules.js
  3. *
  4. * Copyright (C) 2009-11 by RStudio, Inc.
  5. *
  6. * The Initial Developer of the Original Code is
  7. * Ajax.org B.V.
  8. * Portions created by the Initial Developer are Copyright (C) 2010
  9. * the Initial Developer. All Rights Reserved.
  10. *
  11. * This program is licensed to you under the terms of version 3 of the
  12. * GNU Affero General Public License. This program is distributed WITHOUT
  13. * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
  14. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
  15. * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
  16. *
  17. */
  18. define(function(require, exports, module) {
  19. "use strict";
  20. var oop = require("../lib/oop");
  21. var lang = require("../lib/lang");
  22. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  23. var TexHighlightRules = function(textClass) {
  24. if (!textClass)
  25. textClass = "text";
  26. // regexp must not have capturing parentheses. Use (?:) instead.
  27. // regexps are ordered -> the first match is used
  28. this.$rules = {
  29. "start" : [
  30. {
  31. token : "comment",
  32. regex : "%.*$"
  33. }, {
  34. token : textClass, // non-command
  35. regex : "\\\\[$&%#\\{\\}]"
  36. }, {
  37. token : "keyword", // command
  38. 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",
  39. next : "nospell"
  40. }, {
  41. token : "keyword", // command
  42. regex : "\\\\(?:[a-zA-z0-9]+|[^a-zA-z0-9])"
  43. }, {
  44. // Obviously these are neither keywords nor operators, but
  45. // labelling them as such was the easiest way to get them
  46. // to be colored distinctly from regular text
  47. token : "paren.keyword.operator",
  48. regex : "[[({]"
  49. }, {
  50. // Obviously these are neither keywords nor operators, but
  51. // labelling them as such was the easiest way to get them
  52. // to be colored distinctly from regular text
  53. token : "paren.keyword.operator",
  54. regex : "[\\])}]"
  55. }, {
  56. token : textClass,
  57. regex : "\\s+"
  58. }
  59. ],
  60. // This mode is necessary to prevent spell checking, but to keep the
  61. // same syntax highlighting behavior. The list of commands comes from
  62. // Texlipse.
  63. "nospell" : [
  64. {
  65. token : "comment",
  66. regex : "%.*$",
  67. next : "start"
  68. }, {
  69. token : "nospell." + textClass, // non-command
  70. regex : "\\\\[$&%#\\{\\}]"
  71. }, {
  72. token : "keyword", // command
  73. 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"
  74. }, {
  75. token : "keyword", // command
  76. regex : "\\\\(?:[a-zA-z0-9]+|[^a-zA-z0-9])",
  77. next : "start"
  78. }, {
  79. token : "paren.keyword.operator",
  80. regex : "[[({]"
  81. }, {
  82. token : "paren.keyword.operator",
  83. regex : "[\\])]"
  84. }, {
  85. token : "paren.keyword.operator",
  86. regex : "}",
  87. next : "start"
  88. }, {
  89. token : "nospell." + textClass,
  90. regex : "\\s+"
  91. }, {
  92. token : "nospell." + textClass,
  93. regex : "\\w+"
  94. }
  95. ]
  96. };
  97. };
  98. oop.inherits(TexHighlightRules, TextHighlightRules);
  99. exports.TexHighlightRules = TexHighlightRules;
  100. });