Skip to content
This repository was archived by the owner on Aug 8, 2025. It is now read-only.

Commit 6d9fd92

Browse files
committed
[feature]: parse link to external sites;
1 parent 6c46586 commit 6d9fd92

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/component/markdown/MarkdownToHTMLRenderer.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const parseInlineMarkdown = (line: string): React.ReactNode[] => {
1717
{ regex: /\*(.*?)\*/, tag: 'em' },
1818
{ regex: /`([^`]+)`/, tag: 'code' },
1919
{ regex: /\[([^\]]+)\]\(([^)]+)\)/, tag: 'a' },
20+
{ regex: /(https?:\/\/[^\s)]+[^\s).,;:'"\]\s])/, tag: 'auto-link' },
2021
];
2122

2223
while (line.length) {
@@ -56,6 +57,12 @@ const parseInlineMarkdown = (line: string): React.ReactNode[] => {
5657
{content}
5758
</a>
5859
);
60+
} else if (pattern.tag === 'auto-link') {
61+
parts.push(
62+
<a key={parts.length} href={match[1]} target="_blank" rel="noreferrer">
63+
{match[1]}
64+
</a>
65+
);
5966
}
6067

6168
line = remaining;
@@ -172,7 +179,7 @@ const parseMarkdown = (raw: string) => {
172179

173180
// Flush any remaining list at end
174181
flushList(lines.length);
175-
182+
176183
return elements;
177184
};
178185

0 commit comments

Comments
 (0)