Skip to content

Commit 12c695f

Browse files
authored
Merge pull request #3 from react18-tools/fix-must-have-protocol
Fix must have protocol
2 parents bda54a0 + 5ff99b1 commit 12c695f

File tree

6 files changed

+39
-8
lines changed

6 files changed

+39
-8
lines changed

lib/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# react-markdown-autolink
22

3+
## 0.0.2
4+
5+
### Patch Changes
6+
7+
- aa934d7: Urls must have protocols as many markdown parsers don't parse <my-domain.com>
8+
39
## 0.0.1
410

511
### Patch Changes

lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "react-markdown-autolink",
33
"author": "Mayank Kumar Chaudhari <https://mayank-chaudhari.vercel.app>",
44
"private": false,
5-
"version": "0.0.1",
5+
"version": "0.0.2",
66
"description": "A highly lightweight utility that automatically detects and makes links clickable in Markdown.",
77
"license": "MPL-2.0",
88
"main": "./dist/index.js",

lib/src/index.test.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,23 @@ import { describe, test } from "vitest";
22
import { autoLinkMd } from "../src";
33

44
describe("react-markdown-autolink", () => {
5-
test("test autolink", ({ expect }) => {
6-
expect(autoLinkMd("this is a link: google.com")).toBe("this is a link: <google.com>");
5+
test("test autolink url", ({ expect }) => {
6+
expect(autoLinkMd("this is a link: https://google.com")).toBe(
7+
"this is a link: <https://google.com>",
8+
);
9+
});
10+
test("test autolink email", ({ expect }) => {
11+
expect(autoLinkMd("this is a email: [email protected]")).toBe(
12+
"this is a email: <[email protected]>",
13+
);
14+
});
15+
test("test autolink with mixed text", ({ expect }) => {
16+
expect(
17+
autoLinkMd(
18+
"this is a email: [email protected] and this is url: https://google.com and this is invalid url: google.com (without protocol)",
19+
),
20+
).toBe(
21+
"this is a email: <[email protected]> and this is url: <https://google.com> and this is invalid url: google.com (without protocol)",
22+
);
723
});
824
});

lib/src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export const autoLinkMd = (str: string) =>
2-
str.replace(
3-
/((ftp|https?):\/\/)?[\w_-]+(\.[\w_-]+)+[\w@?^=%&\/~+#-.:,]*[\w@?^=%&\/~+#-]/g,
4-
match => `<${match}>`,
5-
);
2+
str
3+
.replace(
4+
/(ftp|https?):\/\/[\w_-]+(\.[\w_-]+)+[\w@?^=%&/~+#.:,-]*[\w@?^=%&/~+#-]/g,
5+
match => `<${match}>`,
6+
)
7+
.replace(/[\w._%+-]+@[\w.-]+\.[a-zA-Z]{2,}/g, match => `<${match}>`);

packages/shared/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# @repo/shared
22

3+
## 0.0.2
4+
5+
### Patch Changes
6+
7+
- Updated dependencies [aa934d7]
8+
9+
310
## 0.0.1
411

512
### Patch Changes

packages/shared/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@repo/shared",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"private": true,
55
"sideEffects": false,
66
"main": "./dist/index.js",

0 commit comments

Comments
 (0)