feat: implement auto link parser

This commit is contained in:
Steven
2023-12-27 08:44:51 +08:00
parent 6fac116d8c
commit c8d7f93dca
14 changed files with 418 additions and 179 deletions

View File

@ -0,0 +1,17 @@
interface Props {
url: string;
}
const AutoLink: React.FC<Props> = ({ url }: Props) => {
return (
<a
className="text-blue-600 dark:text-blue-400 cursor-pointer underline break-all hover:opacity-80 decoration-1"
href={url}
target="_blank"
>
{url}
</a>
);
};
export default AutoLink;

View File

@ -5,7 +5,11 @@ interface Props {
const Link: React.FC<Props> = ({ text, url }: Props) => {
return (
<a className="text-blue-600 dark:text-blue-400 cursor-pointer underline break-all hover:opacity-80 decoration-1" href={url}>
<a
className="text-blue-600 dark:text-blue-400 cursor-pointer underline break-all hover:opacity-80 decoration-1"
href={url}
target="_blank"
>
{text}
</a>
);

View File

@ -1,4 +1,5 @@
import {
AutoLinkNode,
BlockquoteNode,
BoldItalicNode,
BoldNode,
@ -20,6 +21,7 @@ import {
TextNode,
UnorderedListNode,
} from "@/types/proto/api/v2/markdown_service";
import AutoLink from "./AutoLink";
import Blockquote from "./Blockquote";
import Bold from "./Bold";
import BoldItalic from "./BoldItalic";
@ -78,6 +80,8 @@ const Renderer: React.FC<Props> = ({ node }: Props) => {
return <Image {...(node.imageNode as ImageNode)} />;
case NodeType.LINK:
return <Link {...(node.linkNode as LinkNode)} />;
case NodeType.AUTO_LINK:
return <AutoLink {...(node.autoLinkNode as AutoLinkNode)} />;
case NodeType.TAG:
return <Tag {...(node.tagNode as TagNode)} />;
case NodeType.STRIKETHROUGH: