@@ -224,6 +224,9 @@ const setHighlightCode = ({ highlightCode, language, code }: { highlightCode: Re
224224 let pureElement = document . createElement ( 'div' )
225225 pureElement . innerHTML = hljs . highlight ( language , pureCode ) . value // Highlight DOM without modified tags
226226
227+ // Modified span is created per highlight operator and causes it to continue
228+ let innerModifiedTag = false
229+
227230 const diffElements = ( node : HTMLElement ) => {
228231 node . childNodes . forEach ( child => {
229232 if ( child . nodeType === 1 ) {
@@ -237,15 +240,21 @@ const setHighlightCode = ({ highlightCode, language, code }: { highlightCode: Re
237240 let oldContent = child . textContent
238241 let newContent = ''
239242
243+ if ( innerModifiedTag ) { // If it continues within the modified range
244+ newContent = newContent + MODIFIED_START_TAG
245+ }
246+
240247 while ( oldContent . length ) {
241248 if ( originalCode . startsWith ( MODIFIED_START_TAG ) ) { // Add modified start tag
242249 originalCode = originalCode . slice ( MODIFIED_START_TAG . length )
243250 newContent = newContent + MODIFIED_START_TAG
251+ innerModifiedTag = true // Start modified
244252 continue
245253 }
246254 if ( originalCode . startsWith ( MODIFIED_CLOSE_TAG ) ) { // Add modified close tag
247255 originalCode = originalCode . slice ( MODIFIED_CLOSE_TAG . length )
248256 newContent = newContent + MODIFIED_CLOSE_TAG
257+ innerModifiedTag = false // End modified
249258 continue
250259 }
251260
@@ -259,6 +268,10 @@ const setHighlightCode = ({ highlightCode, language, code }: { highlightCode: Re
259268 oldContent = oldContent . slice ( nextDiffsLength )
260269 }
261270
271+ if ( innerModifiedTag ) { // If the loop is finished without a modified close, it is still within the modified range.
272+ newContent = newContent + MODIFIED_CLOSE_TAG
273+ }
274+
262275 child . textContent = newContent // put as entity code because change textContent
263276 }
264277 } )
0 commit comments