From 1ee774d01dfa9d1f781488c6a9560e16fc297f7c Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Thu, 9 Feb 2017 22:03:31 -0800 Subject: [PATCH] Remove linkify test --- src/Linkifier.ts | 16 ++++++----- src/test/addons/linkify-test.js | 48 --------------------------------- 2 files changed, 9 insertions(+), 55 deletions(-) delete mode 100644 src/test/addons/linkify-test.js diff --git a/src/Linkifier.ts b/src/Linkifier.ts index 29b1a953..394d9ba7 100644 --- a/src/Linkifier.ts +++ b/src/Linkifier.ts @@ -75,7 +75,9 @@ export class Linkifier { /** * Registers a link matcher, allowing custom link patterns to be matched and * handled. - * @param {RegExp} regex The regular expression the search for. + * @param {RegExp} regex The regular expression the search for, specifically + * this searches the textContent of the rows. You will want to use \s to match + * a space ' ' character for example. * @param {LinkHandler} handler The callback when the link is called. * @param {number} matchIndex The index of the link from the regex.match(html) * call. This defaults to 0 (for regular expressions without capture groups). @@ -116,10 +118,10 @@ export class Linkifier { * @param {number} rowIndex The index of the row to linkify. */ private _linkifyRow(rowIndex: number): void { - const rowHtml = this._rows[rowIndex].innerHTML; + const text = this._rows[rowIndex].textContent; for (let i = 0; i < this._linkMatchers.length; i++) { const matcher = this._linkMatchers[i]; - const uri = this._findLinkMatch(rowHtml, matcher.regex, matcher.matchIndex); + const uri = this._findLinkMatch(text, matcher.regex, matcher.matchIndex); if (uri) { this._doLinkifyRow(rowIndex, uri, matcher.handler); // Only allow a single LinkMatcher to trigger on any given row. @@ -164,13 +166,13 @@ export class Linkifier { } /** - * Finds a link match in a piece of HTML. - * @param {string} html The HTML to search. + * Finds a link match in a piece of text. + * @param {string} text The text to search. * @param {number} matchIndex The regex match index of the link. * @return {string} The matching URI or null if not found. */ - private _findLinkMatch(html: string, regex: RegExp, matchIndex?: number): string { - const match = html.match(regex); + private _findLinkMatch(text: string, regex: RegExp, matchIndex?: number): string { + const match = text.match(regex); if (!match || match.length === 0) { return null; } diff --git a/src/test/addons/linkify-test.js b/src/test/addons/linkify-test.js deleted file mode 100644 index 285bfbb1..00000000 --- a/src/test/addons/linkify-test.js +++ /dev/null @@ -1,48 +0,0 @@ -var assert = require('chai').assert; -var Terminal = require('../../xterm'); -var linkify = require('../../addons/linkify/linkify'); - -describe('linkify addon', function () { - var xterm; - - describe('API', function () { - it('should define Terminal.prototype.linkify', function () { - assert.isDefined(Terminal.prototype.linkify); - }); - it('should define Terminal.prototype.linkifyTerminalLine', function () { - assert.isDefined(Terminal.prototype.linkifyTerminalLine); - }); - }); - - describe('findUrlMatchOnLine', function () { - describe('strict regex', function () { - it('should match when the entire text is a match', function () { - assert.equal(linkify.findLinkMatch('http://github.com', false), 'http://github.com'); - assert.equal(linkify.findLinkMatch('http://127.0.0.1', false), 'http://127.0.0.1'); - }); - it('should match simple domains', function () { - assert.equal(linkify.findLinkMatch('foo http://github.com bar', false), 'http://github.com'); - assert.equal(linkify.findLinkMatch('foo http://www.github.com bar', false), 'http://www.github.com'); - assert.equal(linkify.findLinkMatch('foo https://github.com bar', false), 'https://github.com'); - assert.equal(linkify.findLinkMatch('foo https://www.github.com bar', false), 'https://www.github.com'); - }); - it('should match web addresses with alpha paths', function () { - assert.equal(linkify.findLinkMatch('foo http://github.com/a/b/c bar', false), 'http://github.com/a/b/c'); - assert.equal(linkify.findLinkMatch('foo http://www.github.com/a/b/c bar', false), 'http://www.github.com/a/b/c'); - }); - it('should not include whitespace surrounding a match', function () { - assert.equal(linkify.findLinkMatch(' http://github.com', false), 'http://github.com'); - assert.equal(linkify.findLinkMatch('http://github.com ', false), 'http://github.com'); - assert.equal(linkify.findLinkMatch(' http://github.com ', false), 'http://github.com'); - }); - it('should match IP addresses', function () { - assert.equal(linkify.findLinkMatch('foo http://127.0.0.1 bar', false), 'http://127.0.0.1'); - assert.equal(linkify.findLinkMatch('foo https://127.0.0.1 bar', false), 'https://127.0.0.1'); - }); - it('should match ports on both domains and IP addresses', function () { - assert.equal(linkify.findLinkMatch('foo http://127.0.0.1:8080 bar', false), 'http://127.0.0.1:8080'); - assert.equal(linkify.findLinkMatch('foo http://www.github.com:8080 bar', false), 'http://www.github.com:8080'); - }); - }); - }); -});