Skip to content

Commit eff1b16

Browse files
authored
fix: false positive pdf link detection for www.pdf* websites (#16)
## Background The anchor detection logic is currently detecting https://www.pdf* URLs as "simplePDF urls" - this results in the editor opening and complaining that the file is not a valid PDF. This PR addresses this issue as well as some janitorial work. ## Changes - [x] Fix the incorrect PDF detection - [x] Update dependencies - [x] Add test coverage - [x] Add formatting - [x] Swap yarn for NPM - [x] Add Github action - [x] **Publish @simplepdf/web-embed-pdf@1.8.3** Also update dependencies, add tests coverage, drop yarn in favour of npm, formatting
1 parent 807fafa commit eff1b16

File tree

13 files changed

+3004
-751
lines changed

13 files changed

+3004
-751
lines changed

.github/workflows/react.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ jobs:
3333
- name: Install dependencies
3434
run: npm ci
3535

36-
- name: Test formatting
36+
- name: Formatting
3737
run: npm run test:format
3838

39-
- name: Test types
39+
- name: Types
4040
run: npm run test:types

.github/workflows/web.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Web
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- web/**
9+
- .github/workflows/web.yaml
10+
pull_request:
11+
branches:
12+
- main
13+
paths:
14+
- web/**
15+
- .github/workflows/web.yaml
16+
17+
jobs:
18+
test:
19+
runs-on: ubuntu-latest
20+
defaults:
21+
run:
22+
working-directory: web
23+
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
28+
- name: Set up Node.js
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: "22"
32+
33+
- name: Install dependencies
34+
run: npm ci
35+
36+
- name: Formatting
37+
run: npm run test:format
38+
39+
- name: Types
40+
run: npm run test:types
41+
42+
- name: Unit tests
43+
run: npm run test:unit

web/.prettierignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
dist/
2+
3+
package.json
4+
package-lock.json
5+
6+
.prettierignore
7+
.prettierrc
8+
.DS_Store

web/.prettierrc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"singleQuote": true,
33
"trailingComma": "all",
44
"bracketSpacing": true,
5-
"jsxBracketSameLine": true,
65
"printWidth": 120,
76
"tabWidth": 2,
87
"useTabs": false,
@@ -26,6 +25,12 @@
2625
"options": {
2726
"parser": "json"
2827
}
28+
},
29+
{
30+
"files": "*.md",
31+
"options": {
32+
"parser": "markdown"
33+
}
2934
}
3035
]
3136
}

web/README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@ Add this script in the head of your webpage:
4444

4545
_Replace `companyIdentifier` with your own_
4646

47+
<!-- prettier-ignore-start -->
4748
```html
4849
<script
4950
src="https://unpkg.com/@simplepdf/web-embed-pdf"
5051
companyIdentifier="yourcompany"
5152
defer
5253
></script>
5354
```
55+
<!-- prettier-ignore-end -->
5456

5557
## How does it work?
5658

@@ -69,9 +71,7 @@ Exclude any anchor tags from opening SimplePDF by adding the class `exclude-simp
6971
Add a class `simplepdf` to any anchor tag to open them with SimplePDF:
7072

7173
```html
72-
<a href="/example_without_pdf_extension" class="simplepdf"
73-
>Open with SimplePDF</a
74-
>
74+
<a href="/example_without_pdf_extension" class="simplepdf">Open with SimplePDF</a>
7575
```
7676

7777
## Advanced usage
@@ -91,6 +91,7 @@ SimplePDF currently supports the following languages automatically detects the l
9191

9292
**If you wish to override the automatic detection, you can specify the `locale` attribute on the script tag as follows**:
9393

94+
<!-- prettier-ignore-start -->
9495
```html
9596
<script
9697
src="https://unpkg.com/@simplepdf/web-embed-pdf"
@@ -99,13 +100,14 @@ SimplePDF currently supports the following languages automatically detects the l
99100
defer
100101
></script>
101102
```
103+
<!-- prettier-ignore-end -->
102104

103105
### Opening the editor programmatically
104106

105107
#### Open the editor with a specific PDF
106108

107109
```javascript
108-
window.simplePDF.openEditor({ href: "publicly_available_url_pdf" });
110+
window.simplePDF.openEditor({ href: 'publicly_available_url_pdf' });
109111
```
110112

111113
#### Let your customers pick the PDF on their computer
@@ -133,17 +135,18 @@ _Do not store sensitive information in the context (!!) as it is available local
133135

134136
```javascript
135137
window.simplePDF.openEditor({
136-
href: "publicly_available_url_pdf",
138+
href: 'publicly_available_url_pdf',
137139
context: {
138-
customer_id: "123",
139-
environment: "prod",
140+
customer_id: '123',
141+
environment: 'prod',
140142
},
141143
});
142144
```
143145

144146
### Updating the configuration programmatically
145147

146148
**Use-cases:**
149+
147150
- Change the locale at run time
148151
- Enabling / Disabling _Auto Open_: automatically opening the editor for anchor tags pointing to PDF files. By default enabled when SimplePDF is added as a script
149152
- Change the company identifier at run time
@@ -153,4 +156,4 @@ window.simplePDF.setConfig({
153156
locale: 'fr',
154157
autoOpen: false,
155158
});
156-
```
159+
```

0 commit comments

Comments
 (0)