From 1d9e3f431c503711cae266f79b967195f456133d Mon Sep 17 00:00:00 2001 From: Daniel Felder Date: Tue, 19 Aug 2014 22:33:09 +0200 Subject: [PATCH] Latex mode for ace has new syntax highlighting This is an update to the latest version. --- services/web/public/js/ace/mode-latex.js | 56 +++++++++++++++++++----- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/services/web/public/js/ace/mode-latex.js b/services/web/public/js/ace/mode-latex.js index 57d60db389..dd8194c1cd 100644 --- a/services/web/public/js/ace/mode-latex.js +++ b/services/web/public/js/ace/mode-latex.js @@ -4,11 +4,24 @@ ace.define("ace/mode/latex_highlight_rules",["require","exports","module","ace/l var oop = require("../lib/oop"); var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; -var LatexHighlightRules = function() { +var LatexHighlightRules = function() { + this.$rules = { "start" : [{ - token : "keyword", - regex : "\\\\(?:[^a-zA-Z]|[a-zA-Z]+)" + token : "comment", + 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", regex : "[[({]" @@ -16,15 +29,33 @@ var LatexHighlightRules = function() { token : "rparen", regex : "[\\])}]" }, { - token : "string", - regex : "\\$(?:(?:\\\\.)|(?:[^\\$\\\\]))*?\\$" + token : "constant.character.escape", + regex : "\\\\[^a-zA-Z]?" }, { + token : "string", + regex : "\\${1,2}", + next : "equation" + }], + "equation" : [{ token : "comment", 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); exports.LatexHighlightRules = LatexHighlightRules; @@ -45,7 +76,7 @@ oop.inherits(FoldMode, BaseFoldMode); (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.getFoldWidgetRange = function(session, foldStyle, row) { @@ -77,7 +108,7 @@ oop.inherits(FoldMode, BaseFoldMode); var stream = new TokenIterator(session, row, column); var token = stream.getCurrentToken(); - if (!token || token.type !== "keyword") + if (!token || !(token.type == "storage.type" || token.type == "constant.character.escape")) return; var val = token.value; @@ -99,7 +130,7 @@ oop.inherits(FoldMode, BaseFoldMode); stream.step = dir === -1 ? stream.stepBackward : stream.stepForward; while(token = stream.step()) { - if (token.type !== "keyword") + if (!token || !(token.type == "storage.type" || token.type == "constant.character.escape")) continue; var level = keywords[token.value]; if (!level) @@ -122,11 +153,11 @@ oop.inherits(FoldMode, BaseFoldMode); }; 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 token = stream.getCurrentToken(); - if (!token || token.type != "keyword") + if (!token || token.type != "storage.type") return; var startLevel = keywords.indexOf(token.value); @@ -134,7 +165,7 @@ oop.inherits(FoldMode, BaseFoldMode); var endRow = row; while(token = stream.stepForward()) { - if (token.type !== "keyword") + if (token.type !== "storage.type") continue; var level = keywords.indexOf(token.value); @@ -181,6 +212,7 @@ oop.inherits(Mode, TextMode); (function() { this.type = "text"; + this.lineCommentStart = "%"; this.$id = "ace/mode/latex";