mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
[addon linkify] Start working on "linkifying" URLs in the terminal
This commit is contained in:
@@ -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<rows.length; i++) {
|
||||
var line = rows[i], nodes = line.childNodes;
|
||||
|
||||
for (var j=0; j<nodes.length; j++) {
|
||||
var node = nodes[j];
|
||||
|
||||
if (node.nodeType == 3) {
|
||||
var match = node.data.match(/(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?/);
|
||||
|
||||
if (match) {
|
||||
var url=match[0],
|
||||
newData = node.data.replace(url, '<a href="http://' + url + '" target="_blank" >' + url + '</a>');
|
||||
buffer.textContent = node.data;
|
||||
line.innerHTML = line.innerHTML.replace(buffer.innerHTML, newData);
|
||||
this.emit('linkify:line', line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user