Merge pull request #2089 from dfelder/master
Some more highlight rules for latex mode
This commit is contained in:
commit
706b7815e3
3 changed files with 73 additions and 40 deletions
|
|
@ -2,37 +2,37 @@
|
||||||
"start",
|
"start",
|
||||||
["keyword","\\usepackage"],
|
["keyword","\\usepackage"],
|
||||||
["lparen","{"],
|
["lparen","{"],
|
||||||
["text","amsmath"],
|
["storage.type","amsmath"],
|
||||||
["rparen","}"]
|
["rparen","}"]
|
||||||
],[
|
],[
|
||||||
"start",
|
"start",
|
||||||
["keyword","\\title"],
|
["storage.type","\\title"],
|
||||||
["lparen","{"],
|
["lparen","{"],
|
||||||
["keyword","\\LaTeX"],
|
["storage.type","\\LaTeX"],
|
||||||
["rparen","}"]
|
["rparen","}"]
|
||||||
],[
|
],[
|
||||||
"start",
|
"start",
|
||||||
["keyword","\\date"],
|
["storage.type","\\date"],
|
||||||
["lparen","{"],
|
["lparen","{"],
|
||||||
["rparen","}"]
|
["rparen","}"]
|
||||||
],[
|
],[
|
||||||
"start",
|
"start",
|
||||||
["keyword","\\begin"],
|
["storage.type","\\begin"],
|
||||||
["lparen","{"],
|
["lparen","{"],
|
||||||
["text","document"],
|
["variable.parameter","document"],
|
||||||
["rparen","}"]
|
["rparen","}"]
|
||||||
],[
|
],[
|
||||||
"start",
|
"start",
|
||||||
["text"," "],
|
["text"," "],
|
||||||
["keyword","\\maketitle"]
|
["storage.type","\\maketitle"]
|
||||||
],[
|
],[
|
||||||
"start",
|
"start",
|
||||||
["text"," "],
|
["text"," "],
|
||||||
["keyword","\\LaTeX"],
|
["storage.type","\\LaTeX"],
|
||||||
["lparen","{"],
|
["lparen","{"],
|
||||||
["rparen","}"],
|
["rparen","}"],
|
||||||
["text"," is a document preparation system for the "],
|
["text"," is a document preparation system for the "],
|
||||||
["keyword","\\TeX"],
|
["storage.type","\\TeX"],
|
||||||
["lparen","{"],
|
["lparen","{"],
|
||||||
["rparen","}"]
|
["rparen","}"]
|
||||||
],[
|
],[
|
||||||
|
|
@ -50,26 +50,26 @@
|
||||||
],[
|
],[
|
||||||
"start",
|
"start",
|
||||||
["text"," and much more. "],
|
["text"," and much more. "],
|
||||||
["keyword","\\LaTeX"],
|
["storage.type","\\LaTeX"],
|
||||||
["lparen","{"],
|
["lparen","{"],
|
||||||
["rparen","}"],
|
["rparen","}"],
|
||||||
["text"," was originally written in 1984 by Leslie"]
|
["text"," was originally written in 1984 by Leslie"]
|
||||||
],[
|
],[
|
||||||
"start",
|
"start",
|
||||||
["text"," Lamport and has become the dominant method for using "],
|
["text"," Lamport and has become the dominant method for using "],
|
||||||
["keyword","\\TeX"],
|
["storage.type","\\TeX"],
|
||||||
["text","; few"]
|
["text","; few"]
|
||||||
],[
|
],[
|
||||||
"start",
|
"start",
|
||||||
["text"," people write in plain "],
|
["text"," people write in plain "],
|
||||||
["keyword","\\TeX"],
|
["storage.type","\\TeX"],
|
||||||
["lparen","{"],
|
["lparen","{"],
|
||||||
["rparen","}"],
|
["rparen","}"],
|
||||||
["text"," anymore. The current version is"]
|
["text"," anymore. The current version is"]
|
||||||
],[
|
],[
|
||||||
"start",
|
"start",
|
||||||
["text"," "],
|
["text"," "],
|
||||||
["keyword","\\LaTeXe"],
|
["storage.type","\\LaTeXe"],
|
||||||
["text","."]
|
["text","."]
|
||||||
],[
|
],[
|
||||||
"start",
|
"start",
|
||||||
|
|
@ -85,26 +85,24 @@
|
||||||
],[
|
],[
|
||||||
"start",
|
"start",
|
||||||
["text"," "],
|
["text"," "],
|
||||||
["keyword","\\begin"],
|
["storage.type","\\begin"],
|
||||||
["lparen","{"],
|
["lparen","{"],
|
||||||
["text","align"],
|
["variable.parameter","align"],
|
||||||
["rparen","}"]
|
["rparen","}"]
|
||||||
],[
|
],[
|
||||||
"start",
|
"start",
|
||||||
["text"," E &= mc^2 "],
|
["text"," E &= mc^2 "],
|
||||||
["keyword","\\\\"]
|
["constant.character.escape","\\\\"],
|
||||||
],[
|
|
||||||
"start",
|
|
||||||
["text"," m &= "],
|
["text"," m &= "],
|
||||||
["keyword","\\frac"],
|
["storage.type","\\frac"],
|
||||||
["lparen","{"],
|
["lparen","{"],
|
||||||
["text","m_0"],
|
["text","m_0"],
|
||||||
["rparen","}"],
|
["rparen","}"],
|
||||||
["lparen","{"],
|
["lparen","{"],
|
||||||
["keyword","\\sqrt"],
|
["storage.type","\\sqrt"],
|
||||||
["lparen","{"],
|
["lparen","{"],
|
||||||
["text","1-"],
|
["text","1-"],
|
||||||
["keyword","\\frac"],
|
["storage.type","\\frac"],
|
||||||
["lparen","{"],
|
["lparen","{"],
|
||||||
["text","v^2"],
|
["text","v^2"],
|
||||||
["rparen","}"],
|
["rparen","}"],
|
||||||
|
|
@ -114,14 +112,14 @@
|
||||||
],[
|
],[
|
||||||
"start",
|
"start",
|
||||||
["text"," "],
|
["text"," "],
|
||||||
["keyword","\\end"],
|
["storage.type","\\end"],
|
||||||
["lparen","{"],
|
["lparen","{"],
|
||||||
["text","align"],
|
["variable.parameter","align"],
|
||||||
["rparen","}"]
|
["rparen","}"]
|
||||||
],[
|
],[
|
||||||
"start",
|
"start",
|
||||||
["keyword","\\end"],
|
["storage.type","\\end"],
|
||||||
["lparen","{"],
|
["lparen","{"],
|
||||||
["text","document"],
|
["variable.parameter","document"],
|
||||||
["rparen","}"]
|
["rparen","}"]
|
||||||
]]
|
]]
|
||||||
|
|
@ -42,7 +42,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) {
|
||||||
|
|
@ -74,7 +74,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;
|
||||||
|
|
@ -96,7 +96,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)
|
||||||
|
|
@ -119,11 +119,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);
|
||||||
|
|
@ -131,7 +131,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);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,30 @@ define(function(require, exports, module) {
|
||||||
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" : [{
|
||||||
|
// A comment. Tex comments start with % and go to
|
||||||
|
// the end of the line
|
||||||
|
token : "comment",
|
||||||
|
regex : "%.*$"
|
||||||
|
}, {
|
||||||
|
// Documentclass and usepackage
|
||||||
|
token : ["keyword", "lparen", "variable.parameter", "rparen", "lparen", "storage.type", "rparen"],
|
||||||
|
regex : "(\\\\(?:documentclass|usepackage|input))(?:(\\[)([^\\]]*)(\\]))?({)([^}]*)(})"
|
||||||
|
}, {
|
||||||
|
// A label
|
||||||
|
token : ["keyword","lparen", "variable.parameter", "rparen"],
|
||||||
|
regex : "(\\\\label)(?:({)([^}]*)(}))?"
|
||||||
|
}, {
|
||||||
|
// A block
|
||||||
|
token : ["storage.type", "lparen", "variable.parameter", "rparen"],
|
||||||
|
regex : "(\\\\(?:begin|end))({)(\\w*)(})"
|
||||||
|
}, {
|
||||||
// A tex command e.g. \foo
|
// A tex command e.g. \foo
|
||||||
token : "keyword",
|
token : "storage.type",
|
||||||
regex : "\\\\(?:[^a-zA-Z]|[a-zA-Z]+)"
|
regex : "\\\\[a-zA-Z]+"
|
||||||
}, {
|
}, {
|
||||||
// Curly and square braces
|
// Curly and square braces
|
||||||
token : "lparen",
|
token : "lparen",
|
||||||
|
|
@ -19,18 +37,35 @@ var LatexHighlightRules = function() {
|
||||||
token : "rparen",
|
token : "rparen",
|
||||||
regex : "[\\])}]"
|
regex : "[\\])}]"
|
||||||
}, {
|
}, {
|
||||||
// Inline math between two $ symbols
|
// Escaped character (including new line)
|
||||||
token : "string",
|
token : "constant.character.escape",
|
||||||
regex : "\\$(?:(?:\\\\.)|(?:[^\\$\\\\]))*?\\$"
|
regex : "\\\\[^a-zA-Z]?"
|
||||||
}, {
|
}, {
|
||||||
// A comment. Tex comments start with % and go to
|
// An equation
|
||||||
// the end of the line
|
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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue