diff --git a/README.md b/README.md index 6ccfc082..da7a9a75 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,6 @@ There may also be some bugs. - Find a better way of testing. Create a test suite from scratch because most markdown compilers don't appear to be working properly in every aspect (but it's hard to tell because the markdown "spec" is so vague). -- Possibly alter rules to recognize arbitrary blocks of HTML better. - Recognize and parse paragraph list items better. - Add an explicit pretty printing and minification feature. diff --git a/lib/marked.js b/lib/marked.js index d3e6ff59..80c7d369 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -196,25 +196,25 @@ block.token = function(str, tokens, line) { */ var inline = { + escape: /^\\([\\`*{}\[\]()#+\-.!])/, autolink: /^<([^ >]+(:|@)[^ >]+)>/, tag: /^<[^\n>]+>/, - img: /^!\[([^\]]+)\]\(([^\s\)]+)\s*([^\)]*)\)/, - link: /^\[([^\]]+)\]\(([^\)]+)\)/, - reflink: /^\[([^\]]+)\]\[([^\]]+)\]/, + link: /^!?\[([^\]]+)\]\(([^\)]+)\)/, + reflink: /^!?\[([^\]]+)\]\[([^\]]+)\]/, strong: /^__([\s\S]+?)__|^\*\*([\s\S]+?)\*\*/, em: /^_([^_]+)_|^\*([^*]+)\*/, - escape: /^`([^`]+)`|^``([\s\S]+?)``/ + code: /^`([^`]+)`|^``([\s\S]+?)``/ }; inline.keys = [ + 'escape', 'autolink', 'tag', - 'img', 'link', 'reflink', 'strong', 'em', - 'escape' + 'code' ]; // hacky, but performant @@ -245,9 +245,10 @@ inline.text = (function(rules) { inline.lexer = function(str) { var out = '' , links = tokens.links - , link + , link = {} , text - , href; + , href + , val; var rules = inline , keys = inline.keys @@ -268,35 +269,52 @@ inline.lexer = function(str) { while (scan()) { switch (key) { + case 'escape': + out += cap[1]; + break; case 'tag': out += cap[0]; break; - case 'img': - out += '' + escape(cap[1])
-          + ''; - break; case 'link': case 'reflink': - link = links[cap[2]] || ''; - out += '' - + inline.lexer(cap[1]) - + ''; + if (cap[0][0] !== '!') { + if (key === 'reflink') { + link = links[cap[2]]; + } else { + link.href = cap[2]; + link.title = cap[3]; + } + out += '' + + inline.lexer(cap[1]) + + ''; + } else { + if (key === 'reflink') { + link = links[cap[2]]; + } else { + val = cap[2].match(/^([^\s]+)\s*(.+)?/); + link.href = val[1]; + link.title = val[2]; + } + out += '' 
+            + escape(cap[1])
+            + ''; + } break; case 'autolink': if (cap[2] === '@') { @@ -320,7 +338,7 @@ inline.lexer = function(str) { + inline.lexer(cap[2] || cap[1]) + ''; break; - case 'escape': + case 'code': out += '' + escape(cap[2] || cap[1]) + '';