-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from 8845musign/fix/sytax-highlite
Fix syntax highlighting not working in production builds
- Loading branch information
Showing
9 changed files
with
1,073 additions
and
240 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,56 +1,51 @@ | ||
.example { | ||
position: relative; | ||
width: 100%; | ||
margin-right: auto; | ||
margin-left: auto; | ||
border: 1px solid var(--color-ubie-black-200); | ||
border-radius: 6px; | ||
.demo { | ||
position: relative; | ||
height: 300px; | ||
border: 1px solid var(--color-ubie-black-200); | ||
border-radius: var(--radius-sm); | ||
} | ||
|
||
.demoFrame { | ||
width: 100%; | ||
min-height: 100%; | ||
} | ||
|
||
.externalLink { | ||
position: absolute; | ||
top: 4px; | ||
right: 4px; | ||
display: inline-flex; | ||
align-items: center; | ||
justify-content: center; | ||
min-height: 32px; | ||
padding: var(--size-spacing-xxs) var(--size-spacing-xs) calc(var(--size-spacing-xxs) - 0.125rem); | ||
font-weight: bold; | ||
color: var(--color-primary); | ||
background-color: rgb(255 255 255 / 75%); | ||
border: none; | ||
position: absolute; | ||
top: 4px; | ||
right: 4px; | ||
display: inline-flex; | ||
align-items: center; | ||
justify-content: center; | ||
min-height: 32px; | ||
padding: var(--size-spacing-xxs) var(--size-spacing-xs) calc(var(--size-spacing-xxs) - 0.125rem); | ||
font-weight: bold; | ||
color: var(--color-primary); | ||
background-color: rgb(255 255 255 / 75%); | ||
border: none; | ||
} | ||
|
||
.externalLink:active { | ||
background-color: var(--color-ubie-black-200); | ||
background-color: var(--color-ubie-black-200); | ||
} | ||
|
||
@media (hover:hover) { | ||
.externalLink:hover { | ||
background-color: var(--color-ubie-black-100); | ||
} | ||
@media (hover: hover) { | ||
.externalLink:hover { | ||
background-color: var(--color-ubie-black-100); | ||
} | ||
} | ||
|
||
.code { | ||
position: relative; | ||
position: relative; | ||
margin-top: var(--size-spacing-sm); | ||
} | ||
|
||
.codePrism { | ||
margin: 0 !important; | ||
margin: 0 !important; | ||
} | ||
|
||
.copy { | ||
position: absolute; | ||
top: 4px; | ||
right: 4px; | ||
position: absolute; | ||
top: 4px; | ||
right: 4px; | ||
} | ||
|
||
.demo { | ||
height: 300px | ||
} | ||
|
||
.demoFrame { | ||
width: 100%; | ||
min-height: 100%; | ||
} |
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
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,5 @@ | ||
.wrapper :global(> .shiki) { | ||
padding: var(--size-spacing-sm); | ||
margin: 0; | ||
border-radius: var(--radius-sm); | ||
} |
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,37 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { getHighlighter } from 'shikiji'; | ||
import styles from './SyntaxHighlighter.module.css'; | ||
import type { FC } from 'react'; | ||
|
||
interface Props { | ||
children: string; | ||
lang: Lang; | ||
} | ||
|
||
const langs = ['javascript', 'typescript', 'html', 'css', 'jsx']; | ||
type Lang = (typeof langs)[number]; | ||
|
||
const SyntaxHighligter: FC<Props> = ({ children, lang }) => { | ||
const [code, setCode] = useState(''); | ||
|
||
useEffect(() => { | ||
const convert = async () => { | ||
const highlighter = await getHighlighter({ | ||
langs, | ||
themes: ['github-dark'], | ||
}); | ||
|
||
const code = highlighter.codeToHtml(children, { | ||
lang: 'javascript', | ||
theme: 'github-dark', | ||
}); | ||
setCode(code); | ||
}; | ||
|
||
convert(); | ||
}, [children, lang]); | ||
|
||
return <div className={styles.wrapper} dangerouslySetInnerHTML={{ __html: code }} />; | ||
}; | ||
|
||
export default SyntaxHighligter; |
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