Merge remote-tracking branch 'jpallen/latex_highlighting' into gh-pages

Conflicts:
	demo/demo.js
	kitchen-sink.html
This commit is contained in:
Fabian Jakobs 2011-09-06 14:31:23 +02:00
commit aaa7abe505
4 changed files with 108 additions and 2 deletions

58
lib/ace/mode/latex.js Normal file
View file

@ -0,0 +1,58 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var TextMode = require("ace/mode/text").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var LatexHighlightRules = require("ace/mode/latex_highlight_rules").LatexHighlightRules;
var Range = require("ace/range").Range;
var Mode = function()
{
this.$tokenizer = new Tokenizer(new LatexHighlightRules().getRules());
};
oop.inherits(Mode, TextMode);
(function()
{
this.toggleCommentLines = function(state, doc, startRow, endRow) {
// This code is adapted from ruby.js
var outdent = true;
var outentedRows = [];
// LaTeX comments begin with % and go to the end of the line
var commentRegEx = /^(\s*)\%/;
for (var i = startRow; i <= endRow; i++) {
if (!commentRegEx.test(doc.getLine(i))) {
outdent = false;
break;
}
}
if (outdent) {
var deleteRange = new Range(0, 0, 0, 0);
for (var i = startRow; i <= endRow; i++) {
var line = doc.getLine(i);
var m = line.match(commentRegEx);
deleteRange.start.row = i;
deleteRange.end.row = i;
deleteRange.end.column = m[0].length;
doc.replace(deleteRange, m[1]);
}
}
else {
doc.indentRows(startRow, endRow, "%");
}
};
// There is no universally accepted way of indenting a tex document
// so just maintain the indentation of the previous line
this.getNextLineIndent = function(state, line, tab) {
return this.$getIndent(line);
};
}).call(Mode.prototype);
exports.Mode = Mode;
});

View file

@ -0,0 +1,39 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
var LatexHighlightRules = function()
{
this.$rules = {
"start" : [
{
// A tex command e.g. \foo
token : "keyword",
regex : "\\\\(?:[^a-zA-Z]|[a-zA-Z]+)",
},
{
// Curly and square braces
token : "keyword",
regex : "[\\{\\}\\]\\[]"
},
{
// Inline math between two $ symbols
token : "string",
regex : "\\$(?:(?:\\\\.)|(?:[^\\$\\\\]))*?\\$"
},
{
// A comment. Tex comments start with % and go to
// the end of the line
token : "comment",
regex : "%.*$"
}
]
};
};
oop.inherits(LatexHighlightRules, TextHighlightRules);
exports.LatexHighlightRules = LatexHighlightRules;
});