-
-
Notifications
You must be signed in to change notification settings - Fork 772
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove shiki vercel not support this
Signed-off-by: Innei <i@innei.in>
- Loading branch information
Showing
3 changed files
with
129 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/components/ui/code-highlighter/CodeHighlighter.tsx.backup_
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React, { useCallback, useLayoutEffect, useRef } from 'react' | ||
import type { FC } from 'react' | ||
|
||
import { useIsPrintMode } from '~/atoms/css-media' | ||
import { useIsDark } from '~/hooks/common/use-is-dark' | ||
import { toast } from '~/lib/toast' | ||
|
||
import styles from './CodeHighlighter.module.css' | ||
import { renderCodeHighlighter } from './render.server' | ||
|
||
declare global { | ||
interface Window { | ||
Prism: any | ||
} | ||
} | ||
|
||
interface Props { | ||
lang: string | undefined | ||
content: string | ||
} | ||
|
||
export const HighLighter: FC<Props> = (props) => { | ||
const { lang: language, content: value } = props | ||
|
||
const handleCopy = useCallback(() => { | ||
navigator.clipboard.writeText(value) | ||
toast.success('COPIED!') | ||
}, [value]) | ||
|
||
const isPrintMode = useIsPrintMode() | ||
const isDark = useIsDark() | ||
|
||
useLayoutEffect(() => { | ||
;(async () => { | ||
const html = await renderCodeHighlighter( | ||
value, | ||
language as string, | ||
isPrintMode ? 'github-light' : isDark ? 'github-dark' : 'github-light', | ||
) | ||
if (!ref.current) { | ||
return | ||
} | ||
ref.current.innerHTML = html | ||
})() | ||
}, [isDark, value, language, isPrintMode]) | ||
|
||
const ref = useRef<HTMLElement>(null) | ||
return ( | ||
<div className={styles['code-wrap']}> | ||
<span className={styles['language-tip']} aria-hidden> | ||
{language?.toUpperCase()} | ||
</span> | ||
|
||
<pre className="line-numbers !bg-transparent" data-start="1"> | ||
<code | ||
className={`language-${language ?? 'markup'} !bg-transparent`} | ||
ref={ref} | ||
> | ||
{value} | ||
</code> | ||
</pre> | ||
|
||
<div className={styles['copy-tip']} onClick={handleCopy} aria-hidden> | ||
Copy | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dbf1dd4
There was a problem hiding this comment.
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 – ./
springtide.vercel.app
shiro-innei.vercel.app
innei.in
shiro-git-main-innei.vercel.app