Skip to content

Commit b3a690b

Browse files
authored
feat: documents link support (#20)
## Background Add support for the `/documents/ID` format returned by the [SimplePDF API](https://simplepdf.com/api/) ## Changes - [x] Update regex - [x] Update tests - [x] Publish web-embed-pdf
1 parent 2749ee5 commit b3a690b

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

web/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@simplepdf/web-embed-pdf",
3-
"version": "1.8.3",
3+
"version": "1.8.4",
44
"description": "SimplePDF straight into your website",
55
"repository": {
66
"type": "git",

web/src/__tests__/shared.test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,31 @@ describe('getSimplePDFElements', () => {
1212
<a href="https://pdfobject.com/pdf/sample-3pp.pdf">PDF link</a>
1313
<a href="https://example.com/some-pdf-without-extension" class="simplepdf">Regular link with class</a>
1414
<button class="simplepdf">Button with class</button>
15-
<a href="https://yourcompany.simplepdf.com/form/d8d57ec7-f3e9-4fc9-8cc5-4a92c02d30d0" class="simplepdf">SimplePDF form link</a>
15+
<a href="https://yourcompany.simplepdf.com/form/d8d57ec7-f3e9-4fc9-8cc5-4a92c02d30d0">SimplePDF form link</a>
16+
<a href="https://yourcompany.simplepdf.com/documents/d8d57ec7-f3e9-4fc9-8cc5-4a92c02d30d0">SimplePDF document link</a>
1617
<!--Should NOT detect below-->
1718
<a href="https://pdfobject.com/pdf/sample-3pp.pdf" class="exclude-simplepdf">PDF link with class exclusion</a>
1819
<a href="https://yourcompany.simplepdf.com/form/d8d57ec7-f3e9-4fc9-8cc5-4a92c02d30d0" class="exclude-simplepdf">SimplePDF form link with exclusion</a>
1920
<a href="https://www.pdfsomething.com/anything">Regular link containing .pdf</a>
2021
<a href="https://www.website.com/some-pdf">Should not be opened with SimplePDF</a>
2122
<a href="https://www.website.com/some-other.pdf.png">Should not be opened with SimplePDF</a>
23+
<a href="https://www.simplepdf.app/s/article/How-to-Manage-PDF-Settings">Should not be opened with SimplePDF</a>
24+
<a href="https://www.app.pdf/some-url">Should not be opened with SimplePDF</a>
2225
</body>
2326
</html>
2427
`,
2528
{ url: 'http://localhost' },
2629
);
2730
const detectedElements = getSimplePDFElements(dom.window.document);
28-
expect(detectedElements).toHaveLength(4);
31+
expect(detectedElements).toHaveLength(5);
2932
expect(detectedElements.map(({ innerHTML }) => innerHTML)).toStrictEqual(
30-
expect.arrayContaining(['Button with class', 'PDF link', 'Regular link with class', 'SimplePDF form link']),
33+
expect.arrayContaining([
34+
'Button with class',
35+
'PDF link',
36+
'Regular link with class',
37+
'SimplePDF form link',
38+
'SimplePDF document link',
39+
]),
3140
);
3241
});
3342
});

web/src/shared.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ const editorContext: EditorContext = {
3232
},
3333
};
3434

35-
const isFormLink = (url: string) => {
36-
const regex = /^https:\/\/[^.]+\.simplepdf\.com\/[^\/]+\/form\/.+/;
35+
const isSimplePDFLink = (url: string) => {
36+
const regex = /^https:\/\/[^.]+\.simplepdf\.com(\/[^\/]+)?\/(form|documents)\/.+/;
3737
return regex.test(url);
3838
};
3939

@@ -122,7 +122,7 @@ export const getSimplePDFElements = (document: Document): Element[] => {
122122
return false;
123123
}
124124

125-
return isPDFLink(anchor.href) || anchor.classList.contains('simplepdf') || isFormLink(anchor.href);
125+
return isPDFLink(anchor.href) || anchor.classList.contains('simplepdf') || isSimplePDFLink(anchor.href);
126126
});
127127

128128
return anchorsWithPDF;

0 commit comments

Comments
 (0)