From ca1c27aa651eac75ec28de6fd77f9ecf47f8e76b Mon Sep 17 00:00:00 2001 From: nightwing Date: Fri, 26 Jul 2013 14:55:08 +0400 Subject: [PATCH] fix #1533 syntax highlighting of markdown links --- lib/ace/mode/_test/text_markdown.txt | 2 +- lib/ace/mode/_test/tokens_markdown.json | 21 ++++++++++++++++++++- lib/ace/mode/markdown_highlight_rules.js | 19 ++++++++++++------- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/lib/ace/mode/_test/text_markdown.txt b/lib/ace/mode/_test/text_markdown.txt index ecaa01b9..0450c820 100644 --- a/lib/ace/mode/_test/text_markdown.txt +++ b/lib/ace/mode/_test/text_markdown.txt @@ -14,7 +14,7 @@ test: only space between #s is not a valid header # # # test links [Cloud9 IDE](http://www.c9.io/) # -* [demo](http://ajaxorg.github.com/ace/) +* [demo](http://ajaxorg.github.com/ace/) [+](escape(\) ) [+](a "title") [+](a "space" ) * usually *work* fine (_em_) in lists diff --git a/lib/ace/mode/_test/tokens_markdown.json b/lib/ace/mode/_test/tokens_markdown.json index 37edf183..3c0db62f 100644 --- a/lib/ace/mode/_test/tokens_markdown.json +++ b/lib/ace/mode/_test/tokens_markdown.json @@ -64,7 +64,26 @@ ["text","]("], ["markup.underline","http://ajaxorg.github.com/ace/"], ["text",")"], - ["list"," "] + ["list"," "], + ["text","["], + ["string","+"], + ["text","]("], + ["markup.underline","escape(\\) "], + ["text",")"], + ["list"," "], + ["text","["], + ["string","+"], + ["text","]("], + ["markup.underline","a"], + ["string"," \"title\""], + ["text",")"], + ["list"," "], + ["text","["], + ["string","+"], + ["text","]("], + ["markup.underline","a"], + ["string"," \"space\" "], + ["text",")"] ],[ "listblock", ["markup.list","* "], diff --git a/lib/ace/mode/markdown_highlight_rules.js b/lib/ace/mode/markdown_highlight_rules.js index cf1457c1..4e07edff 100644 --- a/lib/ace/mode/markdown_highlight_rules.js +++ b/lib/ace/mode/markdown_highlight_rules.js @@ -32,12 +32,17 @@ define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); +var lang = require("../lib/lang"); var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules; var XmlHighlightRules = require("./xml_highlight_rules").XmlHighlightRules; var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules; var CssHighlightRules = require("./css_highlight_rules").CssHighlightRules; +var escaped = function(ch) { + return "(?:[^" + lang.escapeRegExp(ch) + "\\\\]|\\\\.)*"; +} + function github_embed(tag, prefix) { return { // Github style block token : "support.function", @@ -104,15 +109,15 @@ var MarkdownHighlightRules = function() { regex : "^([ ]{0,3}\\[)([^\\]]+)(\\]:\\s*)([^ ]+)(\\s*(?:[\"][^\"]+[\"])?(\\s*))$" }, { // link by reference token : ["text", "string", "text", "constant", "text"], - regex : "(\\[)((?:[[^\\]]*\\]|[^\\[\\]])*)(\\][ ]?(?:\\n[ ]*)?\\[)(.*?)(\\])" + regex : "(\\[)(" + escaped("]") + ")(\\]\s*\\[)("+ escaped("]") + ")(\\])" }, { // link by url token : ["text", "string", "text", "markup.underline", "string", "text"], - regex : "(\\[)"+ - "(\\[[^\\]]*\\]|[^\\[\\]]*)"+ - "(\\]\\([ \\t]*)"+ - "(?)"+ - "((?:[ \t]*\"(?:.*?)\"[ \\t]*)?)"+ - "(\\))" + regex : "(\\[)(" + // [ + escaped("]") + // link text + ")(\\]\\()"+ // ]( + '((?:[^\\)\\s\\\\]|\\\\.|\\s(?=[^"]))*)' + // href + '(\\s*"' + escaped('"') + '"\\s*)?' + // "title" + "(\\))" // ) }, { // strong ** __ token : "string", regex : "([*]{2}|[_]{2}(?=\\S))(.*?\\S[*_]*)(\\1)"