diff --git a/lib/CHANGELOG.md b/lib/CHANGELOG.md index 0da0a3a1..e9d18cb3 100644 --- a/lib/CHANGELOG.md +++ b/lib/CHANGELOG.md @@ -1,5 +1,11 @@ # react-markdown-autolink +## 0.0.2 + +### Patch Changes + +- aa934d7: Urls must have protocols as many markdown parsers don't parse + ## 0.0.1 ### Patch Changes diff --git a/lib/package.json b/lib/package.json index d49d6fb4..4344ac00 100644 --- a/lib/package.json +++ b/lib/package.json @@ -2,7 +2,7 @@ "name": "react-markdown-autolink", "author": "Mayank Kumar Chaudhari ", "private": false, - "version": "0.0.1", + "version": "0.0.2", "description": "A highly lightweight utility that automatically detects and makes links clickable in Markdown.", "license": "MPL-2.0", "main": "./dist/index.js", diff --git a/lib/src/index.test.ts b/lib/src/index.test.ts index 65125833..6e8c054f 100644 --- a/lib/src/index.test.ts +++ b/lib/src/index.test.ts @@ -2,7 +2,23 @@ import { describe, test } from "vitest"; import { autoLinkMd } from "../src"; describe("react-markdown-autolink", () => { - test("test autolink", ({ expect }) => { - expect(autoLinkMd("this is a link: google.com")).toBe("this is a link: "); + test("test autolink url", ({ expect }) => { + expect(autoLinkMd("this is a link: https://google.com")).toBe( + "this is a link: ", + ); + }); + test("test autolink email", ({ expect }) => { + expect(autoLinkMd("this is a email: my-email@mail.com")).toBe( + "this is a email: ", + ); + }); + test("test autolink with mixed text", ({ expect }) => { + expect( + autoLinkMd( + "this is a email: my-email@mail.com and this is url: https://google.com and this is invalid url: google.com (without protocol)", + ), + ).toBe( + "this is a email: and this is url: and this is invalid url: google.com (without protocol)", + ); }); }); diff --git a/lib/src/index.ts b/lib/src/index.ts index 4bc91e42..efb85527 100644 --- a/lib/src/index.ts +++ b/lib/src/index.ts @@ -1,5 +1,7 @@ export const autoLinkMd = (str: string) => - str.replace( - /((ftp|https?):\/\/)?[\w_-]+(\.[\w_-]+)+[\w@?^=%&\/~+#-.:,]*[\w@?^=%&\/~+#-]/g, - match => `<${match}>`, - ); + str + .replace( + /(ftp|https?):\/\/[\w_-]+(\.[\w_-]+)+[\w@?^=%&/~+#.:,-]*[\w@?^=%&/~+#-]/g, + match => `<${match}>`, + ) + .replace(/[\w._%+-]+@[\w.-]+\.[a-zA-Z]{2,}/g, match => `<${match}>`); diff --git a/packages/shared/CHANGELOG.md b/packages/shared/CHANGELOG.md index 9d9ad9e3..80a261ee 100644 --- a/packages/shared/CHANGELOG.md +++ b/packages/shared/CHANGELOG.md @@ -1,5 +1,12 @@ # @repo/shared +## 0.0.2 + +### Patch Changes + +- Updated dependencies [aa934d7] + - react-markdown-autolink@0.0.2 + ## 0.0.1 ### Patch Changes diff --git a/packages/shared/package.json b/packages/shared/package.json index d8809696..f9b4868b 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -1,6 +1,6 @@ { "name": "@repo/shared", - "version": "0.0.1", + "version": "0.0.2", "private": true, "sideEffects": false, "main": "./dist/index.js",