Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/components/codeHighlights/codeHighlights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function makeHighlightBlocks(
let highlightedLineElements: ReactElement[] = [];
let highlightElementGroupCounter = 0;

return items.reduce((arr: ChildrenItem[], child) => {
return items.reduce((arr: ChildrenItem[], child, index) => {
if (typeof child !== 'object') {
arr.push(child);
return arr;
Expand All @@ -42,7 +42,9 @@ export function makeHighlightBlocks(

if (isHighlightedLine) {
highlightedLineElements.push(element);
} else {
}

if (!isHighlightedLine || index === items.length - 1) {
if (highlightedLineElements.length > 0) {
arr.push(
<HighlightBlock key={highlightElementGroupCounter} language={language}>
Expand All @@ -51,8 +53,9 @@ export function makeHighlightBlocks(
);
highlightedLineElements = [];
++highlightElementGroupCounter;
} else {
arr.push(child);
}
arr.push(child);
}

return arr;
Expand Down
Loading