@@ -93,7 +93,9 @@ export class EmbedDescriptor {
|
|||||||
|
|
||||||
matcher(url: string): false | RegExpMatchArray {
|
matcher(url: string): false | RegExpMatchArray {
|
||||||
const regexes = this.regexMatch ?? [];
|
const regexes = this.regexMatch ?? [];
|
||||||
const settingsDomainRegex = urlRegex(this.settings?.url);
|
const settingsDomainRegex = this.settings?.url
|
||||||
|
? urlRegex(this.settings?.url)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
if (settingsDomainRegex) {
|
if (settingsDomainRegex) {
|
||||||
regexes.unshift(settingsDomainRegex);
|
regexes.unshift(settingsDomainRegex);
|
||||||
@@ -372,11 +374,13 @@ const embeds: EmbedDescriptor[] = [
|
|||||||
keywords: "spreadsheet",
|
keywords: "spreadsheet",
|
||||||
regexMatch: [new RegExp("^https?://([a-z.-]+\\.)?getgrist\\.com/(.+)$")],
|
regexMatch: [new RegExp("^https?://([a-z.-]+\\.)?getgrist\\.com/(.+)$")],
|
||||||
transformMatch: (matches: RegExpMatchArray) => {
|
transformMatch: (matches: RegExpMatchArray) => {
|
||||||
if (matches[0].includes("style=singlePage")) {
|
const input = matches.input ?? matches[0];
|
||||||
return matches[0];
|
|
||||||
|
if (input.includes("style=singlePage")) {
|
||||||
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
return matches[0].replace(/(\?embed=true)?$/, "?embed=true");
|
return input.replace(/(\?embed=true)?$/, "?embed=true");
|
||||||
},
|
},
|
||||||
icon: <Img src="/images/grist.png" alt="Grist" />,
|
icon: <Img src="/images/grist.png" alt="Grist" />,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -138,5 +138,12 @@ describe("#urlRegex", () => {
|
|||||||
it("should return corresponding regex otherwise", () => {
|
it("should return corresponding regex otherwise", () => {
|
||||||
const regex = urlRegex("https://docs.google.com");
|
const regex = urlRegex("https://docs.google.com");
|
||||||
expect(regex?.source).toBe(/https:\/\/docs\.google\.com/.source);
|
expect(regex?.source).toBe(/https:\/\/docs\.google\.com/.source);
|
||||||
|
expect(regex?.test("https://docs.google.com")).toBe(true);
|
||||||
|
expect(regex?.test("https://docs.google.com/")).toBe(true);
|
||||||
|
expect(regex?.test("https://docs.google.com/d/123")).toBe(true);
|
||||||
|
expect(regex?.test("http://google.com")).toBe(false);
|
||||||
|
expect(regex?.test("http://docs.google.com")).toBe(false);
|
||||||
|
expect(regex?.test("http://docs.google.com/")).toBe(false);
|
||||||
|
expect(regex?.test("http://docs.google.com/d/123")).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user