mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
feat: implement auto link parser
This commit is contained in:
17
web/src/components/MemoContent/AutoLink.tsx
Normal file
17
web/src/components/MemoContent/AutoLink.tsx
Normal 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;
|
@ -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>
|
||||
);
|
||||
|
@ -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:
|
||||
|
Reference in New Issue
Block a user