From 13e74ea86c5e17c7b00e81a1a4c85b81c1fb150e Mon Sep 17 00:00:00 2001 From: Grant Gayed Date: Tue, 14 Oct 2014 16:13:50 -0400 Subject: [PATCH 1/2] create tokens for encountered link definitions --- lib/marked.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/marked.js b/lib/marked.js index 142eccf00a..ba9636123e 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -372,6 +372,11 @@ Lexer.prototype.token = function(src, top, bq) { href: cap[2], title: cap[3] }; + this.tokens.push({ + type: 'def', + href: cap[2], + title: cap[3] + }); continue; } @@ -781,6 +786,10 @@ Renderer.prototype.blockquote = function(quote) { return '
\n' + quote + '
\n'; }; +Renderer.prototype.def = function(href, title) { + return ''; +}; + Renderer.prototype.html = function(html) { return html; }; @@ -966,6 +975,11 @@ Parser.prototype.tok = function() { case 'space': { return ''; } + case 'def': { + return this.renderer.def( + this.token.href, + this.token.title); + } case 'hr': { return this.renderer.hr(); } From d8e0e3dc3df5394207ff0b74bce86ec479cd8758 Mon Sep 17 00:00:00 2001 From: Grant Gayed Date: Wed, 15 Oct 2014 14:28:47 -0400 Subject: [PATCH 2/2] include the id in link definition tokens --- lib/marked.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index ba9636123e..b3cc2f38cc 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -368,12 +368,14 @@ Lexer.prototype.token = function(src, top, bq) { // def if ((!bq && top) && (cap = this.rules.def.exec(src))) { src = src.substring(cap[0].length); - this.tokens.links[cap[1].toLowerCase()] = { + var id = cap[1].toLowerCase(); + this.tokens.links[id] = { href: cap[2], title: cap[3] }; this.tokens.push({ type: 'def', + id: id, href: cap[2], title: cap[3] }); @@ -786,7 +788,7 @@ Renderer.prototype.blockquote = function(quote) { return '
\n' + quote + '
\n'; }; -Renderer.prototype.def = function(href, title) { +Renderer.prototype.def = function(id, href, title) { return ''; }; @@ -977,6 +979,7 @@ Parser.prototype.tok = function() { } case 'def': { return this.renderer.def( + this.token.id, this.token.href, this.token.title); }