From b60903a2aec137738c394d1b79e82763b44bc959 Mon Sep 17 00:00:00 2001 From: paris Date: Sun, 4 Jan 2015 15:08:36 +0200 Subject: [PATCH 1/8] [addon linkify] Start working on "linkifying" URLs in the terminal --- addons/linkify/linkify.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 addons/linkify/linkify.js diff --git a/addons/linkify/linkify.js b/addons/linkify/linkify.js new file mode 100644 index 00000000..022f89ad --- /dev/null +++ b/addons/linkify/linkify.js @@ -0,0 +1,27 @@ +(function (linkify) { +})(function (Xterm) { + Xterm.prototype.linkify = function () { + var rows = this.rowContainer.children, + buffer = document.createElement('span'); + + for (var i=0; i' + url + ''); + buffer.textContent = node.data; + line.innerHTML = line.innerHTML.replace(buffer.innerHTML, newData); + this.emit('linkify:line', line); + } + } + } + } + }; +}); \ No newline at end of file From 523ff9908ff2938cf935ee82ebbf57a751a1397e Mon Sep 17 00:00:00 2001 From: paris Date: Sun, 4 Jan 2015 15:45:26 +0200 Subject: [PATCH 2/8] [addon linkify] Set up proper initialization of add-on - Also created a demo page for the addon --- addons/linkify/index.html | 36 ++++++++++++++++++++++++++++++++++++ addons/linkify/linkify.js | 11 +++++++++++ 2 files changed, 47 insertions(+) create mode 100644 addons/linkify/index.html diff --git a/addons/linkify/index.html b/addons/linkify/index.html new file mode 100644 index 00000000..5f429326 --- /dev/null +++ b/addons/linkify/index.html @@ -0,0 +1,36 @@ + + + + + + + + + + +
+ + + \ No newline at end of file diff --git a/addons/linkify/linkify.js b/addons/linkify/linkify.js index 022f89ad..4bc173c9 100644 --- a/addons/linkify/linkify.js +++ b/addons/linkify/linkify.js @@ -1,4 +1,15 @@ (function (linkify) { + if (typeof define == 'function') { + /* + * Require.js is available + */ + define(['../../src/xterm'], linkify); + } else { + /* + * Plain browser environment + */ + linkify(this.Xterm); + } })(function (Xterm) { Xterm.prototype.linkify = function () { var rows = this.rowContainer.children, From c8a497eb82076879d8abc0fb65bb11da6aff798e Mon Sep 17 00:00:00 2001 From: paris Date: Sun, 4 Jan 2015 20:39:57 +0200 Subject: [PATCH 3/8] [addon linkify] Fine-grained module and documented almost everything --- addons/linkify/linkify.js | 124 +++++++++++++++++++++++++++++++++----- 1 file changed, 108 insertions(+), 16 deletions(-) diff --git a/addons/linkify/linkify.js b/addons/linkify/linkify.js index 4bc173c9..030c5b4a 100644 --- a/addons/linkify/linkify.js +++ b/addons/linkify/linkify.js @@ -11,28 +11,120 @@ linkify(this.Xterm); } })(function (Xterm) { - Xterm.prototype.linkify = function () { - var rows = this.rowContainer.children, - buffer = document.createElement('span'); + 'use strict'; + /** + * This module provides methods for convertings valid URL substrings + * into HTML anchor elements (links), inside a terminal view. + * + * @module xterm/addons/linkify/linkify + */ + var exports = {}; - for (var i=0; i' + url + ''); - buffer.textContent = node.data; - line.innerHTML = line.innerHTML.replace(buffer.innerHTML, newData); - this.emit('linkify:line', line); + if (match) { + var url = match[0], + link = '' + url + '', + newData = node.data.replace(url, link); + + buffer.textContent = node.data; + line.innerHTML = line.innerHTML.replace(buffer.innerHTML, newData); + } } - } } - } + + /** + * This event gets emitted when conversion of all URL susbtrings + * to HTML anchor elements (links) has finished, for a specific + * line of the current Xterm instance. + * + * @event linkify:line + */ + terminal.emit('linkify:line', line); }; + + + /** + * Converts all valid URLs found in the terminal view into hyperlinks. + * + * @param {Xterm} terminal - The terminal that should get "linkified". + * @emits linkify + * @emits linkify:line + */ + exports.linkify = function (terminal) { + var rows = terminal.rowContainer.children; + + for (var i=0; i Date: Sun, 4 Jan 2015 22:27:14 +0200 Subject: [PATCH 4/8] [addon linkify] Improve URL to link conversion algorithm --- addons/linkify/linkify.js | 57 ++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/addons/linkify/linkify.js b/addons/linkify/linkify.js index 030c5b4a..92089929 100644 --- a/addons/linkify/linkify.js +++ b/addons/linkify/linkify.js @@ -12,14 +12,24 @@ } })(function (Xterm) { 'use strict'; + /** * This module provides methods for convertings valid URL substrings * into HTML anchor elements (links), inside a terminal view. * * @module xterm/addons/linkify/linkify */ - var exports = {}; - + var exports = {}, + protocolClause = '(https?:\\/\\/)', + domainBodyClause = '([\\da-z\\.-]+)', + tldClause = '([a-z\\.]{2,6})', + hostClause = domainBodyClause + '\\.' + tldClause, + pathClause = '([\\/\\w\\.-]*)*\\/?', + bodyClause = hostClause + pathClause, + start = '(?:^|\\s+)(', + end = ')($|\\s+)', + urlClause = start + protocolClause + '?' + bodyClause + end, + urlRegex = new RegExp(urlClause); /** * Converts all valid URLs found in the given terminal line into @@ -46,22 +56,45 @@ var buffer = document.createElement('span'), nodes = line.childNodes; + console.log(nodes.length, 'number of nodes'); for (var j=0; j' + url + '', - newData = node.data.replace(url, link); + var nodeHTML = buffer.innerHTML; - buffer.textContent = node.data; - line.innerHTML = line.innerHTML.replace(buffer.innerHTML, newData); - } + /* + * Apply function only on TextNodes + */ + if (node.nodeType != node.TEXT_NODE) { + continue; } + + + var match = node.data.match(urlRegex); + + /* + * If no URL was found in the current text, return. + */ + if (!match) { + continue; + } + + var url = match[1], + startsWithProtocol = new RegExp('^' + protocolClause), + urlHasProtocol = url.match(startsWithProtocol), + href = (urlHasProtocol) ? url : 'http://' + url, + link = '' + url + '', + newHTML = nodeHTML.replace(url, link); + + line.innerHTML = line.innerHTML.replace(nodeHTML, newHTML); } /** From 43ac453db173b959b60be5b5fbd1f8a8abdc5d75 Mon Sep 17 00:00:00 2001 From: paris Date: Mon, 5 Jan 2015 16:05:14 +0200 Subject: [PATCH 5/8] [addon linkify] Improve start and end clauses --- addons/linkify/linkify.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/linkify/linkify.js b/addons/linkify/linkify.js index 92089929..19d08b67 100644 --- a/addons/linkify/linkify.js +++ b/addons/linkify/linkify.js @@ -26,8 +26,8 @@ hostClause = domainBodyClause + '\\.' + tldClause, pathClause = '([\\/\\w\\.-]*)*\\/?', bodyClause = hostClause + pathClause, - start = '(?:^|\\s+)(', - end = ')($|\\s+)', + start = '(?:^|\\s+|\\(+|\\[+)(', + end = ')($|\\s+|\\)+|\\]+)', urlClause = start + protocolClause + '?' + bodyClause + end, urlRegex = new RegExp(urlClause); From 3e7ab290fac09839486b7fdf1d7696a16f628d2c Mon Sep 17 00:00:00 2001 From: paris Date: Mon, 5 Jan 2015 16:07:29 +0200 Subject: [PATCH 6/8] [addon linkify] Remove console.log --- addons/linkify/linkify.js | 1 - 1 file changed, 1 deletion(-) diff --git a/addons/linkify/linkify.js b/addons/linkify/linkify.js index 19d08b67..2f44fdfa 100644 --- a/addons/linkify/linkify.js +++ b/addons/linkify/linkify.js @@ -56,7 +56,6 @@ var buffer = document.createElement('span'), nodes = line.childNodes; - console.log(nodes.length, 'number of nodes'); for (var j=0; j Date: Tue, 6 Jan 2015 13:03:07 +0200 Subject: [PATCH 7/8] [addon linkify] Further optimize URL algorithm --- addons/linkify/linkify.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/addons/linkify/linkify.js b/addons/linkify/linkify.js index 2f44fdfa..543e5feb 100644 --- a/addons/linkify/linkify.js +++ b/addons/linkify/linkify.js @@ -21,13 +21,16 @@ */ var exports = {}, protocolClause = '(https?:\\/\\/)', - domainBodyClause = '([\\da-z\\.-]+)', + domainCharacterSet = '[\\da-z\\.-]+', + negatedDomainCharacterSet = '[^\\da-z\\.-]+', + domainBodyClause = '(' + domainCharacterSet + ')', tldClause = '([a-z\\.]{2,6})', hostClause = domainBodyClause + '\\.' + tldClause, pathClause = '([\\/\\w\\.-]*)*\\/?', + negatedPathCharacterSet = '[^\\/\\w\\.-]+', bodyClause = hostClause + pathClause, - start = '(?:^|\\s+|\\(+|\\[+)(', - end = ')($|\\s+|\\)+|\\]+)', + start = '(?:^|' + negatedDomainCharacterSet + ')(', + end = ')($|' + negatedPathCharacterSet + ')', urlClause = start + protocolClause + '?' + bodyClause + end, urlRegex = new RegExp(urlClause); From 85abfb81514715456259bf63d89831f5712673bd Mon Sep 17 00:00:00 2001 From: paris Date: Tue, 6 Jan 2015 13:12:31 +0200 Subject: [PATCH 8/8] Bump version to 0.28 --- docs/conf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 3eb1b3cf..cca08f63 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -51,9 +51,9 @@ copyright = u'2014, SourceLair Limited' # built documents. # # The short X.Y version. -version = '0.27' +version = '0.28' # The full version, including alpha/beta/rc tags. -release = '0.27 Alpha' +release = '0.28 Alpha' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages.