forked from alexcorvi/anchorme.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
438 lines (409 loc) · 14.2 KB
/
index.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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>
Anchorme: Javascript library to detect links / URLs / Emails in text
and convert them to clickable HTML anchor links
</title>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<link href="./assets/style.min.css" rel="stylesheet" />
<style>
a.detected {
background: #fff59d;
}
a.detected:hover {
background: #ffe082;
}
</style>
</head>
<body>
<!-- Main navigation
=========================================== -->
<header class="navbar navbar-static-top bs-docs-nav" id="top">
<div class="container">
<div class="navbar-header" role="banner">
<button
class="navbar-toggle"
type="button"
data-toggle="collapse"
data-target=".bs-navbar-collapse"
>
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a
class="navbar-brand"
href="http://alexcorvi.github.io/anchorme.js/"
>Anchorme</a
>
</div>
<nav
class="collapse navbar-collapse bs-navbar-collapse"
role="navigation"
>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="./benchmark.html">Benchmark</a>
</li>
<li>
<a href="https://github.com/alexcorvi/anchorme.js"
>View on GitHub</a
>
</li>
</ul>
</nav>
</div>
</header>
<!-- Header
=========================================== -->
<div
class="bs-docs-masthead"
id="content"
style="background: linear-gradient(135deg, #673ab7, #3f51b5);"
>
<div class="container">
<h1 class="home-title">Anchorme</h1>
<p class="lead" style="font-size: 18px; margin-top: 25px;">
Tiny, fast, efficient, feature rich Javascript library to
detect links / URLs / Emails in text and convert them to
clickable HTML anchor links
</p>
<p class="lead">
<a
data-bootbox="download-popup"
data-bootbox-size="large"
class="btn btn-outline-inverse btn-lg"
>Download</a
>
</p>
</div>
</div>
<div id="download-popup" title="Download" class="hidden">
<div class="row">
<div class="col-xs-12">
<div class="panel panel-default">
<div class="panel-heading">Install with NPM</div>
<div class="panel-body">
<p>You can get this library via NPM or yarn</p>
<pre><code>$ npm i --save anchorme
$ yarn add anchorme</code></pre>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">Download full version</div>
<div class="panel-body">
<p>Compiled version into single file.</p>
<a
href="https://raw.githubusercontent.com/alexcorvi/anchorme.js/gh-pages/dist/browser/anchorme.js"
>Download</a
>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">
Download minified version
</div>
<div class="panel-body">
<p>Compiled and minified version.</p>
<a
href="https://raw.githubusercontent.com/alexcorvi/anchorme.js/gh-pages/dist/browser/anchorme.min.js"
>Download</a
>
</div>
</div>
</div>
</div>
</div>
<div class="container bs-docs-container">
<div class="row">
<div class="col-md-9" role="main">
<section class="bs-docs-section">
<h1 id="overview" class="page-header">
Overview
</h1>
<div id="overview-content"></div>
</section>
<section class="bs-docs-section">
<h1 id="demo" class="page-header">
Demo
</h1>
<div id="demo-content">
<div class="row">
<div class="col-md-6">
<textarea
onkeydown="refresh();"
onkeyup="refresh();"
onchange="refresh();"
id="input"
style="width: 100%; height: 1000px;"
>
</textarea>
</div>
<div class="col-md-6">
<div
id="output"
style="white-space: pre-line;"
></div>
</div>
</div>
</div>
</section>
<section class="bs-docs-section">
<h1 id="getting-started" class="page-header">
Getting started
</h1>
<div id="getting-started-content"></div>
</section>
<section class="bs-docs-section">
<h1 id="options" class="page-header">
Options
</h1>
<div id="options-content"></div>
</section>
<section class="bs-docs-section">
<h1 id="extending" class="page-header">
Extending
</h1>
<div id="extending-content"></div>
</section>
<section class="bs-docs-section">
<h1 id="utility" class="page-header">
Utility functions
</h1>
<div id="utility-content"></div>
</section>
<section class="bs-docs-section">
<h1 id="contributing" class="page-header">
Contributing
</h1>
<div id="contributing-content"></div>
</section>
<section class="bs-docs-section">
<h1 id="license" class="page-header">
License
</h1>
<div id="license-content"></div>
</section>
</div>
<div class="col-md-3" role="complementary">
<div class="bs-docs-sidebar hidden-print">
<ul class="nav bs-docs-sidenav"></ul>
<a class="back-to-top" href="#top">Back to top</a>
</div>
</div>
</div>
</div>
<footer class="bs-docs-footer" role="contentinfo">
<div class="container">
<div class="bs-docs-social">
<ul class="bs-docs-social-buttons">
<li>
<iframe
class="github-btn"
src="//ghbtns.com/github-btn.html?user=alexcorvi&repo=anchorme.js&type=fork&count=true"
width="90"
height="20"
title="Fork on GitHub"
></iframe>
</li>
<li>
<iframe
class="github-btn"
src="//ghbtns.com/github-btn.html?user=alexcorvi&repo=anchorme.js&type=star&count=true"
width="90"
height="20"
title="Star on GitHub"
></iframe>
</li>
</ul>
</div>
<p>
Licensed under
<a href="http://opensource.org/licenses/MIT" target="_blank"
>MIT License</a
>
</p>
<p>
Documentation template by
<a href="http://getbootstrap.com">Bootstrap team</a>
</p>
<ul class="bs-docs-footer-links muted">
<li>·</li>
<li>
<a href="https://github.com/alexcorvi/anchorme.js"
>GitHub</a
>
</li>
<li>·</li>
<li>
<a
href="https://github.com/alexcorvi/anchorme.js/issues?state=open"
>Issues</a
>
</li>
</ul>
</div>
</footer>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.3.0/bootbox.min.js"></script>
<script
src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/highlight.min.js"
type="text/javascript"
></script>
<script type="text/javascript">
hljs.initHighlightingOnLoad();
</script>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="./assets/script.js" type="text/javascript"></script>
<script
src="./dist/browser/anchorme.js"
type="text/javascript"
></script>
<script type="text/javascript">
var initialInput = `Library works with (http://www.google.com) or without (www.google.com) protocols in link. It works well on paths [www.github.io/something/something] and queries <wordpress.com/post.php?p=112> and even when query starts immediately after the TLDS "wordpress.com?p=112". This library does validation against a full IANA list, so for example this link will be detected: 'alex.photography', yet this one will not 'alex.photograph'. Some links might also have ports in them like this one (https://a.co:8999/ab.php?p=12). Some are actually an IP (127.0.0.1/should_(be)_detected, v6:http://[2a00:1450:4025:401::67]/some/path/goes/here, invalid:127.0.0.300/should/not(be)_detected). Local machine names URLs are detected only when preceded by a protocol (https://localhost/abc, ftps://hostname, http://local:123?abc=xyz.)\nLocal TLDs are supported too: (e.g. domain.test).\n\nLinks with non-english alphabets are considered as non-valid, yet they are commonly used in chat application and so, so we supported them (to some degree). (examples: ka.wikipedia.org/wiki/მთავარი_გვერდი, ka.wikipedia.org/wiki/ბაქო, ka.wikipedia.org/wiki/2_აპრილი, ka.wikipedia.org/wiki/მერი_(სპილო)). Encoded links works too (example:ka.wikipedia.org/wiki/%E1%83%91, mailto:[email protected]).\n\nEmails are detected too: (valid: [email protected] mailto:[email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]) (invalid [email protected] email@example [email protected] [email protected]).\n\nFiles (when starting with file:/// protocol) are detected too. (file:///c:/directory/somefile.zip).\n\nTokenization is as accurate as it can get, you can see from the above text that we've tried almost all common punctuation marks and the library detected links from between them.\n\nLibrary doesn't break your HTML, so an HTML attribute that has a link in it will not be broken or a link that is already inside an attribute, will not be detected: <ul><li>Link inside src attribute: <img src='http://dummyimage.com/30'></li><li>Link is already in an anchor tag: <a href="https://github.io">https://github.io</a></li><li>Link inside non-standard attributes: <a href="https://www.validurl.com" data-saferedirecturl="https://www.validurl.com/file.png" data-thumb="https://www.validurl.com/file.png">Link</a></li><li>Link inside inline styling: <span style="background-image:url(http://dummyimage.com/30)">AWESOME</span></li></ul>\n`;
document.getElementById("input").value = initialInput;
refresh();
/*anchor me*/
function refresh() {
val = document.getElementById("input").value;
document.getElementById("output").innerHTML = anchorme({
input: val,
options: {
attributes: (arg) => {
return {
class: "detected",
title: JSON.stringify(anchorme.list(arg))
.replace(/"/g, "'")
.replace(/,/g, ",\n"),
};
},
},
});
}
function embedJSFiddleCode(string) {
for (
let index = 0;
index < string.split(`**[JSFiddle Demo](https`).length + 5;
index++
) {
string = string.replace(
/([\s\S]*)\*\*\[JSFiddle Demo\]\(https:\/\/jsfiddle\.net\/alexcorvi\/([\w\d]+\/\d+)\/\)\*\*([\s\S]*)/gim,
`$1<b>JSFiddle</b><iframe width="100%" height="300" src="//jsfiddle.net/alexcorvi/$2/embedded/js,result/" allowfullscreen="allowfullscreen" allowpaymentrequest frameborder="0"></iframe>$3`
);
}
return string;
}
async function fetchMD(relativePath, linesToDelete) {
return (await (await fetch(relativePath)).text())
.split(/\n/)
.filter((x, i) => i >= linesToDelete)
.join("\n");
}
async function placeMDContent(
relativePath,
linesToDelete,
elementID
) {
let content = await fetchMD(relativePath, linesToDelete);
content = embedJSFiddleCode(content);
document.getElementById(elementID).innerHTML = marked(content);
}
async function loadContent() {
await placeMDContent("./README.md", 4, "overview-content");
await placeMDContent(
"./docs/getting-started.md",
1,
"getting-started-content"
);
await placeMDContent("./docs/options.md", 1, "options-content");
await placeMDContent(
"./docs/contributing.md",
1,
"contributing-content"
);
await placeMDContent("./LICENSE.md", 0, "license-content");
await placeMDContent(
"./docs/extending.md",
1,
"extending-content"
);
await placeMDContent(
"./docs/utility-functions.md",
1,
"utility-content"
);
document.querySelectorAll("pre code").forEach((block) => {
hljs.highlightBlock(block);
});
var html = "";
$(".bs-docs-section").each(function () {
var h1 = $(this).find("h1[id]").first(),
h23 = $(this).find(
"h2[id], h3[id]:not([data-no-menu])"
);
if (h1.length) {
html +=
'<li><a href="#' +
h1[0].id +
'">' +
h1.clone().children().remove().end().text() +
"</a>";
if (h23.length) {
html += '<ul class="nav">';
h23.each(function () {
html +=
'<li><a href="#' +
this.id +
'">' +
$(this)
.clone()
.children()
.remove()
.end()
.text() +
"</a></li>";
});
html += "</ul>";
}
html += "</li>";
}
});
if (html == "") {
$("[role=complementary]").hide();
$("[role=main]").toggleClass("col-md-9 col-md-12");
} else {
$(".bs-docs-sidenav").html(html);
}
// add heading anchors
$("h1[id], h2[id], h3[id], h4[id], h5[id]").each(function () {
$(this).prepend(
'<a href="#' + this.id + '" class="anchor-link">§</i>'
);
});
// enable bootbox
$("[data-bootbox]").on("click", function () {
var $target = $("#" + $(this).data("bootbox"));
bootbox.alert({
title: $target.attr("title"),
message: $target.html(),
size: $(this).data("bootbox-size"),
});
});
}
loadContent();
</script>
</body>
</html>