Skip to content

Commit

Permalink
feat: link with tooltip
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Jul 10, 2024
1 parent 6556b48 commit 875e76e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/renderer/src/components/ui/link/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Tooltip, TooltipContent, TooltipTrigger } from "../tooltip"

interface LinkProps {
href: string
title: string
children: React.ReactNode
target: string
}

export const LinkWithTooltip = (props: LinkProps) => (
<Tooltip delayDuration={0}>
<TooltipTrigger>
<a href={props.href} title={props.title} target={props.target}>{props.children}</a>
</TooltipTrigger>
<TooltipContent align="start" side="bottom">
{props.href}
</TooltipContent>
</Tooltip>
)
3 changes: 2 additions & 1 deletion src/renderer/src/lib/parse-html.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { ShikiHighLighter } from "@renderer/components/ui/code-highlighter"
import { Image } from "@renderer/components/ui/image"
import { LinkWithTooltip } from "@renderer/components/ui/link"
import { toJsxRuntime } from "hast-util-to-jsx-runtime"
import { createElement } from "react"
import { Fragment, jsx, jsxs } from "react/jsx-runtime"
Expand Down Expand Up @@ -69,6 +70,7 @@ export const parseHtml = async (
jsxs: (type, props, key) => jsxs(type as any, props, key),
passNode: true,
components: {
a: ({ node, ...props }) => createElement(LinkWithTooltip, { ...props } as any),
img: ({ node, ...props }) => createElement(Image, { ...props, popper: true }),
pre: ({ node, ...props }) => {
if (!props.children) return null
Expand Down Expand Up @@ -102,7 +104,6 @@ export const parseHtml = async (
}

if (!codeString) return null
// return createElement("pre", { ...props, className: "shiki" })
return createElement(ShikiHighLighter, {
code: codeString,
language: language.toLowerCase(),
Expand Down

0 comments on commit 875e76e

Please sign in to comment.