Open markdown links externally (#100)
This commit is contained in:
@@ -12,6 +12,7 @@ import { useAtomValue } from "jotai";
|
|||||||
import { isStreamingAtom } from "@/atoms/chatAtoms";
|
import { isStreamingAtom } from "@/atoms/chatAtoms";
|
||||||
import { CustomTagState } from "./stateTypes";
|
import { CustomTagState } from "./stateTypes";
|
||||||
import { DyadOutput } from "./DyadOutput";
|
import { DyadOutput } from "./DyadOutput";
|
||||||
|
import { IpcClient } from "@/ipc/ipc_client";
|
||||||
|
|
||||||
interface DyadMarkdownParserProps {
|
interface DyadMarkdownParserProps {
|
||||||
content: string;
|
content: string;
|
||||||
@@ -29,11 +30,27 @@ type ContentPiece =
|
|||||||
| { type: "markdown"; content: string }
|
| { type: "markdown"; content: string }
|
||||||
| { type: "custom-tag"; tagInfo: CustomTagInfo };
|
| { type: "custom-tag"; tagInfo: CustomTagInfo };
|
||||||
|
|
||||||
|
const customLink = ({ node, ...props }: { node?: any; [key: string]: any }) => (
|
||||||
|
<a
|
||||||
|
{...props}
|
||||||
|
onClick={(e) => {
|
||||||
|
const url = props.href;
|
||||||
|
if (url) {
|
||||||
|
e.preventDefault();
|
||||||
|
IpcClient.getInstance().openExternalUrl(url);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
export const VanillaMarkdownParser = ({ content }: { content: string }) => {
|
export const VanillaMarkdownParser = ({ content }: { content: string }) => {
|
||||||
return (
|
return (
|
||||||
<ReactMarkdown
|
<ReactMarkdown
|
||||||
rehypePlugins={[rehypeRaw]}
|
rehypePlugins={[rehypeRaw]}
|
||||||
components={{ code: CodeHighlight } as any}
|
components={{
|
||||||
|
code: CodeHighlight,
|
||||||
|
a: customLink,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{content}
|
{content}
|
||||||
</ReactMarkdown>
|
</ReactMarkdown>
|
||||||
@@ -60,7 +77,10 @@ export const DyadMarkdownParser: React.FC<DyadMarkdownParserProps> = ({
|
|||||||
? piece.content && (
|
? piece.content && (
|
||||||
<ReactMarkdown
|
<ReactMarkdown
|
||||||
rehypePlugins={[rehypeRaw]}
|
rehypePlugins={[rehypeRaw]}
|
||||||
components={{ code: CodeHighlight } as any}
|
components={{
|
||||||
|
code: CodeHighlight,
|
||||||
|
a: customLink,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{piece.content}
|
{piece.content}
|
||||||
</ReactMarkdown>
|
</ReactMarkdown>
|
||||||
|
|||||||
Reference in New Issue
Block a user