diff --git a/lib/plugin/github.js b/lib/plugin/github.js index eb41e26..f9ac40b 100644 --- a/lib/plugin/github.js +++ b/lib/plugin/github.js @@ -37,7 +37,10 @@ function replaceTagAttribute (html, tag, attribute, buildUrl, repository) { // Skip fully-qualified URLs, #hash fragments, and protocol-relative URLs if (!url.host && url.path && !url.path.match(/^\/\//)) { var newUrl = buildUrl(repository, url) - return html.slice(0, attr.index) + attr[0] + quote + newUrl + quote + substring.slice(src[0].length + 1) + var htmlPrefix = html.slice(0, attr.index) + attr[0] + quote + newUrl + quote + var htmlPostfix = substring.slice(src[0].length + 1) + var processedPostfix = replaceTagAttribute(htmlPostfix, tag, attribute, buildUrl, repository) + return htmlPrefix + (processedPostfix || htmlPostfix) } } } diff --git a/test/fixtures/github.md b/test/fixtures/github.md index 729a563..348b0b5 100644 --- a/test/fixtures/github.md +++ b/test/fixtures/github.md @@ -55,6 +55,9 @@ Smiley! :) # Heading with nested image/link: . Nice. +
+ -

Link in an HTML block

+

Link in an HTML block +and second link

diff --git a/test/repo-github.js b/test/repo-github.js index 18aede6..3b029d2 100644 --- a/test/repo-github.js +++ b/test/repo-github.js @@ -49,10 +49,13 @@ describe('when package repo is on github', function () { it('rewrites slashy relative links hrefs to absolute (HTML)', function () { assert(~fixtures.github.indexOf('')) assert(~fixtures.github.indexOf('Link in an HTML block')) + assert(~fixtures.github.indexOf('second link')) assert($("a[href='https://github.com/mark/wahlberg/blob/HEAD/nested/link/image']").length) assert($("a[href='https://github.com/mark/wahlberg/blob/HEAD/html/block.html']").length) + assert($("a[href='https://github.com/mark/wahlberg/blob/HEAD/html/block2.html']").length) assert($short("a[href='https://github.com/mark/wahlberg/blob/HEAD/nested/link/image']").length) assert($short("a[href='https://github.com/mark/wahlberg/blob/HEAD/html/block.html']").length) + assert($short("a[href='https://github.com/mark/wahlberg/blob/HEAD/html/block2.html']").length) }) it('leaves protocol-relative URLs alone', function () { @@ -101,10 +104,13 @@ describe('when package repo is on github', function () { it('replaces slashy relative img URLs with github URLs (HTML)', function () { assert(~fixtures.github.indexOf('')) assert(~fixtures.github.indexOf('')) + assert(~fixtures.github.indexOf('')) assert($("img[src='https://raw.githubusercontent.com/mark/wahlberg/HEAD/nested/link/image/image.png']").length) assert($("img[src='https://raw.githubusercontent.com/mark/wahlberg/HEAD/html/block.png']").length) + assert($("img[src='https://raw.githubusercontent.com/mark/wahlberg/HEAD/html/block2.png']").length) assert($short("img[src='https://raw.githubusercontent.com/mark/wahlberg/HEAD/nested/link/image/image.png']").length) assert($short("img[src='https://raw.githubusercontent.com/mark/wahlberg/HEAD/html/block.png']").length) + assert($short("img[src='https://raw.githubusercontent.com/mark/wahlberg/HEAD/html/block2.png']").length) }) it('leaves protocol relative URLs alone', function () {