This repository has been archived by the owner on May 11, 2021. It is now read-only.
forked from markdown-it/linkify-it
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inproved default 2-characters tlds handle in flex links, closes markd…
- Loading branch information
Vitaly Puzrin
authored and
César Fernández
committed
May 22, 2020
1 parent
e951342
commit b9b7e24
Showing
4 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,6 @@ | |
"mocha": "*", | ||
"ndoc": "^3.1.0", | ||
"stylus": "~0.50.0", | ||
"tlds": "^1.26.0" | ||
"tlds": "^1.37.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env node | ||
|
||
// Generates list of 2-char english tlds. | ||
// | ||
// Code is dirty, i know, but it's needed only once | ||
// | ||
'use strict'; | ||
|
||
|
||
/*eslint-disable no-console*/ | ||
|
||
function toRanges(str) { | ||
var ranges = [], i; | ||
|
||
str = str.slice(1, -1); | ||
|
||
while (str.length) { | ||
for (i = 1; ; i++) { | ||
if (str[i] !== String.fromCharCode(str[i - 1].charCodeAt(0) + 1)) { | ||
if (i < 3) { | ||
ranges.push(str.slice(0, i)); | ||
} else { | ||
ranges.push(str[0] + '-' + str[i - 1]); | ||
} | ||
str = str.slice(i); | ||
break; | ||
} | ||
} | ||
} | ||
return '[' + ranges.join('') + ']'; | ||
} | ||
|
||
var tlds = require('tlds') | ||
.filter(function (name) { | ||
return /^[a-z]{2}$/.test(name); | ||
}) | ||
.sort(); | ||
|
||
// | ||
// group by first letter | ||
// | ||
|
||
var result = []; | ||
|
||
'abcdefghijklmnopqrstuvwxyz'.split('').forEach(function (letter) { | ||
var list = tlds.filter(function (name) { return name[0] === letter; }); | ||
|
||
if (!list.length) { return; } | ||
|
||
if (list.length < 2) { | ||
result = result.concat(list); | ||
return; | ||
} | ||
|
||
result.push(letter + '[' + list.map(function (n) { return n[1]; }).join('') + ']'); | ||
}); | ||
|
||
result = result.join('|'); | ||
|
||
console.log(result); | ||
|
||
// | ||
// Compact ranges | ||
// | ||
|
||
result = result.replace(/\[[a-z]+\]/g, toRanges); | ||
|
||
// console.log(result); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ _example.com | |
http://example.com_ | ||
@example.com | ||
|
||
node.js and io.js | ||
|
||
http:// | ||
http://. | ||
http://.. | ||
|