Added LaTeX syntax highlighting in the editor
This commit is contained in:
parent
d73f789f73
commit
6c8de21321
@ -202,6 +202,7 @@ define([
|
||||
_.each(previewContentsElt.children, function(elt) {
|
||||
html += elt.innerHTML;
|
||||
});
|
||||
html = html.replace(/^<div class="se-section-delimiter"><\/div>\n\n/gm, '');
|
||||
onPreviewFinished(utils.trim(html));
|
||||
});
|
||||
};
|
||||
|
@ -25,9 +25,9 @@ define([
|
||||
}
|
||||
if(mathJax.config.enabled) {
|
||||
// Math delimiter has to follow 1 empty line to be considered as a section delimiter
|
||||
regexp = '^[ \\t]*\\n[ \\t]*\\$\\$[\\s\\S]*\\$\\$|' + regexp; // $$ math delimiters
|
||||
regexp = '^[ \\t]*\\n[ \\t]*\\\\\\\\\\[[\\s\\S]*\\\\\\\\\\]|' + regexp; // \\[ \\] math delimiters
|
||||
regexp = '^[ \\t]*\\n[ \\t]*\\\\\\\\begin\\{[a-z]*\\*?\\}[\\s\\S]*\\\\\\\\end\\{[a-z]*\\*?\\}|' + regexp; // \\begin{...} \\end{...} math delimiters
|
||||
regexp = '^[ \\t]*\\n[ \\t]*\\$\\$[\\s\\S]*?\\$\\$|' + regexp; // $$ math delimiters
|
||||
regexp = '^[ \\t]*\\n[ \\t]*\\\\\\\\[[\\s\\S]*?\\\\\\\\]|' + regexp; // \\[ \\] math delimiters
|
||||
regexp = '^[ \\t]*\\n[ \\t]*\\\\?\\\\begin\\{[a-z]*\\*?\\}[\\s\\S]*?\\\\end\\{[a-z]*\\*?\\}|' + regexp; // \\begin{...} \\end{...} math delimiters
|
||||
}
|
||||
regexp = new RegExp(regexp, 'gmi');
|
||||
|
||||
|
@ -56,10 +56,10 @@ define([
|
||||
htmlSectionList = [];
|
||||
var htmlSectionOffset;
|
||||
var previewScrollTop = $previewElt.scrollTop();
|
||||
$previewElt.find(".preview-content > .se-section-delimiter + *").each(function() {
|
||||
$previewElt.find(".preview-content > .se-section-delimiter").each(function() {
|
||||
var $delimiterElt = $(this);
|
||||
// Consider div scroll position and header element top margin
|
||||
var newSectionOffset = $delimiterElt.position().top + previewScrollTop + pxToFloat($delimiterElt.css('margin-top'));
|
||||
// Consider div scroll position
|
||||
var newSectionOffset = $delimiterElt.position().top + previewScrollTop;
|
||||
if(htmlSectionOffset !== undefined) {
|
||||
htmlSectionList.push({
|
||||
startOffset: htmlSectionOffset,
|
||||
|
@ -33,6 +33,7 @@ define(function(require, exports, module) {
|
||||
|
||||
var oop = require("ace/lib/oop");
|
||||
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
|
||||
var LatexHighlightRules = require("ace/mode/latex_highlight_rules").LatexHighlightRules;
|
||||
|
||||
var MarkdownHighlightRules = function() {
|
||||
|
||||
@ -40,7 +41,18 @@ var MarkdownHighlightRules = function() {
|
||||
// regexps are ordered -> the first match is used
|
||||
|
||||
this.$rules = {
|
||||
"basic" : [{
|
||||
"basic" : [{ // Math inline
|
||||
token : ["constant.language.escape", "keyword", "constant.language.escape"],
|
||||
regex : "(\\$)(.*)(\\$)"
|
||||
}, { // Math block
|
||||
token : "constant.language.escape",
|
||||
regex : "\\$\\$|\\\\\\\\\\[|\\\\\\\\\\\\\\\\\\(",
|
||||
next : "mathblock"
|
||||
}, { // LaTeX block
|
||||
token : "keyword",
|
||||
regex : "\\\\?\\\\begin\\{[a-z]*\\*?\\}",
|
||||
next : "latexblock"
|
||||
}, {
|
||||
token : "constant.language.escape",
|
||||
regex : /\\[\\`*_{}\[\]()#+\-.!]/
|
||||
}, { // code span `
|
||||
@ -163,7 +175,42 @@ var MarkdownHighlightRules = function() {
|
||||
}, {
|
||||
token : "code_block",
|
||||
regex : ".+"
|
||||
} ]
|
||||
} ],
|
||||
|
||||
"mathblock" : [ {
|
||||
token : "constant.language.escape",
|
||||
regex : "\\$\\$|\\\\\\\\\\]|\\\\\\\\\\\\\\\\\\)",
|
||||
next : "basic"
|
||||
}, {
|
||||
include : "latex"
|
||||
} ],
|
||||
|
||||
"latexblock" : [{
|
||||
token : "keyword",
|
||||
regex : "\\\\?\\\\end\\{[a-z]*\\*?\\}",
|
||||
next : "basic"
|
||||
}, {
|
||||
include : "latex"
|
||||
}],
|
||||
|
||||
"latex" : [{
|
||||
// A tex command e.g. \foo
|
||||
token : "keyword",
|
||||
regex : "\\\\(?:[^a-zA-Z]|[a-zA-Z]+)"
|
||||
}, {
|
||||
// Curly and square braces
|
||||
token : "lparen",
|
||||
regex : "[[({]"
|
||||
}, {
|
||||
// Curly and square braces
|
||||
token : "rparen",
|
||||
regex : "[\\])}]"
|
||||
}, {
|
||||
// A comment. Tex comments start with % and go to
|
||||
// the end of the line
|
||||
token : "comment",
|
||||
regex : "%.*$"
|
||||
}]
|
||||
};
|
||||
|
||||
this.normalizeRules();
|
||||
|
@ -999,6 +999,16 @@ ul,ol {
|
||||
color: @primary-color-lightest;
|
||||
}
|
||||
|
||||
.ace_constant.ace_language {
|
||||
color: @primary-color-lightest;
|
||||
}
|
||||
|
||||
.ace_keyword {
|
||||
color: @primary-color;
|
||||
background-color: @code-bg;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.ace_strong {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user