Projekt

Obecné

Profil

Stáhnout (9.5 KB) Statistiky
| Větev: | Tag: | Revize:
1
ace.define("ace/mode/latex_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
2
"use strict";
3

    
4
var oop = require("../lib/oop");
5
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
6

    
7
var LatexHighlightRules = function() {  
8

    
9
    this.$rules = {
10
        "start" : [{
11
            token : "comment",
12
            regex : "%.*$"
13
        }, {
14
            token : ["keyword", "lparen", "variable.parameter", "rparen", "lparen", "storage.type", "rparen"],
15
            regex : "(\\\\(?:documentclass|usepackage|input))(?:(\\[)([^\\]]*)(\\]))?({)([^}]*)(})"
16
        }, {
17
            token : ["keyword","lparen", "variable.parameter", "rparen"],
18
            regex : "(\\\\(?:label|v?ref|cite(?:[^{]*)))(?:({)([^}]*)(}))?"
19
        }, {
20
            token : ["storage.type", "lparen", "variable.parameter", "rparen"],
21
            regex : "(\\\\begin)({)(verbatim)(})",
22
            next : "verbatim"
23
        },  {
24
            token : ["storage.type", "lparen", "variable.parameter", "rparen"],
25
            regex : "(\\\\begin)({)(lstlisting)(})",
26
            next : "lstlisting"
27
        },  {
28
            token : ["storage.type", "lparen", "variable.parameter", "rparen"],
29
            regex : "(\\\\(?:begin|end))({)([\\w*]*)(})"
30
        }, {
31
            token : "storage.type",
32
            regex : /\\verb\b\*?/,
33
            next : [{
34
                token : ["keyword.operator", "string", "keyword.operator"],
35
                regex : "(.)(.*?)(\\1|$)|",
36
                next : "start"
37
            }]
38
        }, {
39
            token : "storage.type",
40
            regex : "\\\\[a-zA-Z]+"
41
        }, {
42
            token : "lparen",
43
            regex : "[[({]"
44
        }, {
45
            token : "rparen",
46
            regex : "[\\])}]"
47
        }, {
48
            token : "constant.character.escape",
49
            regex : "\\\\[^a-zA-Z]?"
50
        }, {
51
            token : "string",
52
            regex : "\\${1,2}",
53
            next  : "equation"
54
        }],
55
        "equation" : [{
56
            token : "comment",
57
            regex : "%.*$"
58
        }, {
59
            token : "string",
60
            regex : "\\${1,2}",
61
            next  : "start"
62
        }, {
63
            token : "constant.character.escape",
64
            regex : "\\\\(?:[^a-zA-Z]|[a-zA-Z]+)"
65
        }, {
66
            token : "error", 
67
            regex : "^\\s*$", 
68
            next : "start" 
69
        }, {
70
            defaultToken : "string"
71
        }],
72
        "verbatim": [{
73
            token : ["storage.type", "lparen", "variable.parameter", "rparen"],
74
            regex : "(\\\\end)({)(verbatim)(})",
75
            next : "start"
76
        }, {
77
            defaultToken : "text"
78
        }],
79
        "lstlisting": [{
80
            token : ["storage.type", "lparen", "variable.parameter", "rparen"],
81
            regex : "(\\\\end)({)(lstlisting)(})",
82
            next : "start"
83
        }, {
84
            defaultToken : "text"
85
        }]
86
    };
87
    
88
    this.normalizeRules();
89
};
90
oop.inherits(LatexHighlightRules, TextHighlightRules);
91

    
92
exports.LatexHighlightRules = LatexHighlightRules;
93

    
94
});
95

    
96
ace.define("ace/mode/folding/latex",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode","ace/range","ace/token_iterator"], function(require, exports, module) {
97
"use strict";
98

    
99
var oop = require("../../lib/oop");
100
var BaseFoldMode = require("./fold_mode").FoldMode;
101
var Range = require("../../range").Range;
102
var TokenIterator = require("../../token_iterator").TokenIterator;
103
var keywordLevels = {
104
    "\\subparagraph": 1,
105
    "\\paragraph": 2,
106
    "\\subsubsubsection": 3,
107
    "\\subsubsection": 4,
108
    "\\subsection": 5,
109
    "\\section": 6,
110
    "\\chapter": 7,
111
    "\\part": 8,
112
    "\\begin": 9,
113
    "\\end": 10
114
};
115

    
116
var FoldMode = exports.FoldMode = function() {};
117

    
118
oop.inherits(FoldMode, BaseFoldMode);
119

    
120
(function() {
121

    
122
    this.foldingStartMarker = /^\s*\\(begin)|\s*\\(part|chapter|(?:sub)*(?:section|paragraph))\b|{\s*$/;
123
    this.foldingStopMarker = /^\s*\\(end)\b|^\s*}/;
124

    
125
    this.getFoldWidgetRange = function(session, foldStyle, row) {
126
        var line = session.doc.getLine(row);
127
        var match = this.foldingStartMarker.exec(line);
128
        if (match) {
129
            if (match[1])
130
                return this.latexBlock(session, row, match[0].length - 1);
131
            if (match[2])
132
                return this.latexSection(session, row, match[0].length - 1);
133

    
134
            return this.openingBracketBlock(session, "{", row, match.index);
135
        }
136

    
137
        var match = this.foldingStopMarker.exec(line);
138
        if (match) {
139
            if (match[1])
140
                return this.latexBlock(session, row, match[0].length - 1);
141

    
142
            return this.closingBracketBlock(session, "}", row, match.index + match[0].length);
143
        }
144
    };
145

    
146
    this.latexBlock = function(session, row, column, returnRange) {
147
        var keywords = {
148
            "\\begin": 1,
149
            "\\end": -1
150
        };
151

    
152
        var stream = new TokenIterator(session, row, column);
153
        var token = stream.getCurrentToken();
154
        if (!token || !(token.type == "storage.type" || token.type == "constant.character.escape"))
155
            return;
156

    
157
        var val = token.value;
158
        var dir = keywords[val];
159

    
160
        var getType = function() {
161
            var token = stream.stepForward();
162
            var type = token.type == "lparen" ?stream.stepForward().value : "";
163
            if (dir === -1) {
164
                stream.stepBackward();
165
                if (type)
166
                    stream.stepBackward();
167
            }
168
            return type;
169
        };
170
        var stack = [getType()];
171
        var startColumn = dir === -1 ? stream.getCurrentTokenColumn() : session.getLine(row).length;
172
        var startRow = row;
173

    
174
        stream.step = dir === -1 ? stream.stepBackward : stream.stepForward;
175
        while(token = stream.step()) {
176
            if (!token || !(token.type == "storage.type" || token.type == "constant.character.escape"))
177
                continue;
178
            var level = keywords[token.value];
179
            if (!level)
180
                continue;
181
            var type = getType();
182
            if (level === dir)
183
                stack.unshift(type);
184
            else if (stack.shift() !== type || !stack.length)
185
                break;
186
        }
187

    
188
        if (stack.length)
189
            return;
190
        
191
        if (dir == 1) {
192
            stream.stepBackward();
193
            stream.stepBackward();
194
        }
195
        
196
        if (returnRange)
197
            return stream.getCurrentTokenRange();
198

    
199
        var row = stream.getCurrentTokenRow();
200
        if (dir === -1)
201
            return new Range(row, session.getLine(row).length, startRow, startColumn);
202
        else
203
            return new Range(startRow, startColumn, row, stream.getCurrentTokenColumn());
204
    };
205

    
206
    this.latexSection = function(session, row, column) {
207
        var stream = new TokenIterator(session, row, column);
208
        var token = stream.getCurrentToken();
209
        if (!token || token.type != "storage.type")
210
            return;
211

    
212
        var startLevel = keywordLevels[token.value] || 0;
213
        var stackDepth = 0;
214
        var endRow = row;
215

    
216
        while(token = stream.stepForward()) {
217
            if (token.type !== "storage.type")
218
                continue;
219
            var level = keywordLevels[token.value] || 0;
220

    
221
            if (level >= 9) {
222
                if (!stackDepth)
223
                    endRow = stream.getCurrentTokenRow() - 1;
224
                stackDepth += level == 9 ? 1 : - 1;
225
                if (stackDepth < 0)
226
                    break;
227
            } else if (level >= startLevel)
228
                break;
229
        }
230

    
231
        if (!stackDepth)
232
            endRow = stream.getCurrentTokenRow() - 1;
233

    
234
        while (endRow > row && !/\S/.test(session.getLine(endRow)))
235
            endRow--;
236

    
237
        return new Range(
238
            row, session.getLine(row).length,
239
            endRow, session.getLine(endRow).length
240
        );
241
    };
242

    
243
}).call(FoldMode.prototype);
244

    
245
});
246

    
247
ace.define("ace/mode/latex",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/latex_highlight_rules","ace/mode/behaviour/cstyle","ace/mode/folding/latex"], function(require, exports, module) {
248
"use strict";
249

    
250
var oop = require("../lib/oop");
251
var TextMode = require("./text").Mode;
252
var LatexHighlightRules = require("./latex_highlight_rules").LatexHighlightRules;
253
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
254
var LatexFoldMode = require("./folding/latex").FoldMode;
255

    
256
var Mode = function() {
257
    this.HighlightRules = LatexHighlightRules;
258
    this.foldingRules = new LatexFoldMode();
259
    this.$behaviour = new CstyleBehaviour({ braces: true });
260
};
261
oop.inherits(Mode, TextMode);
262

    
263
(function() {
264
    this.type = "text";
265
    
266
    this.lineCommentStart = "%";
267

    
268
    this.$id = "ace/mode/latex";
269
    
270
    this.getMatching = function(session, row, column) {
271
        if (row == undefined)
272
            row = session.selection.lead;
273
        if (typeof row == "object") {
274
            column = row.column;
275
            row = row.row;
276
        }
277

    
278
        var startToken = session.getTokenAt(row, column);
279
        if (!startToken)
280
            return;
281
        if (startToken.value == "\\begin" || startToken.value == "\\end") {
282
            return this.foldingRules.latexBlock(session, row, column, true);
283
        }
284
    };
285
}).call(Mode.prototype);
286

    
287
exports.Mode = Mode;
288

    
289
});                (function() {
290
                    ace.require(["ace/mode/latex"], function(m) {
291
                        if (typeof module == "object" && typeof exports == "object" && module) {
292
                            module.exports = m;
293
                        }
294
                    });
295
                })();
296
            
(105-105/244)