layers-design-system 2.0.7 → 2.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "layers-design-system",
3
3
  "main": "src/main.js",
4
- "version": "2.0.7",
4
+ "version": "2.0.8",
5
5
  "scripts": {
6
6
  "start": "vue-cli-service serve ./src/main-docs.js",
7
7
  "build": "vue-cli-service build --target lib ./src/main.js",
@@ -2,12 +2,12 @@ const urlRegex = require('url-regex-safe')
2
2
 
3
3
  const customUrlRegex = new RegExp(
4
4
  '((href=")?)' +
5
- urlRegex({
6
- localhost: false,
7
- apostrophes: false,
8
- returnString: true,
9
- }) +
10
- '((</a>)?)',
5
+ urlRegex({
6
+ localhost: false,
7
+ apostrophes: false,
8
+ returnString: true,
9
+ }) +
10
+ '((</a>)?)',
11
11
  'g'
12
12
  )
13
13
 
@@ -28,9 +28,29 @@ export function addProtocol(link) {
28
28
  }
29
29
 
30
30
  export function mountLink(text) {
31
- return text.replace(customUrlRegex, (url) => {
32
- return url.startsWith('href="') || url.endsWith('</a>')
33
- ? url
34
- : mountTagA(url)
35
- })
36
- }
31
+ // Regular expression to match email addresses
32
+ const emailRegex = /(\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b)/g;
33
+
34
+ // Replace each email address in text with a mailto link
35
+ let finalText = text.replace(emailRegex, (email) => {
36
+ const href = `mailto:${email}`;
37
+ return getTagA(href, email);
38
+ });
39
+ let match;
40
+
41
+ // Loop through the text to find and replace URLs
42
+ while ((match = customUrlRegex.exec(finalText)) !== null) {
43
+ const url = match[0];
44
+
45
+ // Skip URLs that are parto of email addresses or already within anchor tags
46
+ if (finalText[match.index - 1] === '@' || url.startsWith('href="') || url.endsWith('</a>')) {
47
+ continue;
48
+ }
49
+ const finalIndex = match.index + url.length;
50
+ const finalUrl = mountTagA(url);
51
+
52
+ // Replace the URL with the formatted ancho tag
53
+ finalText = finalText.substring(0, match.index) + finalUrl + finalText.substring(finalIndex);
54
+ }
55
+ return finalText;
56
+ }