diff --git a/addons/linkify/linkify.js b/addons/linkify/linkify.js index 4bc173c..030c5b4 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