This repository has been archived by the owner on Aug 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
addons_linkify_linkify.js.html
251 lines (209 loc) · 18.6 KB
/
addons_linkify_linkify.js.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>addons/linkify/linkify.js - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="module-xterm_src_xterm.html">xterm/src/xterm</a><ul class='methods'><li data-type='method'><a href="module-xterm_src_xterm.html#.bindBlur">bindBlur</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#.bindCopy">bindCopy</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#.bindCut">bindCut</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#.bindDrop">bindDrop</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#.bindFocus">bindFocus</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#.bindKeys">bindKeys</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#.bindPaste">bindPaste</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#.click">click</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#.loadAddon">loadAddon</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#.prepareCopiedTextForClipboard">prepareCopiedTextForClipboard</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#bell">bell</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#bindMouse">bindMouse</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#blankLine">blankLine</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#blur">blur</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#ch">ch</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#charAttributes">charAttributes</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#charPosAbsolute">charPosAbsolute</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#clearSelection">clearSelection</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#cursorBackward">cursorBackward</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#cursorBackwardTab">cursorBackwardTab</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#cursorCharAbsolute">cursorCharAbsolute</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#cursorDown">cursorDown</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#cursorForward">cursorForward</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#cursorForwardTab">cursorForwardTab</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#cursorNextLine">cursorNextLine</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#cursorPos">cursorPos</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#cursorPrecedingLine">cursorPrecedingLine</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#cursorUp">cursorUp</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#deleteChars">deleteChars</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#deleteColumns">deleteColumns</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#deleteLines">deleteLines</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#destroy">destroy</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#deviceStatus">deviceStatus</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#disableModifiers">disableModifiers</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#enableLocatorReporting">enableLocatorReporting</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#eraseAttr">eraseAttr</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#eraseChars">eraseChars</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#eraseInDisplay">eraseInDisplay</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#eraseInLine">eraseInLine</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#eraseLeft">eraseLeft</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#eraseLine">eraseLine</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#eraseRectangle">eraseRectangle</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#eraseRight">eraseRight</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#error">error</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#evaluateKeyEscapeSequence">evaluateKeyEscapeSequence</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#fillRectangle">fillRectangle</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#focus">focus</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#handler">handler</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#handleTitle">handleTitle</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#HPositionRelative">HPositionRelative</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#HVPosition">HVPosition</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#index">index</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#initGlobal">initGlobal</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#initMouseTracking">initMouseTracking</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#insertChars">insertChars</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#insertColumns">insertColumns</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#insertLines">insertLines</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#insertRow">insertRow</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#is">is</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#keyDown">keyDown</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#keyPress">keyPress</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#leaseContentEditable">leaseContentEditable</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#linePosAbsolute">linePosAbsolute</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#loadLEDs">loadLEDs</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#log">log</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#maxRange">maxRange</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#mediaCopy">mediaCopy</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#nextStop">nextStop</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#open">open</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#prevStop">prevStop</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#refresh">refresh</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#repeatPrecedingCharacter">repeatPrecedingCharacter</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#requestAnsiMode">requestAnsiMode</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#requestPrivateMode">requestPrivateMode</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#reset">reset</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#resetMode">resetMode</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#resetTitleModes">resetTitleModes</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#resize">resize</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#restoreCursor">restoreCursor</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#restorePrivateValues">restorePrivateValues</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#reverseIndex">reverseIndex</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#saveCursor">saveCursor</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#scroll">scroll</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#scrollDisp">scrollDisp</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#scrollDown">scrollDown</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#scrollUp">scrollUp</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#send">send</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#sendDeviceAttributes">sendDeviceAttributes</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#setAttrInRectangle">setAttrInRectangle</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#setCharProtectionAttr">setCharProtectionAttr</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#setConformanceLevel">setConformanceLevel</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#setCursorStyle">setCursorStyle</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#setgCharset">setgCharset</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#setgLevel">setgLevel</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#setMode">setMode</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#setPointerMode">setPointerMode</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#setResources">setResources</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#setScrollRegion">setScrollRegion</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#setupStops">setupStops</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#showCursor">showCursor</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#softReset">softReset</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#tabClear">tabClear</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#tabSet">tabSet</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#updateRange">updateRange</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#VPositionRelative">VPositionRelative</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#write">write</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#writeln">writeln</a></li></ul></li></ul><h3>Modules</h3><ul><li><a href="module-xterm_addons_attach_attach.html">xterm/addons/attach/attach</a><ul class='methods'><li data-type='method'><a href="module-xterm_addons_attach_attach.html#.attach">attach</a></li><li data-type='method'><a href="module-xterm_addons_attach_attach.html#.detach">detach</a></li></ul></li><li><a href="module-xterm_addons_fit_fit.html">xterm/addons/fit/fit</a></li><li><a href="module-xterm_addons_linkify_linkify.html">xterm/addons/linkify/linkify</a><ul class='methods'><li data-type='method'><a href="module-xterm_addons_linkify_linkify.html#.findLinkMatch">findLinkMatch</a></li><li data-type='method'><a href="module-xterm_addons_linkify_linkify.html#.linkify">linkify</a></li><li data-type='method'><a href="module-xterm_addons_linkify_linkify.html#.linkifyTerminalLine">linkifyTerminalLine</a></li></ul></li></ul><h3>Events</h3><ul><li><a href="module-xterm_addons_linkify_linkify.html#~event:linkify">linkify</a></li><li><a href="module-xterm_addons_linkify_linkify.html#~event:linkify:line">linkify:line</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">addons/linkify/linkify.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>(function (linkify) {
if (typeof exports === 'object' && typeof module === 'object') {
/*
* CommonJS environment
*/
module.exports = linkify(require('../../src/xterm'));
} else if (typeof define == 'function') {
/*
* Require.js is available
*/
define(['../../src/xterm'], linkify);
} else {
/*
* Plain browser environment
*/
linkify(this.Xterm);
}
})(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 = {},
protocolClause = '(https?:\\/\\/)',
domainCharacterSet = '[\\da-z\\.-]+',
negatedDomainCharacterSet = '[^\\da-z\\.-]+',
domainBodyClause = '(' + domainCharacterSet + ')',
tldClause = '([a-z\\.]{2,6})',
ipClause = '((\\d{1,3}\\.){3}\\d{1,3})',
portClause = '(:\\d{1,5})',
hostClause = '((' + domainBodyClause + '\\.' + tldClause + ')|' + ipClause + ')' + portClause + '?',
pathClause = '(\\/[\\/\\w\\.-]*)*',
negatedPathCharacterSet = '[^\\/\\w\\.-]+',
bodyClause = hostClause + pathClause,
start = '(?:^|' + negatedDomainCharacterSet + ')(',
end = ')($|' + negatedPathCharacterSet + ')',
lenientUrlClause = start + protocolClause + '?' + bodyClause + end,
strictUrlClause = start + protocolClause + bodyClause + end,
lenientUrlRegex = new RegExp(lenientUrlClause),
strictUrlRegex = new RegExp(strictUrlClause);
/**
* Converts all valid URLs found in the given terminal line into
* hyperlinks. The terminal line can be either the HTML element itself
* or the index of the termina line in the children of the terminal
* rows container.
*
* @param {Xterm} terminal - The terminal that owns the given line.
* @param {number|HTMLDivElement} line - The terminal line that should get
* "linkified".
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
* false, the regex requires a protocol clause. Defaults to true.
* @emits linkify
* @emits linkify:line
*/
exports.linkifyTerminalLine = function (terminal, line, lenient) {
if (typeof line == 'number') {
line = terminal.rowContainer.children[line];
} else if (! (line instanceof HTMLDivElement)) {
var message = 'The "line" argument should be either a number';
message += ' or an HTMLDivElement';
throw new TypeError(message);
}
var buffer = document.createElement('span'),
nodes = line.childNodes;
for (var j=0; j<nodes.length; j++) {
var node = nodes[j],
match;
/**
* Since we cannot access the TextNode's HTML representation
* from the instance itself, we assign its data as textContent
* to a dummy buffer span, in order to retrieve the TextNode's
* HTML representation from the buffer's innerHTML.
*/
buffer.textContent = node.data;
var nodeHTML = buffer.innerHTML;
/**
* Apply function only on TextNodes
*/
if (node.nodeType != node.TEXT_NODE) {
continue;
}
var url = exports.findLinkMatch(node.data, lenient);
if (!url) {
continue;
}
var startsWithProtocol = new RegExp('^' + protocolClause),
urlHasProtocol = url.match(startsWithProtocol),
href = (urlHasProtocol) ? url : 'http://' + url,
link = '<a href="' + href + '" >' + url + '</a>',
newHTML = nodeHTML.replace(url, link);
line.innerHTML = line.innerHTML.replace(nodeHTML, newHTML);
}
/**
* 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);
};
/**
* Finds a link within a block of text.
*
* @param {string} text - The text to search .
* @param {boolean} lenient - Whether to use the lenient search.
* @return {string} A URL.
*/
exports.findLinkMatch = function (text, lenient) {
var match = text.match(lenient ? lenientUrlRegex : strictUrlRegex);
if (!match || match.length === 0) {
return null;
}
return match[1];
}
/**
* Converts all valid URLs found in the terminal view into hyperlinks.
*
* @param {Xterm} terminal - The terminal that should get "linkified".
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
* false, the regex requires a protocol clause. Defaults to true.
* @emits linkify
* @emits linkify:line
*/
exports.linkify = function (terminal, lenient) {
var rows = terminal.rowContainer.children;
lenient = (typeof lenient == "boolean") ? lenient : true;
for (var i=0; i<rows.length; i++) {
var line = rows[i];
exports.linkifyTerminalLine(terminal, line, lenient);
}
/**
* This event gets emitted when conversion of all URL substrings to
* HTML anchor elements (links) has finished for the current Xterm
* instance's view.
*
* @event linkify
*/
terminal.emit('linkify');
};
/**
* Extend Xterm prototype.
*/
/**
* Converts all valid URLs found in the current terminal linte into
* hyperlinks.
*
* @memberof Xterm
* @param {number|HTMLDivElement} line - The terminal line that should get
* "linkified".
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
* false, the regex requires a protocol clause. Defaults to true.
*/
Xterm.prototype.linkifyTerminalLine = function (line, lenient) {
return exports.linkifyTerminalLine(this, line, lenient);
};
/**
* Converts all valid URLs found in the current terminal into hyperlinks.
*
* @memberof Xterm
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
* false, the regex requires a protocol clause. Defaults to true.
*/
Xterm.prototype.linkify = function (lenient) {
return exports.linkify(this, lenient);
};
return exports;
});
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Thu Jul 14 2016 13:31:36 GMT+0000 (UTC) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
</body>
</html>