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) {
|
_.each(previewContentsElt.children, function(elt) {
|
||||||
html += elt.innerHTML;
|
html += elt.innerHTML;
|
||||||
});
|
});
|
||||||
|
html = html.replace(/^<div class="se-section-delimiter"><\/div>\n\n/gm, '');
|
||||||
onPreviewFinished(utils.trim(html));
|
onPreviewFinished(utils.trim(html));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -25,9 +25,9 @@ define([
|
|||||||
}
|
}
|
||||||
if(mathJax.config.enabled) {
|
if(mathJax.config.enabled) {
|
||||||
// Math delimiter has to follow 1 empty line to be considered as a section delimiter
|
// 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]*\\\\\\\\\\[[\\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]*\\\\?\\\\begin\\{[a-z]*\\*?\\}[\\s\\S]*?\\\\end\\{[a-z]*\\*?\\}|' + regexp; // \\begin{...} \\end{...} math delimiters
|
||||||
}
|
}
|
||||||
regexp = new RegExp(regexp, 'gmi');
|
regexp = new RegExp(regexp, 'gmi');
|
||||||
|
|
||||||
|
@ -56,10 +56,10 @@ define([
|
|||||||
htmlSectionList = [];
|
htmlSectionList = [];
|
||||||
var htmlSectionOffset;
|
var htmlSectionOffset;
|
||||||
var previewScrollTop = $previewElt.scrollTop();
|
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);
|
var $delimiterElt = $(this);
|
||||||
// Consider div scroll position and header element top margin
|
// Consider div scroll position
|
||||||
var newSectionOffset = $delimiterElt.position().top + previewScrollTop + pxToFloat($delimiterElt.css('margin-top'));
|
var newSectionOffset = $delimiterElt.position().top + previewScrollTop;
|
||||||
if(htmlSectionOffset !== undefined) {
|
if(htmlSectionOffset !== undefined) {
|
||||||
htmlSectionList.push({
|
htmlSectionList.push({
|
||||||
startOffset: htmlSectionOffset,
|
startOffset: htmlSectionOffset,
|
||||||
|
@ -33,6 +33,7 @@ define(function(require, exports, module) {
|
|||||||
|
|
||||||
var oop = require("ace/lib/oop");
|
var oop = require("ace/lib/oop");
|
||||||
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
|
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
|
||||||
|
var LatexHighlightRules = require("ace/mode/latex_highlight_rules").LatexHighlightRules;
|
||||||
|
|
||||||
var MarkdownHighlightRules = function() {
|
var MarkdownHighlightRules = function() {
|
||||||
|
|
||||||
@ -40,7 +41,18 @@ var MarkdownHighlightRules = function() {
|
|||||||
// regexps are ordered -> the first match is used
|
// regexps are ordered -> the first match is used
|
||||||
|
|
||||||
this.$rules = {
|
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",
|
token : "constant.language.escape",
|
||||||
regex : /\\[\\`*_{}\[\]()#+\-.!]/
|
regex : /\\[\\`*_{}\[\]()#+\-.!]/
|
||||||
}, { // code span `
|
}, { // code span `
|
||||||
@ -163,7 +175,42 @@ var MarkdownHighlightRules = function() {
|
|||||||
}, {
|
}, {
|
||||||
token : "code_block",
|
token : "code_block",
|
||||||
regex : ".+"
|
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();
|
this.normalizeRules();
|
||||||
|
@ -999,6 +999,16 @@ ul,ol {
|
|||||||
color: @primary-color-lightest;
|
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 {
|
.ace_strong {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user