From df706e570641dbef7b2ad44a1853b56b8713b274 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 17 Feb 2013 00:20:47 +0400 Subject: [PATCH] fix link highlighting in markdown headers --- lib/ace/mode/_test/text_markdown.txt | 5 +++-- lib/ace/mode/_test/tokens_markdown.json | 21 +++++++++++++++------ lib/ace/mode/markdown_highlight_rules.js | 16 +++++++++++++--- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/lib/ace/mode/_test/text_markdown.txt b/lib/ace/mode/_test/text_markdown.txt index 40688776..f3c044c6 100644 --- a/lib/ace/mode/_test/text_markdown.txt +++ b/lib/ace/mode/_test/text_markdown.txt @@ -12,8 +12,9 @@ test: # followed be only space is not a valid header test: only space between #s is not a valid header # # -test links [Cloud9 IDE](http://www.c9.io/) +# test links [Cloud9 IDE](http://www.c9.io/) # * [demo](http://ajaxorg.github.com/ace/) in lists -in plain text http://ace.ajaxorg.com \ No newline at end of file +in plain text http://ace.ajaxorg.com + diff --git a/lib/ace/mode/_test/tokens_markdown.json b/lib/ace/mode/_test/tokens_markdown.json index 4fb6af81..63a9650e 100644 --- a/lib/ace/mode/_test/tokens_markdown.json +++ b/lib/ace/mode/_test/tokens_markdown.json @@ -3,25 +3,29 @@ ["text","test: header 1 "] ],[ "start", - ["markup.heading.1","#f"] + ["markup.heading.1","#"], + ["markup.heading","f"] ],[ "start", ["text","test: header 2"] ],[ "start", - ["markup.heading.2","## foo"] + ["markup.heading.2","##"], + ["markup.heading"," foo"] ],[ "start", ["text","test: header ends with ' #'"] ],[ "start", - ["markup.heading.1","# # # "] + ["markup.heading.1","#"], + ["markup.heading"," # # "] ],[ "start", ["text","test: header ends with '#'"] ],[ "start", - ["markup.heading.1","#foo# "] + ["markup.heading.1","#"], + ["markup.heading","foo# "] ],[ "start", ["text","test: 6+ #s is not a valid header"] @@ -41,13 +45,14 @@ "allowBlock" ],[ "start", - ["text","test links "], + ["markup.heading.1","#"], + ["markup.heading"," test links "], ["text","["], ["string","Cloud9 IDE"], ["text","]("], ["markup.underline","http://www.c9.io/"], ["text",")"], - ["text"," "] + ["markup.heading"," #"] ],[ "listblock", ["markup.list","* "], @@ -72,4 +77,8 @@ ["meta.tag","<"], ["meta.tag.tag-name","b"], ["meta.tag.r",">"] +],[ + "allowBlock" +],[ + "start" ]] \ No newline at end of file diff --git a/lib/ace/mode/markdown_highlight_rules.js b/lib/ace/mode/markdown_highlight_rules.js index 6a62d7e1..39b95fc8 100644 --- a/lib/ace/mode/markdown_highlight_rules.js +++ b/lib/ace/mode/markdown_highlight_rules.js @@ -100,11 +100,12 @@ var MarkdownHighlightRules = function() { }, { // h2 token: "markup.heading.2", regex: "^\\-+(?=\\s*$)" - }, { // header + }, { token : function(value) { - return "markup.heading." + value.search(/[^#]/); + return "markup.heading." + value.length; }, - regex : "^#{1,6}(?:[^ #].*| +.*(?:[^ #].*|[^ ]+.* +#+ *))$" + regex : /^#{1,6}(?=\s*[^ #]|\s+#.)/, + next : "header" }, github_embed("(?:javascript|js)", "js-"), github_embed("xml", "xml-"), @@ -129,6 +130,15 @@ var MarkdownHighlightRules = function() { }, { include : "basic" }], + + "header" : [{ + regex: "$", + next : "start" + }, { + include: "basic" + }, { + defaultToken : "markup.heading" + } ], "listblock-start" : [{ token : "support.variable",