Skip to content

Fix must have protocol #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# react-markdown-autolink

## 0.0.2

### Patch Changes

- aa934d7: Urls must have protocols as many markdown parsers don't parse <my-domain.com>

## 0.0.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "react-markdown-autolink",
"author": "Mayank Kumar Chaudhari <https://mayank-chaudhari.vercel.app>",
"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",
Expand Down
20 changes: 18 additions & 2 deletions lib/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: <google.com>");
test("test autolink url", ({ expect }) => {
expect(autoLinkMd("this is a link: https://google.com")).toBe(
"this is a link: <https://google.com>",
);
});
test("test autolink email", ({ expect }) => {
expect(autoLinkMd("this is a email: [email protected]")).toBe(
"this is a email: <[email protected]>",
);
});
test("test autolink with mixed text", ({ expect }) => {
expect(
autoLinkMd(
"this is a email: [email protected] and this is url: https://google.com and this is invalid url: google.com (without protocol)",
),
).toBe(
"this is a email: <[email protected]> and this is url: <https://google.com> and this is invalid url: google.com (without protocol)",
);
});
});
10 changes: 6 additions & 4 deletions lib/src/index.ts
Original file line number Diff line number Diff line change
@@ -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}>`);
7 changes: 7 additions & 0 deletions packages/shared/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @repo/shared

## 0.0.2

### Patch Changes

- Updated dependencies [aa934d7]
- [email protected]

## 0.0.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@repo/shared",
"version": "0.0.1",
"version": "0.0.2",
"private": true,
"sideEffects": false,
"main": "./dist/index.js",
Expand Down