fix #1533 syntax highlighting of markdown links

This commit is contained in:
nightwing 2013-07-26 14:55:08 +04:00
commit ca1c27aa65
3 changed files with 33 additions and 9 deletions

View file

@ -14,7 +14,7 @@ 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/) * [demo](http://ajaxorg.github.com/ace/) [+](escape(\) ) [+](a "title") [+](a "space" )
* usually *work* fine (_em_) * usually *work* fine (_em_)
in lists in lists

View file

@ -64,7 +64,26 @@
["text","]("], ["text","]("],
["markup.underline","http://ajaxorg.github.com/ace/"], ["markup.underline","http://ajaxorg.github.com/ace/"],
["text",")"], ["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", "listblock",
["markup.list","* "], ["markup.list","* "],

View file

@ -32,12 +32,17 @@ define(function(require, exports, module) {
"use strict"; "use strict";
var oop = require("../lib/oop"); var oop = require("../lib/oop");
var lang = require("../lib/lang");
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules; var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules;
var XmlHighlightRules = require("./xml_highlight_rules").XmlHighlightRules; var XmlHighlightRules = require("./xml_highlight_rules").XmlHighlightRules;
var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules; var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules;
var CssHighlightRules = require("./css_highlight_rules").CssHighlightRules; var CssHighlightRules = require("./css_highlight_rules").CssHighlightRules;
var escaped = function(ch) {
return "(?:[^" + lang.escapeRegExp(ch) + "\\\\]|\\\\.)*";
}
function github_embed(tag, prefix) { function github_embed(tag, prefix) {
return { // Github style block return { // Github style block
token : "support.function", token : "support.function",
@ -104,15 +109,15 @@ var MarkdownHighlightRules = function() {
regex : "^([ ]{0,3}\\[)([^\\]]+)(\\]:\\s*)([^ ]+)(\\s*(?:[\"][^\"]+[\"])?(\\s*))$" regex : "^([ ]{0,3}\\[)([^\\]]+)(\\]:\\s*)([^ ]+)(\\s*(?:[\"][^\"]+[\"])?(\\s*))$"
}, { // link by reference }, { // link by reference
token : ["text", "string", "text", "constant", "text"], token : ["text", "string", "text", "constant", "text"],
regex : "(\\[)((?:[[^\\]]*\\]|[^\\[\\]])*)(\\][ ]?(?:\\n[ ]*)?\\[)(.*?)(\\])" regex : "(\\[)(" + escaped("]") + ")(\\]\s*\\[)("+ escaped("]") + ")(\\])"
}, { // link by url }, { // link by url
token : ["text", "string", "text", "markup.underline", "string", "text"], token : ["text", "string", "text", "markup.underline", "string", "text"],
regex : "(\\[)"+ regex : "(\\[)(" + // [
"(\\[[^\\]]*\\]|[^\\[\\]]*)"+ escaped("]") + // link text
"(\\]\\([ \\t]*)"+ ")(\\]\\()"+ // ](
"(<?(?:(?:[^\\(]*?\\([^\\)]*?\\)\\S*?)|(?:.*?))>?)"+ '((?:[^\\)\\s\\\\]|\\\\.|\\s(?=[^"]))*)' + // href
"((?:[ \t]*\"(?:.*?)\"[ \\t]*)?)"+ '(\\s*"' + escaped('"') + '"\\s*)?' + // "title"
"(\\))" "(\\))" // )
}, { // strong ** __ }, { // strong ** __
token : "string", token : "string",
regex : "([*]{2}|[_]{2}(?=\\S))(.*?\\S[*_]*)(\\1)" regex : "([*]{2}|[_]{2}(?=\\S))(.*?\\S[*_]*)(\\1)"