mode-rst.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. ace.define("ace/mode/rst_highlight_rules",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/mode/text_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 RSTHighlightRules = function() {
  7. var tokens = {
  8. title: "markup.heading",
  9. list: "markup.heading",
  10. table: "constant",
  11. directive: "keyword.operator",
  12. entity: "string",
  13. link: "markup.underline.list",
  14. bold: "markup.bold",
  15. italic: "markup.italic",
  16. literal: "support.function",
  17. comment: "comment"
  18. };
  19. var startStringPrefix = "(^|\\s|[\"'(<\\[{\\-/:])";
  20. var endStringSuffix = "(?:$|(?=\\s|[\\\\.,;!?\\-/:\"')>\\]}]))";
  21. this.$rules = {
  22. "start": [
  23. {
  24. token : tokens.title,
  25. regex : "(^)([\\=\\-`:\\.'\"~\\^_\\*\\+#])(\\2{2,}\\s*$)"
  26. },
  27. {
  28. token : ["text", tokens.directive, tokens.literal],
  29. regex : "(^\\s*\\.\\. )([^: ]+::)(.*$)",
  30. next : "codeblock"
  31. },
  32. {
  33. token : tokens.directive,
  34. regex : "::$",
  35. next : "codeblock"
  36. },
  37. {
  38. token : [tokens.entity, tokens.link],
  39. regex : "(^\\.\\. _[^:]+:)(.*$)"
  40. },
  41. {
  42. token : [tokens.entity, tokens.link],
  43. regex : "(^__ )(https?://.*$)"
  44. },
  45. {
  46. token : tokens.entity,
  47. regex : "^\\.\\. \\[[^\\]]+\\] "
  48. },
  49. {
  50. token : tokens.comment,
  51. regex : "^\\.\\. .*$",
  52. next : "comment"
  53. },
  54. {
  55. token : tokens.list,
  56. regex : "^\\s*[\\*\\+-] "
  57. },
  58. {
  59. token : tokens.list,
  60. regex : "^\\s*(?:[A-Za-z]|[0-9]+|[ivxlcdmIVXLCDM]+)\\. "
  61. },
  62. {
  63. token : tokens.list,
  64. regex : "^\\s*\\(?(?:[A-Za-z]|[0-9]+|[ivxlcdmIVXLCDM]+)\\) "
  65. },
  66. {
  67. token : tokens.table,
  68. regex : "^={2,}(?: +={2,})+$"
  69. },
  70. {
  71. token : tokens.table,
  72. regex : "^\\+-{2,}(?:\\+-{2,})+\\+$"
  73. },
  74. {
  75. token : tokens.table,
  76. regex : "^\\+={2,}(?:\\+={2,})+\\+$"
  77. },
  78. {
  79. token : ["text", tokens.literal],
  80. regex : startStringPrefix + "(``)(?=\\S)",
  81. next : "code"
  82. },
  83. {
  84. token : ["text", tokens.bold],
  85. regex : startStringPrefix + "(\\*\\*)(?=\\S)",
  86. next : "bold"
  87. },
  88. {
  89. token : ["text", tokens.italic],
  90. regex : startStringPrefix + "(\\*)(?=\\S)",
  91. next : "italic"
  92. },
  93. {
  94. token : tokens.entity,
  95. regex : "\\|[\\w\\-]+?\\|"
  96. },
  97. {
  98. token : tokens.entity,
  99. regex : ":[\\w-:]+:`\\S",
  100. next : "entity"
  101. },
  102. {
  103. token : ["text", tokens.entity],
  104. regex : startStringPrefix + "(_`)(?=\\S)",
  105. next : "entity"
  106. },
  107. {
  108. token : tokens.entity,
  109. regex : "_[A-Za-z0-9\\-]+?"
  110. },
  111. {
  112. token : ["text", tokens.link],
  113. regex : startStringPrefix + "(`)(?=\\S)",
  114. next : "link"
  115. },
  116. {
  117. token : tokens.link,
  118. regex : "[A-Za-z0-9\\-]+?__?"
  119. },
  120. {
  121. token : tokens.link,
  122. regex : "\\[[^\\]]+?\\]_"
  123. },
  124. {
  125. token : tokens.link,
  126. regex : "https?://\\S+"
  127. },
  128. {
  129. token : tokens.table,
  130. regex : "\\|"
  131. }
  132. ],
  133. "codeblock": [
  134. {
  135. token : tokens.literal,
  136. regex : "^ +.+$",
  137. next : "codeblock"
  138. },
  139. {
  140. token : tokens.literal,
  141. regex : '^$',
  142. next: "codeblock"
  143. },
  144. {
  145. token : "empty",
  146. regex : "",
  147. next : "start"
  148. }
  149. ],
  150. "code": [
  151. {
  152. token : tokens.literal,
  153. regex : "\\S``" + endStringSuffix,
  154. next : "start"
  155. },
  156. {
  157. defaultToken: tokens.literal
  158. }
  159. ],
  160. "bold": [
  161. {
  162. token : tokens.bold,
  163. regex : "\\S\\*\\*" + endStringSuffix,
  164. next : "start"
  165. },
  166. {
  167. defaultToken: tokens.bold
  168. }
  169. ],
  170. "italic": [
  171. {
  172. token : tokens.italic,
  173. regex : "\\S\\*" + endStringSuffix,
  174. next : "start"
  175. },
  176. {
  177. defaultToken: tokens.italic
  178. }
  179. ],
  180. "entity": [
  181. {
  182. token : tokens.entity,
  183. regex : "\\S`" + endStringSuffix,
  184. next : "start"
  185. },
  186. {
  187. defaultToken: tokens.entity
  188. }
  189. ],
  190. "link": [
  191. {
  192. token : tokens.link,
  193. regex : "\\S`__?" + endStringSuffix,
  194. next : "start"
  195. },
  196. {
  197. defaultToken: tokens.link
  198. }
  199. ],
  200. "comment": [
  201. {
  202. token : tokens.comment,
  203. regex : "^ +.+$",
  204. next : "comment"
  205. },
  206. {
  207. token : tokens.comment,
  208. regex : '^$',
  209. next: "comment"
  210. },
  211. {
  212. token : "empty",
  213. regex : "",
  214. next : "start"
  215. }
  216. ]
  217. };
  218. };
  219. oop.inherits(RSTHighlightRules, TextHighlightRules);
  220. exports.RSTHighlightRules = RSTHighlightRules;
  221. });
  222. ace.define("ace/mode/rst",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/rst_highlight_rules"], function(require, exports, module) {
  223. "use strict";
  224. var oop = require("../lib/oop");
  225. var TextMode = require("./text").Mode;
  226. var RSTHighlightRules = require("./rst_highlight_rules").RSTHighlightRules;
  227. var Mode = function() {
  228. this.HighlightRules = RSTHighlightRules;
  229. };
  230. oop.inherits(Mode, TextMode);
  231. (function() {
  232. this.type = "text";
  233. this.$id = "ace/mode/rst";
  234. }).call(Mode.prototype);
  235. exports.Mode = Mode;
  236. });