-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(lib): remove Article component and refactor Code component w…
…ith shiki
- Loading branch information
Showing
16 changed files
with
410 additions
and
210 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ node_modules | |
dist | ||
storybook-static | ||
coverage | ||
.DS_Store |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,55 @@ | ||
'use client'; | ||
|
||
import { highlight } from 'sugar-high'; | ||
import './code.css'; | ||
|
||
export const Code = ({ children, ...props }: { children: string }) => { | ||
let codeHTML = highlight(children); | ||
return ( | ||
<code | ||
dangerouslySetInnerHTML={{ __html: codeHTML }} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
import type { JSX } from 'react'; | ||
import type { BundledLanguage } from 'shiki'; | ||
import { codeToHast } from 'shiki'; | ||
import { Components, toJsxRuntime } from 'hast-util-to-jsx-runtime'; | ||
import { Fragment } from 'react'; | ||
import { jsx, jsxs } from 'react/jsx-runtime'; | ||
|
||
interface Props { | ||
children: string; | ||
lang: BundledLanguage; | ||
className: string; | ||
} | ||
|
||
async function CodeBlock(props: Props) { | ||
let lang = 'text'; // default monospaced text | ||
|
||
if (props.lang && props.lang.startsWith('lang-')) { | ||
lang = props.lang.replace('lang-', ''); | ||
} | ||
|
||
if (props.className && props.className.startsWith('lang-')) { | ||
lang = props.className.replace('lang-', ''); | ||
} | ||
|
||
const hast = await codeToHast(props.children, { | ||
lang, | ||
themes: { | ||
dark: 'material-theme-ocean', | ||
light: 'min-light', | ||
}, | ||
}); | ||
|
||
return toJsxRuntime(hast, { | ||
Fragment, | ||
jsx, | ||
jsxs, | ||
components: { | ||
pre: (props: any) => ( | ||
<pre | ||
{...props} | ||
className="code-block rounded-xl border" | ||
/> | ||
), | ||
} as Components, | ||
}) as JSX.Element; | ||
} | ||
|
||
async function PreBlock({ children }: { children: any }) { | ||
if ('type' in children && children['type'] === 'code') { | ||
return CodeBlock(children['props']); | ||
} | ||
return children; | ||
} | ||
|
||
export { CodeBlock, PreBlock }; |
This file was deleted.
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
import './global.scss'; | ||
|
||
export * from './Callout/Callout'; | ||
export * from './Accordion/Accordion'; | ||
export * from './Steps/Steps'; | ||
export * from './Tabs/Tabs'; | ||
export * from './Article/Article'; | ||
export * from './Code/Code'; | ||
export * from './Typography/Typography'; | ||
|
||
export * from './utils'; |
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
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const CodeSamples = () => { | ||
return <></>; | ||
}; |
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
Oops, something went wrong.