From 91837e8fa46e617ef1d78084484d5f78a07a77ac Mon Sep 17 00:00:00 2001 From: Lazar Nikolov Date: Sat, 29 Mar 2025 08:08:34 -0400 Subject: [PATCH 1/3] fix(mdx): making sure last highlighted line is pushed when making highlight blocks --- src/components/codeHighlights/codeHighlights.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/codeHighlights/codeHighlights.tsx b/src/components/codeHighlights/codeHighlights.tsx index c101d65bf934b..219848ca5bc80 100644 --- a/src/components/codeHighlights/codeHighlights.tsx +++ b/src/components/codeHighlights/codeHighlights.tsx @@ -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; @@ -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( @@ -51,8 +53,9 @@ export function makeHighlightBlocks( ); highlightedLineElements = []; ++highlightElementGroupCounter; + } else { + arr.push(child); } - arr.push(child); } return arr; From c0074d6598f249125adc879ec3eb2ad915c320c5 Mon Sep 17 00:00:00 2001 From: Lazar Nikolov Date: Sat, 29 Mar 2025 09:55:31 -0400 Subject: [PATCH 2/3] fix(mdx): improved code highlights parser --- src/components/codeHighlights/codeHighlights.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/components/codeHighlights/codeHighlights.tsx b/src/components/codeHighlights/codeHighlights.tsx index 219848ca5bc80..0d087dc6bf624 100644 --- a/src/components/codeHighlights/codeHighlights.tsx +++ b/src/components/codeHighlights/codeHighlights.tsx @@ -42,9 +42,17 @@ export function makeHighlightBlocks( if (isHighlightedLine) { highlightedLineElements.push(element); - } - if (!isHighlightedLine || index === items.length - 1) { + // If it's the last line that's highlighted, push it + if (index === items.length - 1) { + arr.push( + + {...highlightedLineElements} + + ); + } + } else { + // Check for an opened highlight group before pushing the new line if (highlightedLineElements.length > 0) { arr.push( @@ -53,9 +61,9 @@ export function makeHighlightBlocks( ); highlightedLineElements = []; ++highlightElementGroupCounter; - } else { - arr.push(child); } + + arr.push(child); } return arr; From 4d07693aa167eaf4ca6fa9ea536b44d98071afe9 Mon Sep 17 00:00:00 2001 From: Lazar Nikolov Date: Sat, 29 Mar 2025 09:56:12 -0400 Subject: [PATCH 3/3] fix(style): removing codeblock bottom padding if last child is a highlight block --- src/components/codeBlock/code-blocks.module.scss | 5 ++++- src/components/codeHighlights/codeHighlights.tsx | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/codeBlock/code-blocks.module.scss b/src/components/codeBlock/code-blocks.module.scss index aebf464edcac6..cae98176e9424 100644 --- a/src/components/codeBlock/code-blocks.module.scss +++ b/src/components/codeBlock/code-blocks.module.scss @@ -57,6 +57,10 @@ min-width: 100%; } + :global(.code-highlight > .highlight-block:last-child) { + margin-bottom: -10px; + } + :global(.code-line) { display: block; float: left; @@ -74,7 +78,6 @@ } } - /* Diff highlighting, classes provided by rehype-prism-plus */ /* Set inserted line (+) color */ /* Move the margin left and adjust width so we can keep the parent padding */ diff --git a/src/components/codeHighlights/codeHighlights.tsx b/src/components/codeHighlights/codeHighlights.tsx index 0d087dc6bf624..b50355f8ef2d0 100644 --- a/src/components/codeHighlights/codeHighlights.tsx +++ b/src/components/codeHighlights/codeHighlights.tsx @@ -109,7 +109,7 @@ export function HighlightBlock({ } return ( - + {children} {showCopyButton && !copied && (