544cdec50f7d5ee773f1023634bc8c59.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. ace.define("ace/mode/asciidoc_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 AsciidocHighlightRules = function () {
  5. var identifierRe = "[a-zA-Z\u00a1-\uffff]+\\b";
  6. this.$rules = {
  7. "start": [
  8. { token: "empty", regex: /$/ },
  9. { token: "literal", regex: /^\.{4,}\s*$/, next: "listingBlock" },
  10. { token: "literal", regex: /^-{4,}\s*$/, next: "literalBlock" },
  11. { token: "string", regex: /^\+{4,}\s*$/, next: "passthroughBlock" },
  12. { token: "keyword", regex: /^={4,}\s*$/ },
  13. { token: "text", regex: /^\s*$/ },
  14. { token: "empty", regex: "", next: "dissallowDelimitedBlock" }
  15. ],
  16. "dissallowDelimitedBlock": [
  17. { include: "paragraphEnd" },
  18. { token: "comment", regex: '^//.+$' },
  19. { token: "keyword", regex: "^(?:NOTE|TIP|IMPORTANT|WARNING|CAUTION):" },
  20. { include: "listStart" },
  21. { token: "literal", regex: /^\s+.+$/, next: "indentedBlock" },
  22. { token: "empty", regex: "", next: "text" }
  23. ],
  24. "paragraphEnd": [
  25. { token: "doc.comment", regex: /^\/{4,}\s*$/, next: "commentBlock" },
  26. { token: "tableBlock", regex: /^\s*[|!]=+\s*$/, next: "tableBlock" },
  27. { token: "keyword", regex: /^(?:--|''')\s*$/, next: "start" },
  28. { token: "option", regex: /^\[.*\]\s*$/, next: "start" },
  29. { token: "pageBreak", regex: /^>{3,}$/, next: "start" },
  30. { token: "literal", regex: /^\.{4,}\s*$/, next: "listingBlock" },
  31. { token: "titleUnderline", regex: /^(?:={2,}|-{2,}|~{2,}|\^{2,}|\+{2,})\s*$/, next: "start" },
  32. { token: "singleLineTitle", regex: /^={1,5}\s+\S.*$/, next: "start" },
  33. { token: "otherBlock", regex: /^(?:\*{2,}|_{2,})\s*$/, next: "start" },
  34. { token: "optionalTitle", regex: /^\.[^.\s].+$/, next: "start" }
  35. ],
  36. "listStart": [
  37. { token: "keyword", regex: /^\s*(?:\d+\.|[a-zA-Z]\.|[ixvmIXVM]+\)|\*{1,5}|-|\.{1,5})\s/, next: "listText" },
  38. { token: "meta.tag", regex: /^.+(?::{2,4}|;;)(?: |$)/, next: "listText" },
  39. { token: "support.function.list.callout", regex: /^(?:<\d+>|\d+>|>) /, next: "text" },
  40. { token: "keyword", regex: /^\+\s*$/, next: "start" }
  41. ],
  42. "text": [
  43. { token: ["link", "variable.language"], regex: /((?:https?:\/\/|ftp:\/\/|file:\/\/|mailto:|callto:)[^\s\[]+)(\[.*?\])/ },
  44. { token: "link", regex: /(?:https?:\/\/|ftp:\/\/|file:\/\/|mailto:|callto:)[^\s\[]+/ },
  45. { token: "link", regex: /\b[\w\.\/\-]+@[\w\.\/\-]+\b/ },
  46. { include: "macros" },
  47. { include: "paragraphEnd" },
  48. { token: "literal", regex: /\+{3,}/, next: "smallPassthrough" },
  49. { token: "escape", regex: /\((?:C|TM|R)\)|\.{3}|->|<-|=>|<=|&#(?:\d+|x[a-fA-F\d]+);|(?: |^)--(?=\s+\S)/ },
  50. { token: "escape", regex: /\\[_*'`+#]|\\{2}[_*'`+#]{2}/ },
  51. { token: "keyword", regex: /\s\+$/ },
  52. { token: "text", regex: identifierRe },
  53. { token: ["keyword", "string", "keyword"],
  54. regex: /(<<[\w\d\-$]+,)(.*?)(>>|$)/ },
  55. { token: "keyword", regex: /<<[\w\d\-$]+,?|>>/ },
  56. { token: "constant.character", regex: /\({2,3}.*?\){2,3}/ },
  57. { token: "keyword", regex: /\[\[.+?\]\]/ },
  58. { token: "support", regex: /^\[{3}[\w\d =\-]+\]{3}/ },
  59. { include: "quotes" },
  60. { token: "empty", regex: /^\s*$/, next: "start" }
  61. ],
  62. "listText": [
  63. { include: "listStart" },
  64. { include: "text" }
  65. ],
  66. "indentedBlock": [
  67. { token: "literal", regex: /^[\s\w].+$/, next: "indentedBlock" },
  68. { token: "literal", regex: "", next: "start" }
  69. ],
  70. "listingBlock": [
  71. { token: "literal", regex: /^\.{4,}\s*$/, next: "dissallowDelimitedBlock" },
  72. { token: "constant.numeric", regex: '<\\d+>' },
  73. { token: "literal", regex: '[^<]+' },
  74. { token: "literal", regex: '<' }
  75. ],
  76. "literalBlock": [
  77. { token: "literal", regex: /^-{4,}\s*$/, next: "dissallowDelimitedBlock" },
  78. { token: "constant.numeric", regex: '<\\d+>' },
  79. { token: "literal", regex: '[^<]+' },
  80. { token: "literal", regex: '<' }
  81. ],
  82. "passthroughBlock": [
  83. { token: "literal", regex: /^\+{4,}\s*$/, next: "dissallowDelimitedBlock" },
  84. { token: "literal", regex: identifierRe + "|\\d+" },
  85. { include: "macros" },
  86. { token: "literal", regex: "." }
  87. ],
  88. "smallPassthrough": [
  89. { token: "literal", regex: /[+]{3,}/, next: "dissallowDelimitedBlock" },
  90. { token: "literal", regex: /^\s*$/, next: "dissallowDelimitedBlock" },
  91. { token: "literal", regex: identifierRe + "|\\d+" },
  92. { include: "macros" }
  93. ],
  94. "commentBlock": [
  95. { token: "doc.comment", regex: /^\/{4,}\s*$/, next: "dissallowDelimitedBlock" },
  96. { token: "doc.comment", regex: '^.*$' }
  97. ],
  98. "tableBlock": [
  99. { token: "tableBlock", regex: /^\s*\|={3,}\s*$/, next: "dissallowDelimitedBlock" },
  100. { token: "tableBlock", regex: /^\s*!={3,}\s*$/, next: "innerTableBlock" },
  101. { token: "tableBlock", regex: /\|/ },
  102. { include: "text", noEscape: true }
  103. ],
  104. "innerTableBlock": [
  105. { token: "tableBlock", regex: /^\s*!={3,}\s*$/, next: "tableBlock" },
  106. { token: "tableBlock", regex: /^\s*|={3,}\s*$/, next: "dissallowDelimitedBlock" },
  107. { token: "tableBlock", regex: /!/ }
  108. ],
  109. "macros": [
  110. { token: "macro", regex: /{[\w\-$]+}/ },
  111. { token: ["text", "string", "text", "constant.character", "text"], regex: /({)([\w\-$]+)(:)?(.+)?(})/ },
  112. { token: ["text", "markup.list.macro", "keyword", "string"], regex: /(\w+)(footnote(?:ref)?::?)([^\s\[]+)?(\[.*?\])?/ },
  113. { token: ["markup.list.macro", "keyword", "string"], regex: /([a-zA-Z\-][\w\.\/\-]*::?)([^\s\[]+)(\[.*?\])?/ },
  114. { token: ["markup.list.macro", "keyword"], regex: /([a-zA-Z\-][\w\.\/\-]+::?)(\[.*?\])/ },
  115. { token: "keyword", regex: /^:.+?:(?= |$)/ }
  116. ],
  117. "quotes": [
  118. { token: "string.italic", regex: /__[^_\s].*?__/ },
  119. { token: "string.italic", regex: quoteRule("_") },
  120. { token: "keyword.bold", regex: /\*\*[^*\s].*?\*\*/ },
  121. { token: "keyword.bold", regex: quoteRule("\\*") },
  122. { token: "literal", regex: quoteRule("\\+") },
  123. { token: "literal", regex: /\+\+[^+\s].*?\+\+/ },
  124. { token: "literal", regex: /\$\$.+?\$\$/ },
  125. { token: "literal", regex: quoteRule("`") },
  126. { token: "keyword", regex: quoteRule("^") },
  127. { token: "keyword", regex: quoteRule("~") },
  128. { token: "keyword", regex: /##?/ },
  129. { token: "keyword", regex: /(?:\B|^)``|\b''/ }
  130. ]
  131. };
  132. function quoteRule(ch) {
  133. var prefix = /\w/.test(ch) ? "\\b" : "(?:\\B|^)";
  134. return prefix + ch + "[^" + ch + "].*?" + ch + "(?![\\w*])";
  135. }
  136. var tokenMap = {
  137. macro: "constant.character",
  138. tableBlock: "doc.comment",
  139. titleUnderline: "markup.heading",
  140. singleLineTitle: "markup.heading",
  141. pageBreak: "string",
  142. option: "string.regexp",
  143. otherBlock: "markup.list",
  144. literal: "support.function",
  145. optionalTitle: "constant.numeric",
  146. escape: "constant.language.escape",
  147. link: "markup.underline.list"
  148. };
  149. for (var state in this.$rules) {
  150. var stateRules = this.$rules[state];
  151. for (var i = stateRules.length; i--;) {
  152. var rule = stateRules[i];
  153. if (rule.include || typeof rule == "string") {
  154. var args = [i, 1].concat(this.$rules[rule.include || rule]);
  155. if (rule.noEscape) {
  156. args = args.filter(function (x) {
  157. return !x.next;
  158. });
  159. }
  160. stateRules.splice.apply(stateRules, args);
  161. }
  162. else if (rule.token in tokenMap) {
  163. rule.token = tokenMap[rule.token];
  164. }
  165. }
  166. }
  167. };
  168. oop.inherits(AsciidocHighlightRules, TextHighlightRules);
  169. exports.AsciidocHighlightRules = AsciidocHighlightRules;
  170. });
  171. ace.define("ace/mode/folding/asciidoc",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode","ace/range"], function(require, exports, module){"use strict";
  172. var oop = require("../../lib/oop");
  173. var BaseFoldMode = require("./fold_mode").FoldMode;
  174. var Range = require("../../range").Range;
  175. var FoldMode = exports.FoldMode = function () { };
  176. oop.inherits(FoldMode, BaseFoldMode);
  177. (function () {
  178. this.foldingStartMarker = /^(?:\|={10,}|[\.\/=\-~^+]{4,}\s*$|={1,5} )/;
  179. this.singleLineHeadingRe = /^={1,5}(?=\s+\S)/;
  180. this.getFoldWidget = function (session, foldStyle, row) {
  181. var line = session.getLine(row);
  182. if (!this.foldingStartMarker.test(line))
  183. return "";
  184. if (line[0] == "=") {
  185. if (this.singleLineHeadingRe.test(line))
  186. return "start";
  187. if (session.getLine(row - 1).length != session.getLine(row).length)
  188. return "";
  189. return "start";
  190. }
  191. if (session.bgTokenizer.getState(row) == "dissallowDelimitedBlock")
  192. return "end";
  193. return "start";
  194. };
  195. this.getFoldWidgetRange = function (session, foldStyle, row) {
  196. var line = session.getLine(row);
  197. var startColumn = line.length;
  198. var maxRow = session.getLength();
  199. var startRow = row;
  200. var endRow = row;
  201. if (!line.match(this.foldingStartMarker))
  202. return;
  203. var token;
  204. function getTokenType(row) {
  205. token = session.getTokens(row)[0];
  206. return token && token.type;
  207. }
  208. var levels = ["=", "-", "~", "^", "+"];
  209. var heading = "markup.heading";
  210. var singleLineHeadingRe = this.singleLineHeadingRe;
  211. function getLevel() {
  212. var match = token.value.match(singleLineHeadingRe);
  213. if (match)
  214. return match[0].length;
  215. var level = levels.indexOf(token.value[0]) + 1;
  216. if (level == 1) {
  217. if (session.getLine(row - 1).length != session.getLine(row).length)
  218. return Infinity;
  219. }
  220. return level;
  221. }
  222. if (getTokenType(row) == heading) {
  223. var startHeadingLevel = getLevel();
  224. while (++row < maxRow) {
  225. if (getTokenType(row) != heading)
  226. continue;
  227. var level = getLevel();
  228. if (level <= startHeadingLevel)
  229. break;
  230. }
  231. var isSingleLineHeading = token && token.value.match(this.singleLineHeadingRe);
  232. endRow = isSingleLineHeading ? row - 1 : row - 2;
  233. if (endRow > startRow) {
  234. while (endRow > startRow && (!getTokenType(endRow) || token.value[0] == "["))
  235. endRow--;
  236. }
  237. if (endRow > startRow) {
  238. var endColumn = session.getLine(endRow).length;
  239. return new Range(startRow, startColumn, endRow, endColumn);
  240. }
  241. }
  242. else {
  243. var state = session.bgTokenizer.getState(row);
  244. if (state == "dissallowDelimitedBlock") {
  245. while (row-- > 0) {
  246. if (session.bgTokenizer.getState(row).lastIndexOf("Block") == -1)
  247. break;
  248. }
  249. endRow = row + 1;
  250. if (endRow < startRow) {
  251. var endColumn = session.getLine(row).length;
  252. return new Range(endRow, 5, startRow, startColumn - 5);
  253. }
  254. }
  255. else {
  256. while (++row < maxRow) {
  257. if (session.bgTokenizer.getState(row) == "dissallowDelimitedBlock")
  258. break;
  259. }
  260. endRow = row;
  261. if (endRow > startRow) {
  262. var endColumn = session.getLine(row).length;
  263. return new Range(startRow, 5, endRow, endColumn - 5);
  264. }
  265. }
  266. }
  267. };
  268. }).call(FoldMode.prototype);
  269. });
  270. ace.define("ace/mode/asciidoc",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/asciidoc_highlight_rules","ace/mode/folding/asciidoc"], function(require, exports, module){"use strict";
  271. var oop = require("../lib/oop");
  272. var TextMode = require("./text").Mode;
  273. var AsciidocHighlightRules = require("./asciidoc_highlight_rules").AsciidocHighlightRules;
  274. var AsciidocFoldMode = require("./folding/asciidoc").FoldMode;
  275. var Mode = function () {
  276. this.HighlightRules = AsciidocHighlightRules;
  277. this.foldingRules = new AsciidocFoldMode();
  278. };
  279. oop.inherits(Mode, TextMode);
  280. (function () {
  281. this.type = "text";
  282. this.getNextLineIndent = function (state, line, tab) {
  283. if (state == "listblock") {
  284. var match = /^((?:.+)?)([-+*][ ]+)/.exec(line);
  285. if (match) {
  286. return new Array(match[1].length + 1).join(" ") + match[2];
  287. }
  288. else {
  289. return "";
  290. }
  291. }
  292. else {
  293. return this.$getIndent(line);
  294. }
  295. };
  296. this.$id = "ace/mode/asciidoc";
  297. }).call(Mode.prototype);
  298. exports.Mode = Mode;
  299. }); (function() {
  300. ace.require(["ace/mode/asciidoc"], function(m) {
  301. if (typeof module == "object" && typeof exports == "object" && module) {
  302. module.exports = m;
  303. }
  304. });
  305. })();