mirror of
https://github.com/thelounge/thelounge.git
synced 2026-03-14 14:35:50 +01:00
linkify: Add web+ schema support
Co-Authored-By: Reto Brunner <reto@slightlybroken.com>
This commit is contained in:
parent
d15998d919
commit
ae6bae69ac
2 changed files with 70 additions and 0 deletions
|
|
@ -55,6 +55,28 @@ for (const schema of commonSchemes) {
|
|||
linkify.add(schema + ":", "http:");
|
||||
}
|
||||
|
||||
linkify.add("web+", {
|
||||
validate(text: string, pos: number, self: LinkifyIt.LinkifyIt) {
|
||||
const webSchemaRe = /^[a-z]+:/gi;
|
||||
|
||||
if (!webSchemaRe.test(text.slice(pos))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const linkEnd = self.testSchemaAt(text, "http:", pos + webSchemaRe.lastIndex);
|
||||
|
||||
if (linkEnd === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return webSchemaRe.lastIndex + linkEnd;
|
||||
},
|
||||
normalize(match) {
|
||||
match.schema = match.text.slice(0, match.text.indexOf(":") + 1);
|
||||
LinkifyIt.prototype.normalize(match); // hand over to the global override
|
||||
},
|
||||
});
|
||||
|
||||
export function findLinks(text: string) {
|
||||
const matches = linkify.match(text) as NoSchemaMatch[];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue