mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 04:45:21 -05:00
Latex mode for ace has new syntax highlighting
This is an update to the latest version.
This commit is contained in:
parent
b5341e8a25
commit
1d9e3f431c
1 changed files with 44 additions and 12 deletions
|
@ -4,11 +4,24 @@ ace.define("ace/mode/latex_highlight_rules",["require","exports","module","ace/l
|
||||||
var oop = require("../lib/oop");
|
var oop = require("../lib/oop");
|
||||||
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
|
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
|
||||||
|
|
||||||
var LatexHighlightRules = function() {
|
var LatexHighlightRules = function() {
|
||||||
|
|
||||||
this.$rules = {
|
this.$rules = {
|
||||||
"start" : [{
|
"start" : [{
|
||||||
token : "keyword",
|
token : "comment",
|
||||||
regex : "\\\\(?:[^a-zA-Z]|[a-zA-Z]+)"
|
regex : "%.*$"
|
||||||
|
}, {
|
||||||
|
token : ["keyword", "lparen", "variable.parameter", "rparen", "lparen", "storage.type", "rparen"],
|
||||||
|
regex : "(\\\\(?:documentclass|usepackage|input))(?:(\\[)([^\\]]*)(\\]))?({)([^}]*)(})"
|
||||||
|
}, {
|
||||||
|
token : ["keyword","lparen", "variable.parameter", "rparen"],
|
||||||
|
regex : "(\\\\label)(?:({)([^}]*)(}))?"
|
||||||
|
}, {
|
||||||
|
token : ["storage.type", "lparen", "variable.parameter", "rparen"],
|
||||||
|
regex : "(\\\\(?:begin|end))({)(\\w*)(})"
|
||||||
|
}, {
|
||||||
|
token : "storage.type",
|
||||||
|
regex : "\\\\[a-zA-Z]+"
|
||||||
}, {
|
}, {
|
||||||
token : "lparen",
|
token : "lparen",
|
||||||
regex : "[[({]"
|
regex : "[[({]"
|
||||||
|
@ -16,15 +29,33 @@ var LatexHighlightRules = function() {
|
||||||
token : "rparen",
|
token : "rparen",
|
||||||
regex : "[\\])}]"
|
regex : "[\\])}]"
|
||||||
}, {
|
}, {
|
||||||
token : "string",
|
token : "constant.character.escape",
|
||||||
regex : "\\$(?:(?:\\\\.)|(?:[^\\$\\\\]))*?\\$"
|
regex : "\\\\[^a-zA-Z]?"
|
||||||
}, {
|
}, {
|
||||||
|
token : "string",
|
||||||
|
regex : "\\${1,2}",
|
||||||
|
next : "equation"
|
||||||
|
}],
|
||||||
|
"equation" : [{
|
||||||
token : "comment",
|
token : "comment",
|
||||||
regex : "%.*$"
|
regex : "%.*$"
|
||||||
|
}, {
|
||||||
|
token : "string",
|
||||||
|
regex : "\\${1,2}",
|
||||||
|
next : "start"
|
||||||
|
}, {
|
||||||
|
token : "constant.character.escape",
|
||||||
|
regex : "\\\\(?:[^a-zA-Z]|[a-zA-Z]+)"
|
||||||
|
}, {
|
||||||
|
token : "error",
|
||||||
|
regex : "^\\s*$",
|
||||||
|
next : "start"
|
||||||
|
}, {
|
||||||
|
defaultToken : "string"
|
||||||
}]
|
}]
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
oop.inherits(LatexHighlightRules, TextHighlightRules);
|
oop.inherits(LatexHighlightRules, TextHighlightRules);
|
||||||
|
|
||||||
exports.LatexHighlightRules = LatexHighlightRules;
|
exports.LatexHighlightRules = LatexHighlightRules;
|
||||||
|
@ -45,7 +76,7 @@ oop.inherits(FoldMode, BaseFoldMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
this.foldingStartMarker = /^\s*\\(begin)|(section|subsection)\b|{\s*$/;
|
this.foldingStartMarker = /^\s*\\(begin)|(section|subsection|paragraph)\b|{\s*$/;
|
||||||
this.foldingStopMarker = /^\s*\\(end)\b|^\s*}/;
|
this.foldingStopMarker = /^\s*\\(end)\b|^\s*}/;
|
||||||
|
|
||||||
this.getFoldWidgetRange = function(session, foldStyle, row) {
|
this.getFoldWidgetRange = function(session, foldStyle, row) {
|
||||||
|
@ -77,7 +108,7 @@ oop.inherits(FoldMode, BaseFoldMode);
|
||||||
|
|
||||||
var stream = new TokenIterator(session, row, column);
|
var stream = new TokenIterator(session, row, column);
|
||||||
var token = stream.getCurrentToken();
|
var token = stream.getCurrentToken();
|
||||||
if (!token || token.type !== "keyword")
|
if (!token || !(token.type == "storage.type" || token.type == "constant.character.escape"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var val = token.value;
|
var val = token.value;
|
||||||
|
@ -99,7 +130,7 @@ oop.inherits(FoldMode, BaseFoldMode);
|
||||||
|
|
||||||
stream.step = dir === -1 ? stream.stepBackward : stream.stepForward;
|
stream.step = dir === -1 ? stream.stepBackward : stream.stepForward;
|
||||||
while(token = stream.step()) {
|
while(token = stream.step()) {
|
||||||
if (token.type !== "keyword")
|
if (!token || !(token.type == "storage.type" || token.type == "constant.character.escape"))
|
||||||
continue;
|
continue;
|
||||||
var level = keywords[token.value];
|
var level = keywords[token.value];
|
||||||
if (!level)
|
if (!level)
|
||||||
|
@ -122,11 +153,11 @@ oop.inherits(FoldMode, BaseFoldMode);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.latexSection = function(session, row, column) {
|
this.latexSection = function(session, row, column) {
|
||||||
var keywords = ["\\subsection", "\\section", "\\begin", "\\end"];
|
var keywords = ["\\subsection", "\\section", "\\begin", "\\end", "\\paragraph"];
|
||||||
|
|
||||||
var stream = new TokenIterator(session, row, column);
|
var stream = new TokenIterator(session, row, column);
|
||||||
var token = stream.getCurrentToken();
|
var token = stream.getCurrentToken();
|
||||||
if (!token || token.type != "keyword")
|
if (!token || token.type != "storage.type")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var startLevel = keywords.indexOf(token.value);
|
var startLevel = keywords.indexOf(token.value);
|
||||||
|
@ -134,7 +165,7 @@ oop.inherits(FoldMode, BaseFoldMode);
|
||||||
var endRow = row;
|
var endRow = row;
|
||||||
|
|
||||||
while(token = stream.stepForward()) {
|
while(token = stream.stepForward()) {
|
||||||
if (token.type !== "keyword")
|
if (token.type !== "storage.type")
|
||||||
continue;
|
continue;
|
||||||
var level = keywords.indexOf(token.value);
|
var level = keywords.indexOf(token.value);
|
||||||
|
|
||||||
|
@ -181,6 +212,7 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
this.type = "text";
|
this.type = "text";
|
||||||
|
|
||||||
this.lineCommentStart = "%";
|
this.lineCommentStart = "%";
|
||||||
|
|
||||||
this.$id = "ace/mode/latex";
|
this.$id = "ace/mode/latex";
|
||||||
|
|
Loading…
Reference in a new issue