-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add syntax highlighting to config block
Signed-off-by: Joe Fusco <[email protected]>
- Loading branch information
1 parent
1c773cd
commit 0ea6760
Showing
2 changed files
with
86 additions
and
111 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Highlight, { defaultProps } from 'prism-react-renderer'; | ||
import clsx from 'clsx'; | ||
|
||
export const highlightCode = (code, language, highlightLines = []) => { | ||
return ( | ||
<Highlight {...defaultProps} code={code} language={language}> | ||
{({ className, style, tokens, getLineProps, getTokenProps }) => ( | ||
<div className={clsx(className, 'code-highlight')} style={{ display: 'flex' }}> | ||
<pre className="flex-1 overflow-x-auto" style={style}> | ||
<code> | ||
{tokens.map((line, i) => { | ||
const lineNumber = i + 1; | ||
const isHighlighted = highlightLines.includes(lineNumber); | ||
const lineProps = getLineProps({ line, key: i }); | ||
|
||
return ( | ||
<div | ||
key={i} | ||
{...lineProps} | ||
style={{ ...lineProps.style, display: 'flex' }} | ||
className={clsx({ 'highlighted-line': isHighlighted })} | ||
> | ||
<span className="line-content"> | ||
{line.map((token, key) => ( | ||
<span key={key} {...getTokenProps({ token, key })} /> | ||
))} | ||
</span> | ||
</div> | ||
); | ||
})} | ||
</code> | ||
</pre> | ||
</div> | ||
)} | ||
</Highlight> | ||
); | ||
}; |
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