/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-latex.js

  • Committer: Gustav Hatvigsson
  • Date: 2013-05-30 12:02:31 UTC
  • mfrom: (85.1.28 lenasys)
  • Revision ID: gustav.hartvigsson@gmail.com-20130530120231-ttqgqjqw2w8enn7g
Merged Ohlsons changes:
added function to get ssn and name for the registrationspages in the user model.
added the registrationpage for students.
edited the registration page for instructors
edited the css for both the registrationpages
minor fix to registration css

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
define('ace/mode/latex', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/latex_highlight_rules', 'ace/mode/folding/latex', 'ace/range'], function(require, exports, module) {
 
2
 
 
3
 
 
4
var oop = require("../lib/oop");
 
5
var TextMode = require("./text").Mode;
 
6
var Tokenizer = require("../tokenizer").Tokenizer;
 
7
var LatexHighlightRules = require("./latex_highlight_rules").LatexHighlightRules;
 
8
var LatexFoldMode = require("./folding/latex").FoldMode;
 
9
var Range = require("../range").Range;
 
10
 
 
11
var Mode = function() {
 
12
    this.$tokenizer = new Tokenizer(new LatexHighlightRules().getRules());
 
13
    this.foldingRules = new LatexFoldMode();
 
14
};
 
15
oop.inherits(Mode, TextMode);
 
16
 
 
17
(function() {
 
18
    this.lineCommentStart = "%";
 
19
 
 
20
}).call(Mode.prototype);
 
21
 
 
22
exports.Mode = Mode;
 
23
 
 
24
});
 
25
define('ace/mode/latex_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
 
26
 
 
27
 
 
28
var oop = require("../lib/oop");
 
29
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
 
30
 
 
31
var LatexHighlightRules = function() {   
 
32
    this.$rules = {
 
33
        "start" : [{
 
34
            token : "keyword",
 
35
            regex : "\\\\(?:[^a-zA-Z]|[a-zA-Z]+)"
 
36
        }, {
 
37
            token : "lparen",
 
38
            regex : "[[({]"
 
39
        }, {
 
40
            token : "rparen",
 
41
            regex : "[\\])}]"
 
42
        }, {
 
43
            token : "string",
 
44
            regex : "\\$(?:(?:\\\\.)|(?:[^\\$\\\\]))*?\\$"
 
45
        }, {
 
46
            token : "comment",
 
47
            regex : "%.*$"
 
48
        }]
 
49
    };
 
50
};
 
51
 
 
52
oop.inherits(LatexHighlightRules, TextHighlightRules);
 
53
 
 
54
exports.LatexHighlightRules = LatexHighlightRules;
 
55
 
 
56
});
 
57
 
 
58
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) {
 
59
 
 
60
 
 
61
var oop = require("../../lib/oop");
 
62
var BaseFoldMode = require("./fold_mode").FoldMode;
 
63
var Range = require("../../range").Range;
 
64
var TokenIterator = require("../../token_iterator").TokenIterator;
 
65
 
 
66
var FoldMode = exports.FoldMode = function() {};
 
67
 
 
68
oop.inherits(FoldMode, BaseFoldMode);
 
69
 
 
70
(function() {
 
71
 
 
72
    this.foldingStartMarker = /^\s*\\(begin)|(section|subsection)\b|{\s*$/;
 
73
    this.foldingStopMarker = /^\s*\\(end)\b|^\s*}/;
 
74
 
 
75
    this.getFoldWidgetRange = function(session, foldStyle, row) {
 
76
        var line = session.doc.getLine(row);
 
77
        var match = this.foldingStartMarker.exec(line);
 
78
        if (match) {
 
79
            if (match[1])
 
80
                return this.latexBlock(session, row, match[0].length - 1);
 
81
            if (match[2])
 
82
                return this.latexSection(session, row, match[0].length - 1);
 
83
 
 
84
            return this.openingBracketBlock(session, "{", row, match.index);
 
85
        }
 
86
 
 
87
        var match = this.foldingStopMarker.exec(line);
 
88
        if (match) {
 
89
            if (match[1])
 
90
                return this.latexBlock(session, row, match[0].length - 1);
 
91
 
 
92
            return this.closingBracketBlock(session, "}", row, match.index + match[0].length);
 
93
        }
 
94
    };
 
95
 
 
96
    this.latexBlock = function(session, row, column) {
 
97
        var keywords = {
 
98
            "\\begin": 1,
 
99
            "\\end": -1
 
100
        };
 
101
 
 
102
        var stream = new TokenIterator(session, row, column);
 
103
        var token = stream.getCurrentToken();
 
104
        if (!token || token.type !== "keyword")
 
105
            return;
 
106
 
 
107
        var val = token.value;
 
108
        var dir = keywords[val];
 
109
 
 
110
        var getType = function() {
 
111
            var token = stream.stepForward();
 
112
            var type = token.type == "lparen" ?stream.stepForward().value : "";
 
113
            if (dir === -1) {
 
114
                stream.stepBackward();
 
115
                if (type)
 
116
                    stream.stepBackward();
 
117
            }
 
118
            return type;
 
119
        };
 
120
        var stack = [getType()];
 
121
        var startColumn = dir === -1 ? stream.getCurrentTokenColumn() : session.getLine(row).length;
 
122
        var startRow = row;
 
123
 
 
124
        stream.step = dir === -1 ? stream.stepBackward : stream.stepForward;
 
125
        while(token = stream.step()) {
 
126
            if (token.type !== "keyword")
 
127
                continue;
 
128
            var level = keywords[token.value];
 
129
            if (!level)
 
130
                continue;
 
131
            var type = getType();
 
132
            if (level === dir)
 
133
                stack.unshift(type);
 
134
            else if (stack.shift() !== type || !stack.length)
 
135
                break;
 
136
        }
 
137
 
 
138
        if (stack.length)
 
139
            return;
 
140
 
 
141
        var row = stream.getCurrentTokenRow();
 
142
        if (dir === -1)
 
143
            return new Range(row, session.getLine(row).length, startRow, startColumn);
 
144
        stream.stepBackward();
 
145
        return new Range(startRow, startColumn, row, stream.getCurrentTokenColumn());
 
146
    };
 
147
 
 
148
    this.latexSection = function(session, row, column) {
 
149
        var keywords = ["\\subsection", "\\section", "\\begin", "\\end"];
 
150
 
 
151
        var stream = new TokenIterator(session, row, column);
 
152
        var token = stream.getCurrentToken();
 
153
        if (!token || token.type != "keyword")
 
154
            return;
 
155
 
 
156
        var startLevel = keywords.indexOf(token.value);
 
157
        var stackDepth = 0
 
158
        var endRow = row;
 
159
 
 
160
        while(token = stream.stepForward()) {
 
161
            if (token.type !== "keyword")
 
162
                continue;
 
163
            var level = keywords.indexOf(token.value);
 
164
 
 
165
            if (level >= 2) {
 
166
                if (!stackDepth)
 
167
                    endRow = stream.getCurrentTokenRow() - 1;
 
168
                stackDepth += level == 2 ? 1 : - 1;
 
169
                if (stackDepth < 0)
 
170
                    break
 
171
            } else if (level >= startLevel)
 
172
                break;
 
173
        }
 
174
 
 
175
        if (!stackDepth)
 
176
            endRow = stream.getCurrentTokenRow() - 1;
 
177
 
 
178
        while (endRow > row && !/\S/.test(session.getLine(endRow)))
 
179
            endRow--;
 
180
 
 
181
        return new Range(
 
182
            row, session.getLine(row).length,
 
183
            endRow, session.getLine(endRow).length
 
184
        );
 
185
    };
 
186
 
 
187
}).call(FoldMode.prototype);
 
188
 
 
189
});