Skip to content

Commit c0074d6

Browse files
committed
fix(mdx): improved code highlights parser
1 parent 91837e8 commit c0074d6

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/components/codeHighlights/codeHighlights.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,17 @@ export function makeHighlightBlocks(
4242

4343
if (isHighlightedLine) {
4444
highlightedLineElements.push(element);
45-
}
4645

47-
if (!isHighlightedLine || index === items.length - 1) {
46+
// If it's the last line that's highlighted, push it
47+
if (index === items.length - 1) {
48+
arr.push(
49+
<HighlightBlock key={highlightElementGroupCounter} language={language}>
50+
{...highlightedLineElements}
51+
</HighlightBlock>
52+
);
53+
}
54+
} else {
55+
// Check for an opened highlight group before pushing the new line
4856
if (highlightedLineElements.length > 0) {
4957
arr.push(
5058
<HighlightBlock key={highlightElementGroupCounter} language={language}>
@@ -53,9 +61,9 @@ export function makeHighlightBlocks(
5361
);
5462
highlightedLineElements = [];
5563
++highlightElementGroupCounter;
56-
} else {
57-
arr.push(child);
5864
}
65+
66+
arr.push(child);
5967
}
6068

6169
return arr;

0 commit comments

Comments
 (0)