Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add footnotes prompt #131

Merged
merged 1 commit into from
Oct 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 40 additions & 17 deletions src/components/ui/markdown/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Script from 'next/script'
import type { MarkdownToJSX } from 'markdown-to-jsx'
import type { FC, PropsWithChildren } from 'react'

import { FloatPopover } from '~/components/ui/float-popover'
import { MAIN_MARKDOWN_ID } from '~/constants/dom-id'
import { isDev } from '~/lib/env'
import { noopObj } from '~/lib/noop'
Expand Down Expand Up @@ -166,24 +167,46 @@ export const Markdown: FC<MdProps & MarkdownToJSX.Options & PropsWithChildren> =
return undefined
}
})()

const footnotes = () => {
return (
<Fragment key={state?.key}>
<a
href={`#fn:${content}`}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#fn 这种前缀太 magic 能不能封装一个函数。

onClick={(e) => {
e.preventDefault()
springScrollToElement(
document.getElementById(`fn:${content}`)!,
-window.innerHeight / 2,
)
redHighlight(`fn:${content}`)
}}
>
<sup id={`fnref:${content}`}>{`[^${content}]`}</sup>
</a>
{linkCardId && (
<LinkCard id={linkCardId} source="mx-space" />
)}
</Fragment>
)
}
return (
<Fragment key={state?.key}>
<a
href={`#fn:${content}`}
onClick={(e) => {
e.preventDefault()
springScrollToElement(
document.getElementById(`fn:${content}`)!,
-window.innerHeight / 2,
)
redHighlight(`fn:${content}`)
}}
>
<sup id={`fnref:${content}`}>{`[^${content}]`}</sup>
</a>
{linkCardId && <LinkCard id={linkCardId} source="mx-space" />}
</Fragment>
<FloatPopover
as="span"
TriggerComponent={footnotes}
type="popover"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type="popover"
type="tooltip"

wrapperClassName="footnotes_text"
>
<div className="space-y-2 leading-relaxed">
<p className="flex items-center space-x-1 opacity-80">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好像不是很需要

<span
className="font-medium"
dangerouslySetInnerHTML={{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要 dangerouslySetInnerHTML

__html: footnote?.footnote?.substring(1),
}}
/>
</p>
</div>
</FloatPopover>
)
},
},
Expand Down