/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk

« back to all changes in this revision

Viewing changes to codeigniter/js/ace/mode-asciidoc.js

  • Committer: galaxyAbstractor
  • Date: 2013-04-10 15:49:32 UTC
  • mto: (19.1.5 lenasys)
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: galaxyabstractor@gmail.com-20130410154932-4vizlzk0ar5gykvi
* Added an simple admin panel to the codeviewer-cmssy stuff
* Redesigned a bit like the mockups - still stuff to come
* Implemented the codeviewer + admin panel again using the Framework CodeIgniter instead 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ***** BEGIN LICENSE BLOCK *****
 
2
 * Distributed under the BSD license:
 
3
 *
 
4
 * Copyright (c) 2010, Ajax.org B.V.
 
5
 * All rights reserved.
 
6
 *
 
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.
 
17
 *
 
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.
 
28
 *
 
29
 * ***** END LICENSE BLOCK ***** */
 
30
 
 
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) {
 
32
 
 
33
 
 
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;
 
39
 
 
40
var Mode = function() {
 
41
    var highlighter = new AsciidocHighlightRules();
 
42
    
 
43
    this.$tokenizer = new Tokenizer(highlighter.getRules());
 
44
    this.foldingRules = new AsciidocFoldMode();    
 
45
};
 
46
oop.inherits(Mode, TextMode);
 
47
 
 
48
(function() {
 
49
    this.getNextLineIndent = function(state, line, tab) {
 
50
        if (state == "listblock") {
 
51
            var match = /^((?:.+)?)([-+*][ ]+)/.exec(line);
 
52
            if (match) {
 
53
                return new Array(match[1].length + 1).join(" ") + match[2];
 
54
            } else {
 
55
                return "";
 
56
            }
 
57
        } else {
 
58
            return this.$getIndent(line);
 
59
        }
 
60
    };
 
61
}).call(Mode.prototype);
 
62
 
 
63
exports.Mode = Mode;
 
64
});
 
65
 
 
66
define('ace/mode/asciidoc_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
 
67
 
 
68
 
 
69
var oop = require("../lib/oop");
 
70
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
 
71
 
 
72
var AsciidocHighlightRules = function() {
 
73
    var identifierRe = "[a-zA-Z\u00a1-\uffff]+\\b";
 
74
 
 
75
    this.$rules = {
 
76
        "start": [
 
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"}
 
84
        ],
 
85
 
 
86
        "dissallowDelimitedBlock": [
 
87
            {include: "paragraphEnd"},
 
88
            {token: "comment", regex: '^//.+$'},
 
89
            {token: "keyword", regex: "^(?:NOTE|TIP|IMPORTANT|WARNING|CAUTION):"},
 
90
 
 
91
            {include: "listStart"},
 
92
            {token: "literal", regex: /^\s+.+$/, next: "indentedBlock"},
 
93
            {token: "empty",   regex: "", next: "text"}
 
94
        ],
 
95
 
 
96
        "paragraphEnd": [
 
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"},
 
105
 
 
106
            {token: "otherBlock",    regex: /^(?:\*{2,}|_{2,})\s*$/, next: "start"},
 
107
            {token: "optionalTitle", regex: /^\.[^.\s].+$/,  next: "start"}
 
108
        ],
 
109
 
 
110
        "listStart": [
 
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"}
 
115
        ],
 
116
 
 
117
        "text": [
 
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/},
 
121
            {include: "macros"},
 
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\-$]+,)(.*?)(>>|$)/},
 
130
            {token: "keyword", regex: /<<[\w\d\-$]+,?|>>/},
 
131
            {token: "constant.character", regex: /\({2,3}.*?\){2,3}/},
 
132
            {token: "keyword", regex: /\[\[.+?\]\]/},
 
133
            {token: "support", regex: /^\[{3}[\w\d =\-]+\]{3}/},
 
134
 
 
135
            {include: "quotes"},
 
136
            {token: "empty", regex: /^\s*$/, next: "start"}
 
137
        ],
 
138
 
 
139
        "listText": [
 
140
            {include: "listStart"},
 
141
            {include: "text"}
 
142
        ],
 
143
 
 
144
        "indentedBlock": [
 
145
            {token: "literal", regex: /^[\s\w].+$/, next: "indentedBlock"},
 
146
            {token: "literal", regex: "", next: "start"}
 
147
        ],
 
148
 
 
149
        "listingBlock": [
 
150
            {token: "literal", regex: /^\.{4,}\s*$/, next: "dissallowDelimitedBlock"},
 
151
            {token: "constant.numeric", regex: '<\\d+>'},
 
152
            {token: "literal", regex: '[^<]+'},
 
153
            {token: "literal", regex: '<'}
 
154
        ],
 
155
        "literalBlock": [
 
156
            {token: "literal", regex: /^-{4,}\s*$/, next: "dissallowDelimitedBlock"},
 
157
            {token: "constant.numeric", regex: '<\\d+>'},
 
158
            {token: "literal", regex: '[^<]+'},
 
159
            {token: "literal", regex: '<'}
 
160
        ],
 
161
        "passthroughBlock": [
 
162
            {token: "literal", regex: /^\+{4,}\s*$/, next: "dissallowDelimitedBlock"},
 
163
            {token: "literal", regex: identifierRe + "|\\d+"},
 
164
            {include: "macros"},
 
165
            {token: "literal", regex: "."}
 
166
        ],
 
167
 
 
168
        "smallPassthrough": [
 
169
            {token: "literal", regex: /[+]{3,}/, next: "dissallowDelimitedBlock"},
 
170
            {token: "literal", regex: /^\s*$/, next: "dissallowDelimitedBlock"},
 
171
            {token: "literal", regex: identifierRe + "|\\d+"},
 
172
            {include: "macros"}
 
173
        ],
 
174
 
 
175
        "commentBlock": [
 
176
            {token: "doc.comment", regex: /^\/{4,}\s*$/, next: "dissallowDelimitedBlock"},
 
177
            {token: "doc.comment", regex: '^.*$'}
 
178
        ],
 
179
        "tableBlock": [
 
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}
 
184
        ],
 
185
        "innerTableBlock": [
 
186
            {token: "tableBlock", regex: /^\s*!={3,}\s*$/, next: "tableBlock"},
 
187
            {token: "tableBlock", regex: /^\s*|={3,}\s*$/, next: "dissallowDelimitedBlock"},
 
188
            {token: "tableBlock", regex: /\!/}
 
189
        ],
 
190
        "macros": [
 
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: /^:.+?:(?= |$)/}
 
197
        ],
 
198
 
 
199
        "quotes": [
 
200
            {token: "string.italic", regex: /__[^_\s].*?__/},
 
201
            {token: "string.italic", regex: quoteRule("_")},
 
202
            
 
203
            {token: "keyword.bold", regex: /\*\*[^*\s].*?\*\*/},
 
204
            {token: "keyword.bold", regex: quoteRule("\\*")},
 
205
            
 
206
            {token: "literal", regex: quoteRule("\\+")},
 
207
            {token: "literal", regex: /\+\+[^+\s].*?\+\+/},
 
208
            {token: "literal", regex: /\$\$.+?\$\$/},
 
209
            {token: "literal", regex: quoteRule("`")},
 
210
 
 
211
            {token: "keyword", regex: quoteRule("^")},
 
212
            {token: "keyword", regex: quoteRule("~")},
 
213
            {token: "keyword", regex: /##?/},
 
214
            {token: "keyword", regex: /(?:\B|^)``|\b''/}
 
215
        ]
 
216
 
 
217
    };
 
218
 
 
219
    function quoteRule(ch) {
 
220
        var prefix = /\w/.test(ch) ? "\\b" : "(?:\\B|^)";
 
221
        return prefix + ch + "[^" + ch + "].*?" + ch + "(?![\\w*])";
 
222
    }
 
223
 
 
224
    var tokenMap = {
 
225
        macro: "constant.character",
 
226
        tableBlock: "doc.comment",
 
227
        titleUnderline: "markup.heading",
 
228
        singleLineTitle: "markup.heading",
 
229
        pageBreak: "string",
 
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"
 
236
    };
 
237
 
 
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]);
 
244
                if (rule.noEscape) {
 
245
                    args = args.filter(function(x) {
 
246
                        return !x.next;
 
247
                    });
 
248
                }
 
249
                stateRules.splice.apply(stateRules, args);
 
250
            } else if (rule.token in tokenMap) {
 
251
                rule.token = tokenMap[rule.token];
 
252
            }
 
253
        }
 
254
    }
 
255
};
 
256
oop.inherits(AsciidocHighlightRules, TextHighlightRules);
 
257
 
 
258
exports.AsciidocHighlightRules = AsciidocHighlightRules;
 
259
});
 
260
 
 
261
define('ace/mode/folding/asciidoc', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/folding/fold_mode', 'ace/range'], function(require, exports, module) {
 
262
 
 
263
 
 
264
var oop = require("../../lib/oop");
 
265
var BaseFoldMode = require("./fold_mode").FoldMode;
 
266
var Range = require("../../range").Range;
 
267
 
 
268
var FoldMode = exports.FoldMode = function() {};
 
269
oop.inherits(FoldMode, BaseFoldMode);
 
270
 
 
271
(function() {
 
272
    this.foldingStartMarker = /^(?:\|={10,}|[\.\/=\-~^+]{4,}\s*$|={1,5} )/;
 
273
    this.singleLineHeadingRe = /^={1,5}(?=\s+\S)/;
 
274
 
 
275
    this.getFoldWidget = function(session, foldStyle, row) {
 
276
        var line = session.getLine(row);
 
277
        if (!this.foldingStartMarker.test(line))
 
278
            return ""
 
279
 
 
280
        if (line[0] == "=") {
 
281
            if (this.singleLineHeadingRe.test(line))
 
282
                return "start";
 
283
            if (session.getLine(row - 1).length != session.getLine(row).length)
 
284
                return "";
 
285
            return "start";
 
286
        }
 
287
        if (session.bgTokenizer.getState(row) == "dissallowDelimitedBlock")
 
288
            return "end";
 
289
        return "start";
 
290
    };
 
291
 
 
292
    this.getFoldWidgetRange = function(session, foldStyle, row) {
 
293
        var line = session.getLine(row);
 
294
        var startColumn = line.length;
 
295
        var maxRow = session.getLength();
 
296
        var startRow = row;
 
297
        var endRow = row;
 
298
        if (!line.match(this.foldingStartMarker))
 
299
            return;
 
300
 
 
301
        var token;
 
302
        function getTokenType(row) {
 
303
            token = session.getTokens(row)[0];
 
304
            return token && token.type;
 
305
        }
 
306
 
 
307
        var levels = ["=","-","~","^","+"];
 
308
        var heading = "markup.heading";
 
309
        var singleLineHeadingRe = this.singleLineHeadingRe;
 
310
        function getLevel() {
 
311
            var match = token.value.match(singleLineHeadingRe);
 
312
            if (match)
 
313
                return match[0].length;
 
314
            var level = levels.indexOf(token.value[0]) + 1;
 
315
            if (level == 1) {
 
316
                if (session.getLine(row - 1).length != session.getLine(row).length)
 
317
                    return Infinity;
 
318
            }
 
319
            return level;
 
320
        }
 
321
 
 
322
        if (getTokenType(row) == heading) {
 
323
            var startHeadingLevel = getLevel();
 
324
            while (++row < maxRow) {
 
325
                if (getTokenType(row) != heading)
 
326
                    continue;
 
327
                var level = getLevel();
 
328
                if (level <= startHeadingLevel)
 
329
                    break;
 
330
            }
 
331
 
 
332
            var isSingleLineHeading = token && token.value.match(this.singleLineHeadingRe);
 
333
            endRow = isSingleLineHeading ? row - 1 : row - 2;
 
334
 
 
335
            if (endRow > startRow) {
 
336
                while (endRow > startRow && (!getTokenType(endRow) || token.value[0] == "["))
 
337
                    endRow--;
 
338
            }
 
339
 
 
340
            if (endRow > startRow) {
 
341
                var endColumn = session.getLine(endRow).length;
 
342
                return new Range(startRow, startColumn, endRow, endColumn);
 
343
            }
 
344
        } else {
 
345
            var state = session.bgTokenizer.getState(row);
 
346
            if (state == "dissallowDelimitedBlock") {
 
347
                while (row -- > 0) {
 
348
                    if (session.bgTokenizer.getState(row).lastIndexOf("Block") == -1)
 
349
                        break;
 
350
                }
 
351
                endRow = row + 1;
 
352
                if (endRow < startRow) {
 
353
                    var endColumn = session.getLine(row).length;
 
354
                    return new Range(endRow, 5, startRow, startColumn - 5);
 
355
                }
 
356
            } else {
 
357
                while (++row < maxRow) {
 
358
                    if (session.bgTokenizer.getState(row) == "dissallowDelimitedBlock")
 
359
                        break;
 
360
                }
 
361
                endRow = row;
 
362
                if (endRow > startRow) {
 
363
                    var endColumn = session.getLine(row).length;
 
364
                    return new Range(startRow, 5, endRow, endColumn - 5);
 
365
                }
 
366
            }
 
367
        }
 
368
    };
 
369
 
 
370
}).call(FoldMode.prototype);
 
371
 
 
372
});