Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: component CodeBlock not able to highlight lines. #3480

Merged
merged 10 commits into from
Jan 14, 2025
18 changes: 15 additions & 3 deletions components/editor/CodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,20 +275,32 @@ export default function CodeBlock({
lineNumberStyle={(lineNumber: number) => {
const isHighlighted = highlightedLines && highlightedLines.includes(lineNumber);

return {
const styles = {
display: 'inline-block',
marginLeft: '16px',
paddingRight: '16px',
background: isHighlighted ? '#252f3f' : 'inherit',
backgroundColor: isHighlighted ? '#3e4d64' : '#252f3f',
color: isHighlighted ? '#A3ACAD' : '#8B9394'
};

return styles;
}}
wrapLines={true}
lineProps={(lineNumber: number) => {
const isHighlighted = highlightedLines && highlightedLines.includes(lineNumber);
SahilDahekar marked this conversation as resolved.
Show resolved Hide resolved

const style: React.CSSProperties = {
paddingRight: '2rem'
};

if (isHighlighted) {
style.display = 'block';
style.width = '100%';
style.backgroundColor = '#3e4d64';
}

return {
className: `${isHighlighted ? 'bg-code-editor-dark-highlight block ml-10 w-full' : ''} pr-8`
style
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SahilDahekar Why are we relying on custom CSS instead of tailwind utility classes?

Copy link
Contributor Author

@SahilDahekar SahilDahekar Dec 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why but tailwind utility classes were not understood by the react-syntax-highlight library . Other than this i think passing custom css to a external library is a safer option than relying on it for parsing tailwind utility classes

};
}}
codeTagProps={{
Expand Down
Loading