Skip to content

Commit

Permalink
feat: add footnotes prompt (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
TNXG authored Oct 29, 2023
1 parent 42f03ca commit c50d283
Showing 1 changed file with 40 additions and 17 deletions.
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}`}
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"
wrapperClassName="footnotes_text"
>
<div className="space-y-2 leading-relaxed">
<p className="flex items-center space-x-1 opacity-80">
<span
className="font-medium"
dangerouslySetInnerHTML={{
__html: footnote?.footnote?.substring(1),
}}
/>
</p>
</div>
</FloatPopover>
)
},
},
Expand Down

1 comment on commit c50d283

@vercel
Copy link

@vercel vercel bot commented on c50d283 Oct 29, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

shiro – ./

shiro-innei.vercel.app
springtide.vercel.app
shiro-git-main-innei.vercel.app
innei.in

Please sign in to comment.