mode-asciidoc.js 14 KB

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