mirror of
https://github.com/thelounge/thelounge.git
synced 2024-06-04 14:52:19 +02:00
Add webplus
This commit is contained in:
parent
d15998d919
commit
767ab499a2
|
@ -11,6 +11,8 @@ export type LinkPart = {
|
|||
link: string;
|
||||
};
|
||||
|
||||
const webplus_scheme_chars = /^[a-z]+:/i;
|
||||
|
||||
LinkifyIt.prototype.normalize = function normalize(match: NoSchemaMatch) {
|
||||
match.noschema = false;
|
||||
|
||||
|
@ -26,6 +28,10 @@ LinkifyIt.prototype.normalize = function normalize(match: NoSchemaMatch) {
|
|||
match.noschema = true;
|
||||
}
|
||||
|
||||
if (match.schema === "web+") {
|
||||
match.schema = "web+" + match.url.slice(4).match(webplus_scheme_chars)![0];
|
||||
}
|
||||
|
||||
if (match.schema === "mailto:" && !/^mailto:/i.test(match.url)) {
|
||||
match.url = "mailto:" + match.url;
|
||||
}
|
||||
|
@ -55,6 +61,25 @@ for (const schema of commonSchemes) {
|
|||
linkify.add(schema + ":", "http:");
|
||||
}
|
||||
|
||||
linkify.add("web+", {
|
||||
validate(text: string, pos: number, self: LinkifyIt.LinkifyIt) {
|
||||
const tail = text.slice(pos);
|
||||
|
||||
if (webplus_scheme_chars.test(tail)) {
|
||||
const offset = tail.match(webplus_scheme_chars)![0].length;
|
||||
const result = self.testSchemaAt(text, "http:", pos + offset);
|
||||
|
||||
if (result === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return offset + result;
|
||||
}
|
||||
|
||||
return 0;
|
||||
},
|
||||
});
|
||||
|
||||
export function findLinks(text: string) {
|
||||
const matches = linkify.match(text) as NoSchemaMatch[];
|
||||
|
||||
|
|
|
@ -372,4 +372,34 @@ describe("findLinks", () => {
|
|||
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
|
||||
it("should find web+ap urls", () => {
|
||||
const input = "web+ap://instance.example/@Example";
|
||||
const expected = [
|
||||
{
|
||||
link: "web+ap://instance.example/@Example",
|
||||
start: 0,
|
||||
end: 34,
|
||||
},
|
||||
];
|
||||
|
||||
const actual = findLinks(input);
|
||||
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
|
||||
it("should find web+ap urls if scheme required flag is specified", () => {
|
||||
const input = "web+ap://instance.example/@Example";
|
||||
const expected = [
|
||||
{
|
||||
link: "web+ap://instance.example/@Example",
|
||||
start: 0,
|
||||
end: 34,
|
||||
},
|
||||
];
|
||||
|
||||
const actual = findLinksWithSchema(input);
|
||||
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue