From 81b1162240fb73bb1e6f1d0ea5284693487f469e Mon Sep 17 00:00:00 2001 From: Maksim Kryuchkov Date: Wed, 23 May 2018 21:55:16 +0300 Subject: [PATCH 1/2] r, python, javascript and css sections highlighted --- demo/spring-2018.html | 7 ++++- lib/ace/mode/markdown_highlight_rules.js | 37 +++++++++++------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/demo/spring-2018.html b/demo/spring-2018.html index dda5cc52d62..c9fb8bda097 100644 --- a/demo/spring-2018.html +++ b/demo/spring-2018.html @@ -56,6 +56,8 @@ # Header1 +Some text in our markdown file + ```{r} library(feather) library(ggplot2) @@ -89,6 +91,7 @@ ``` ```{js} +var a = "hello" $('.title').remove() ``` @@ -113,8 +116,10 @@ function(ace, langTools, katexPreviewer, highlighter, TexCompleter, Spellchecker, SpellcheckerPopup) { var editor = ace.edit("editor"); editor.$blockScrolling = Infinity; + // editor.setTheme("ace/theme/monokai"); var session = editor.getSession(); session.setMode("ace/mode/markdown"); + //alert("Mode Set"); session.setUseWorker(true); // SpellcheckerPopup.setup(editor); @@ -244,7 +249,7 @@ }); - + diff --git a/lib/ace/mode/markdown_highlight_rules.js b/lib/ace/mode/markdown_highlight_rules.js index 03f51bee62c..5ad1e603579 100644 --- a/lib/ace/mode/markdown_highlight_rules.js +++ b/lib/ace/mode/markdown_highlight_rules.js @@ -39,6 +39,7 @@ var XmlHighlightRules = require("./xml_highlight_rules").XmlHighlightRules; var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules; var CssHighlightRules = require("./css_highlight_rules").CssHighlightRules; var RHighlightRules = require("./r_highlight_rules").RHighlightRules; +var PythonHighlightRules = require("./python_highlight_rules").PythonHighlightRules; var escaped = function(ch) { return "(?:[^" + lang.escapeRegExp(ch) + "\\\\]|\\\\.)*"; @@ -47,8 +48,8 @@ var escaped = function(ch) { function github_embed(tag, prefix) { return { // Github style block token : "support.function", - regex : "^\\s*```" + tag + "\\s*$", - push : prefix + "start" + regex : "^\\s*```{" + tag + "}\\s*$", + next : prefix + "start" }; } @@ -75,9 +76,9 @@ var MarkdownHighlightRules = function() { next : "header" }, github_embed("(?:javascript|js)", "jscode-"), - github_embed("xml", "xmlcode-"), - github_embed("html", "htmlcode-"), github_embed("css", "csscode-"), + github_embed("r", "rcode-"), + github_embed("python", "pycode-"), { // Github style block token : "support.function", regex : "^\\s*```\\s*\\S*(?:{.*?\\})?\\s*$", @@ -198,28 +199,22 @@ var MarkdownHighlightRules = function() { } ] }); - this.embedRules(JavaScriptHighlightRules, "jscode-", [{ - token : "support.function", - regex : "^\\s*```", - next : "pop" - }]); - - this.embedRules(HtmlHighlightRules, "htmlcode-", [{ - token : "support.function", - regex : "^\\s*```", - next : "pop" + this.embedRules(CssHighlightRules, "csscode-", [{ + token: "support.function", + regex: "^```\\s*$", + next: "start" }]); - this.embedRules(CssHighlightRules, "csscode-", [{ + this.embedRules(JavaScriptHighlightRules, "jscode-", [{ token : "support.function", - regex : "^\\s*```", - next : "pop" + regex : "^```\\s*$", + next : "start" }]); - this.embedRules(XmlHighlightRules, "xmlcode-", [{ + this.embedRules(PythonHighlightRules, "pycode-", [{ token : "support.function", - regex : "^\\s*```", - next : "pop" + regex : "^```\\s*$", + next : "start" }]); this.embedRules(RHighlightRules, "rcode-", [{ @@ -230,7 +225,9 @@ var MarkdownHighlightRules = function() { this.normalizeRules(); }; + oop.inherits(MarkdownHighlightRules, TextHighlightRules); exports.MarkdownHighlightRules = MarkdownHighlightRules; + }); From 786b17eead4120353434be92fb0f73228127e72b Mon Sep 17 00:00:00 2001 From: Maksim Kryuchkov Date: Wed, 23 May 2018 22:49:45 +0300 Subject: [PATCH 2/2] unnessecary changes canceled --- lib/ace/mode/markdown_highlight_rules.js | 40 +++++++++++++++--------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/lib/ace/mode/markdown_highlight_rules.js b/lib/ace/mode/markdown_highlight_rules.js index 5ad1e603579..9d452bd1040 100644 --- a/lib/ace/mode/markdown_highlight_rules.js +++ b/lib/ace/mode/markdown_highlight_rules.js @@ -49,7 +49,7 @@ function github_embed(tag, prefix) { return { // Github style block token : "support.function", regex : "^\\s*```{" + tag + "}\\s*$", - next : prefix + "start" + push : prefix + "start" }; } @@ -76,9 +76,11 @@ var MarkdownHighlightRules = function() { next : "header" }, github_embed("(?:javascript|js)", "jscode-"), + github_embed("xml", "xmlcode-"), + github_embed("html", "htmlcode-"), github_embed("css", "csscode-"), - github_embed("r", "rcode-"), github_embed("python", "pycode-"), + github_embed("r", "rcode-"), { // Github style block token : "support.function", regex : "^\\s*```\\s*\\S*(?:{.*?\\})?\\s*$", @@ -199,22 +201,28 @@ var MarkdownHighlightRules = function() { } ] }); - this.embedRules(CssHighlightRules, "csscode-", [{ - token: "support.function", - regex: "^```\\s*$", - next: "start" + this.embedRules(JavaScriptHighlightRules, "jscode-", [{ + token : "support.function", + regex : "^\\s*```", + next : "pop" }]); - this.embedRules(JavaScriptHighlightRules, "jscode-", [{ + this.embedRules(HtmlHighlightRules, "htmlcode-", [{ token : "support.function", - regex : "^```\\s*$", - next : "start" + regex : "^\\s*```", + next : "pop" }]); - this.embedRules(PythonHighlightRules, "pycode-", [{ + this.embedRules(CssHighlightRules, "csscode-", [{ token : "support.function", - regex : "^```\\s*$", - next : "start" + regex : "^\\s*```", + next : "pop" + }]); + + this.embedRules(XmlHighlightRules, "xmlcode-", [{ + token : "support.function", + regex : "^\\s*```", + next : "pop" }]); this.embedRules(RHighlightRules, "rcode-", [{ @@ -223,11 +231,15 @@ var MarkdownHighlightRules = function() { next : "pop" }]); + this.embedRules(PythonHighlightRules, "pycode-", [{ + token : "support.function", + regex : "^\\s*```", + next : "pop" + }]); + this.normalizeRules(); }; - oop.inherits(MarkdownHighlightRules, TextHighlightRules); exports.MarkdownHighlightRules = MarkdownHighlightRules; - });