diff --git a/package.json b/package.json index d1fc3e2d..963aabdf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "linkifyjs", - "version": "2.0.0-beta.6", + "version": "2.0.0-beta.7", "description": "Intelligent link recognition, made easy", "repository": { "type": "git", diff --git a/src/linkify-html.js b/src/linkify-html.js index 0f3e8488..29661423 100644 --- a/src/linkify-html.js +++ b/src/linkify-html.js @@ -24,10 +24,10 @@ export default function linkifyHtml(str, opts={}) { if (token.type === StartTag && token.tagName.toUpperCase() === 'A') { // Ignore all the contents of an anchor tag + linkifiedTokens.push(token); let preskipLen = linkifiedTokens.length; - skipTokens('A', tokens, ++i, linkifiedTokens); - - i += linkifiedTokens.length - preskipLen; + skipTagTokens('A', tokens, ++i, linkifiedTokens); + i += linkifiedTokens.length - preskipLen - 1; continue; } else if (token.type !== Chars) { diff --git a/test/spec/linkify-html-test.js b/test/spec/linkify-html-test.js index 6d323abc..422628b6 100644 --- a/test/spec/linkify-html-test.js +++ b/test/spec/linkify-html-test.js @@ -3,12 +3,74 @@ var htmlOptions = require('./html/options'); describe('linkify-html', function () { + var options = { // test options + tagName: 'span', + target: '_parent', + nl2br: true, + linkClass: 'my-linkify-class', + defaultProtocol: 'https', + linkAttributes: { + rel: 'nofollow', + onclick: 'javascript:;' + }, + format: function (val) { + return val.truncate(40); + }, + formatHref: function (href, type) { + if (type === 'email') { + href += '?subject=Hello%20from%20Linkify'; + } + return href; + } + }, + + // For each element in this array + // [0] - Original text + // [1] - Linkified with default options + // [2] - Linkified with new options + tests = [ + [ + 'Test with no links', + 'Test with no links', + 'Test with no links' + ], [ + 'The URL is google.com and the email is test@example.com', + 'The URL is google.com and the email is test@example.com', + 'The URL is google.com and the email is test@example.com' + ], [ + 'Super long maps URL https://www.google.ca/maps/@43.472082,-80.5426668,18z?hl=en, a #hash-tag, and an email: test."wut".yo@gmail.co.uk!', + 'Super long maps URL https://www.google.ca/maps/@43.472082,-80.5426668,18z?hl=en, a #hash-tag, and an email: test."wut".yo@gmail.co.uk!', + 'Super long maps URL https://www.google.ca/maps/@43.472082,-8…, a #hash-tag, and an email: test."wut".yo@gmail.co.uk!', + ], [ + 'This link is already in an anchor tag google.com LOL and this one