Skip to content

Commit

Permalink
fix: component CodeBlock not able to highlight lines. (#3480)
Browse files Browse the repository at this point in the history
Co-authored-by: Akshat Nema <[email protected]>%0ACo-authored-by: asyncapi-bot <[email protected]>
  • Loading branch information
SahilDahekar and asyncapi-bot authored Jan 14, 2025
1 parent 45fb086 commit e3722be
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions components/editor/CodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,22 +273,34 @@ export default function CodeBlock({
background: '#252f3f'
}}
lineNumberStyle={(lineNumber: number) => {
const isHighlighted = highlightedLines && highlightedLines.includes(lineNumber);
const isHighlighted = highlightedLines?.includes(lineNumber);

return {
const styles: React.CSSProperties = {
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);
const isHighlighted = highlightedLines?.includes(lineNumber);

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
};
}}
codeTagProps={{
Expand Down

0 comments on commit e3722be

Please sign in to comment.