1
/* ***** BEGIN LICENSE BLOCK *****
2
* Distributed under the BSD license:
4
* Copyright (c) 2010, Ajax.org B.V.
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
9
* * Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* * Neither the name of Ajax.org B.V. nor the
15
* names of its contributors may be used to endorse or promote products
16
* derived from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
22
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
* ***** END LICENSE BLOCK ***** */
31
define('ace/mode/asciidoc', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/asciidoc_highlight_rules', 'ace/mode/folding/asciidoc'], function(require, exports, module) {
34
var oop = require("../lib/oop");
35
var TextMode = require("./text").Mode;
36
var Tokenizer = require("../tokenizer").Tokenizer;
37
var AsciidocHighlightRules = require("./asciidoc_highlight_rules").AsciidocHighlightRules;
38
var AsciidocFoldMode = require("./folding/asciidoc").FoldMode;
40
var Mode = function() {
41
var highlighter = new AsciidocHighlightRules();
43
this.$tokenizer = new Tokenizer(highlighter.getRules());
44
this.foldingRules = new AsciidocFoldMode();
46
oop.inherits(Mode, TextMode);
49
this.getNextLineIndent = function(state, line, tab) {
50
if (state == "listblock") {
51
var match = /^((?:.+)?)([-+*][ ]+)/.exec(line);
53
return new Array(match[1].length + 1).join(" ") + match[2];
58
return this.$getIndent(line);
61
}).call(Mode.prototype);
66
define('ace/mode/asciidoc_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
69
var oop = require("../lib/oop");
70
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
72
var AsciidocHighlightRules = function() {
73
var identifierRe = "[a-zA-Z\u00a1-\uffff]+\\b";
77
{token: "empty", regex: /$/},
78
{token: "literal", regex: /^\.{4,}\s*$/, next: "listingBlock"},
79
{token: "literal", regex: /^-{4,}\s*$/, next: "literalBlock"},
80
{token: "string", regex: /^\+{4,}\s*$/, next: "passthroughBlock"},
81
{token: "keyword", regex: /^={4,}\s*$/},
82
{token: "text", regex: /^\s*$/},
83
{token: "empty", regex: "", next: "dissallowDelimitedBlock"}
86
"dissallowDelimitedBlock": [
87
{include: "paragraphEnd"},
88
{token: "comment", regex: '^//.+$'},
89
{token: "keyword", regex: "^(?:NOTE|TIP|IMPORTANT|WARNING|CAUTION):"},
91
{include: "listStart"},
92
{token: "literal", regex: /^\s+.+$/, next: "indentedBlock"},
93
{token: "empty", regex: "", next: "text"}
97
{token: "doc.comment", regex: /^\/{4,}\s*$/, next: "commentBlock"},
98
{token: "tableBlock", regex: /^\s*[|!]=+\s*$/, next: "tableBlock"},
99
{token: "keyword", regex: /^(?:--|''')\s*$/, next: "start"},
100
{token: "option", regex: /^\[.*\]\s*$/, next: "start"},
101
{token: "pageBreak", regex: /^>{3,}$/, next: "start"},
102
{token: "literal", regex: /^\.{4,}\s*$/, next: "listingBlock"},
103
{token: "titleUnderline", regex: /^(?:={2,}|-{2,}|~{2,}|\^{2,}|\+{2,})\s*$/, next: "start"},
104
{token: "singleLineTitle", regex: /^={1,5}\s+\S.*$/, next: "start"},
106
{token: "otherBlock", regex: /^(?:\*{2,}|_{2,})\s*$/, next: "start"},
107
{token: "optionalTitle", regex: /^\.[^.\s].+$/, next: "start"}
111
{token: "keyword", regex: /^\s*(?:\d+\.|[a-zA-Z]\.|[ixvmIXVM]+\)|\*{1,5}|-|\.{1,5})\s/, next: "listText"},
112
{token: "meta.tag", regex: /^.+(?::{2,4}|;;)(?: |$)/, next: "listText"},
113
{token: "support.function.list.callout", regex: /^(?:<\d+>|\d+>|>) /, next: "text"},
114
{token: "keyword", regex: /^\+\s*$/, next: "start"}
118
{token: ["link", "variable.language"], regex: /((?:https?:\/\/|ftp:\/\/|file:\/\/|mailto:|callto:)[^\s\[]+)(\[.*?\])/},
119
{token: "link", regex: /(?:https?:\/\/|ftp:\/\/|file:\/\/|mailto:|callto:)[^\s\[]+/},
120
{token: "link", regex: /\b[\w\.\/\-]+@[\w\.\/\-]+\b/},
122
{include: "paragraphEnd"},
123
{token: "literal", regex:/\+{3,}/, next:"smallPassthrough"},
124
{token: "escape", regex: /\((?:C|TM|R)\)|\.{3}|->|<-|=>|<=|&#(?:\d+|x[a-fA-F\d]+);|(?: |^)--(?=\s+\S)/},
125
{token: "escape", regex: /\\[_*'`+#]|\\{2}[_*'`+#]{2}/},
126
{token: "keyword", regex: /\s\+$/},
127
{token: "text", regex: identifierRe},
128
{token: ["keyword", "string", "keyword"],
129
regex: /(<<[\w\d\-$]+,)(.*?)(>>|$)/, merge: true},
130
{token: "keyword", regex: /<<[\w\d\-$]+,?|>>/, merge: true},
131
{token: "constant.character", regex: /\({2,3}.*?\){2,3}/, merge: true},
132
{token: "keyword", regex: /\[\[.+?\]\]/},
133
{token: "support", regex: /^\[{3}[\w\d =\-]+\]{3}/},
136
{token: "empty", regex: /^\s*$/, next: "start"}
140
{include: "listStart"},
145
{token: "literal", regex: /^[\s\w].+$/, next: "indentedBlock"},
146
{token: "literal", regex: "", next: "start"}
150
{token: "literal", regex: /^\.{4,}\s*$/, next: "dissallowDelimitedBlock"},
151
{token: "constant.numeric", regex: '<\\d+>'},
152
{token: "literal", regex: '[^<]+', merge: true},
153
{token: "literal", regex: '<', merge: true}
156
{token: "literal", regex: /^-{4,}\s*$/, next: "dissallowDelimitedBlock"},
157
{token: "constant.numeric", regex: '<\\d+>'},
158
{token: "literal", regex: '[^<]+', merge: true},
159
{token: "literal", regex: '<', merge: true}
161
"passthroughBlock": [
162
{token: "literal", regex: /^\+{4,}\s*$/, next: "dissallowDelimitedBlock"},
163
{token: "literal", regex: identifierRe + "|\\d+", merge: true},
165
{token: "literal", regex: ".", merge: true}
168
"smallPassthrough": [
169
{token: "literal", regex: /[+]{3,}/, next: "dissallowDelimitedBlock"},
170
{token: "literal", regex: /^\s*$/, next: "dissallowDelimitedBlock", merge: true},
171
{token: "literal", regex: identifierRe + "|\\d+", merge: true},
176
{token: "doc.comment", regex: /^\/{4,}\s*$/, next: "dissallowDelimitedBlock"},
177
{token: "doc.comment", regex: '^.*$'}
180
{token: "tableBlock", regex: /^\s*\|={3,}\s*$/, next: "dissallowDelimitedBlock"},
181
{token: "tableBlock", regex: /^\s*!={3,}\s*$/, next: "innerTableBlock"},
182
{token: "tableBlock", regex: /\|/},
183
{include: "text", noEscape: true}
186
{token: "tableBlock", regex: /^\s*!={3,}\s*$/, next: "tableBlock"},
187
{token: "tableBlock", regex: /^\s*|={3,}\s*$/, next: "dissallowDelimitedBlock"},
188
{token: "tableBlock", regex: /\!/}
191
{token: "macro", regex: /{[\w\-$]+}/},
192
{token: ["text", "string", "text", "constant.character", "text"], regex: /({)([\w\-$]+)(:)?(.+)?(})/},
193
{token: ["text", "markup.list.macro", "keyword", "string"], regex: /(\w+)(footnote(?:ref)?::?)([^\s\[]+)?(\[.*?\])?/},
194
{token: ["markup.list.macro", "keyword", "string"], regex: /([a-zA-Z\-][\w\.\/\-]*::?)([^\s\[]+)(\[.*?\])?/},
195
{token: ["markup.list.macro", "keyword"], regex: /([a-zA-Z\-][\w\.\/\-]+::?)(\[.*?\])/},
196
{token: "keyword", regex: /^:.+?:(?= |$)/}
200
{token: "string.italic", regex: /__[^_\s].*?__/},
201
{token: "string.italic", regex: quoteRule("_")},
203
{token: "keyword.bold", regex: /\*\*[^*\s].*?\*\*/},
204
{token: "keyword.bold", regex: quoteRule("\\*")},
206
{token: "literal", regex: quoteRule("\\+")},
207
{token: "literal", regex: /\+\+[^+\s].*?\+\+/},
208
{token: "literal", regex: /\$\$.+?\$\$/},
209
{token: "literal", regex: quoteRule("`")},
211
{token: "keyword", regex: quoteRule("^")},
212
{token: "keyword", regex: quoteRule("~")},
213
{token: "keyword", regex: /##?/},
214
{token: "keyword", regex: /(?:\B|^)``|\b''/}
219
function quoteRule(ch) {
220
var prefix = /\w/.test(ch) ? "\\b" : "(?:\\B|^)";
221
return prefix + ch + "[^" + ch + "].*?" + ch + "(?![\\w*])";
225
macro: "constant.character",
226
tableBlock: "doc.comment",
227
titleUnderline: "markup.heading",
228
singleLineTitle: "markup.heading",
230
option: "string.regexp",
231
otherBlock: "markup.list",
232
literal: "support.function",
233
optionalTitle: "constant.numeric",
234
escape: "constant.language.escape",
235
link: "markup.underline.list"
238
for (var state in this.$rules) {
239
var stateRules = this.$rules[state];
240
for (var i = stateRules.length; i--; ) {
241
var rule = stateRules[i];
242
if (rule.include || typeof rule == "string") {
243
var args = [i, 1].concat(this.$rules[rule.include || rule]);
245
args = args.filter(function(x) {
249
stateRules.splice.apply(stateRules, args);
250
} else if (rule.token in tokenMap) {
251
rule.token = tokenMap[rule.token];
256
oop.inherits(AsciidocHighlightRules, TextHighlightRules);
258
exports.AsciidocHighlightRules = AsciidocHighlightRules;
261
define('ace/mode/folding/asciidoc', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/folding/fold_mode', 'ace/range'], function(require, exports, module) {
264
var oop = require("../../lib/oop");
265
var BaseFoldMode = require("./fold_mode").FoldMode;
266
var Range = require("../../range").Range;
268
var FoldMode = exports.FoldMode = function() {};
269
oop.inherits(FoldMode, BaseFoldMode);
272
this.foldingStartMarker = /^(?:\|={10,}|[\.\/=\-~^+]{4,}\s*$|={1,5} )/;
273
this.singleLineHeadingRe = /^={1,5}(?=\s+\S)/;
275
this.getFoldWidget = function(session, foldStyle, row) {
276
var line = session.getLine(row);
277
if (!this.foldingStartMarker.test(line))
280
if (line[0] == "=") {
281
if (this.singleLineHeadingRe.test(line))
283
if (session.getLine(row - 1).length != session.getLine(row).length)
287
if (session.bgTokenizer.getState(row) == "dissallowDelimitedBlock")
292
this.getFoldWidgetRange = function(session, foldStyle, row) {
293
var line = session.getLine(row);
294
var startColumn = line.length;
295
var maxRow = session.getLength();
298
if (!line.match(this.foldingStartMarker))
302
function getTokenType(row) {
303
token = session.getTokens(row)[0];
304
return token && token.type;
307
var levels = ["=","-","~","^","+"];
308
var heading = "markup.heading";
309
var singleLineHeadingRe = this.singleLineHeadingRe;
310
function getLevel() {
311
var match = token.value.match(singleLineHeadingRe);
313
return match[0].length;
314
var level = levels.indexOf(token.value[0]) + 1;
316
if (session.getLine(row - 1).length != session.getLine(row).length)
322
if (getTokenType(row) == heading) {
323
var startHeadingLevel = getLevel();
324
while (++row < maxRow) {
325
if (getTokenType(row) != heading)
327
var level = getLevel();
328
if (level <= startHeadingLevel)
332
var isSingleLineHeading = token && token.value.match(this.singleLineHeadingRe);
333
endRow = isSingleLineHeading ? row - 1 : row - 2;
335
if (endRow > startRow) {
336
while (endRow > startRow && (!getTokenType(endRow) || token.value[0] == "["))
340
if (endRow > startRow) {
341
var endColumn = session.getLine(endRow).length;
342
return new Range(startRow, startColumn, endRow, endColumn);
345
var state = session.bgTokenizer.getState(row);
346
if (state == "dissallowDelimitedBlock") {
348
if (session.bgTokenizer.getState(row).lastIndexOf("Block") == -1)
352
if (endRow < startRow) {
353
var endColumn = session.getLine(row).length;
354
return new Range(endRow, 5, startRow, startColumn - 5);
357
while (++row < maxRow) {
358
if (session.bgTokenizer.getState(row) == "dissallowDelimitedBlock")
362
if (endRow > startRow) {
363
var endColumn = session.getLine(row).length;
364
return new Range(startRow, 5, endRow, endColumn - 5);
370
}).call(FoldMode.prototype);