Skip to content

Instantly share code, notes, and snippets.

View RafaelDavisH's full-sized avatar
🏠
Working from home

Rafael D. Hernandez RafaelDavisH

🏠
Working from home
View GitHub Profile
@andrelandgraf
andrelandgraf / pre.tsx
Created December 26, 2021 17:35
PrismJS custom component
​import​ ​type​ ​{​ ​FC​,​ ​HTMLAttributes​,​ ​ReactElement​ ​}​ ​from​ ​'react'​;
​import​ ​{​ ​Children​ ​}​ ​from​ ​'react'​;
​import​ ​invariant​ ​from​ ​'tiny-invariant'​;
​import​ ​Highlight​,​ ​{​ ​Language​,​ ​defaultProps​ ​}​ ​from​ ​'prism-react-renderer'​;
​import​ ​CopyClipboardButton​ ​from​ ​'../button/copyClipboardButton'​;
​function​ ​getLanguageFromClassName​(​className​: ​string​)​ ​{
​  ​const​ ​match​ ​=​ ​className​.​match​(​/​language-​(​\w​+​)​/​)​;
​  ​return​ ​match​ ? ​match​[​1​]​ : ​''​;