diff --git a/public/res/eventMgr.js b/public/res/eventMgr.js index 0358b855..39c50528 100644 --- a/public/res/eventMgr.js +++ b/public/res/eventMgr.js @@ -202,6 +202,7 @@ define([ _.each(previewContentsElt.children, function(elt) { html += elt.innerHTML; }); + html = html.replace(/^
<\/div>\n\n/gm, ''); onPreviewFinished(utils.trim(html)); }); }; diff --git a/public/res/extensions/markdownSectionParser.js b/public/res/extensions/markdownSectionParser.js index 1a440bdd..16f71eed 100644 --- a/public/res/extensions/markdownSectionParser.js +++ b/public/res/extensions/markdownSectionParser.js @@ -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'); diff --git a/public/res/extensions/scrollLink.js b/public/res/extensions/scrollLink.js index 910c7c4f..e7c9657f 100644 --- a/public/res/extensions/scrollLink.js +++ b/public/res/extensions/scrollLink.js @@ -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, diff --git a/public/res/libs/ace_mode_highlight_rules.js b/public/res/libs/ace_mode_highlight_rules.js index d94cb744..ec35c9da 100644 --- a/public/res/libs/ace_mode_highlight_rules.js +++ b/public/res/libs/ace_mode_highlight_rules.js @@ -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(); diff --git a/public/res/styles/main.less b/public/res/styles/main.less index 8cdf95ab..942cb1ac 100644 --- a/public/res/styles/main.less +++ b/public/res/styles/main.less @@ -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; }