@@ -74,7 +74,7 @@ export async function translateNodesBilingualMode(
7474 }
7575 }
7676
77- const textContent = transNodes . map ( node => extractTextContent ( node , config ) ) . join ( ' ' ) . trim ( )
77+ const textContent = transNodes . map ( node => extractTextContent ( node , config ) ) . join ( '' ) . trim ( )
7878 if ( ! textContent || isNumericContent ( textContent ) )
7979 return
8080
@@ -213,7 +213,7 @@ export async function translateNodeTranslationOnlyMode(
213213 }
214214 }
215215
216- const innerTextContent = transNodes . map ( node => extractTextContent ( node , config ) ) . join ( ' ' )
216+ const innerTextContent = transNodes . map ( node => extractTextContent ( node , config ) ) . join ( '' )
217217 if ( ! innerTextContent . trim ( ) || isNumericContent ( innerTextContent ) )
218218 return
219219
@@ -223,7 +223,11 @@ export async function translateNodeTranslationOnlyMode(
223223
224224 let cleanedContent = content . replace ( MARK_ATTRIBUTES_REGEX , '' )
225225 cleanedContent = cleanedContent . replace ( / < ! - - [ \s \S ] * ?- - > / g, ' ' )
226- cleanedContent = cleanedContent . replace ( / \s + / g, ' ' ) . trim ( )
226+ // Preserve newlines, only collapse horizontal whitespace (spaces/tabs)
227+ cleanedContent = cleanedContent . replace ( / [ ^ \S \n ] + / g, ' ' )
228+ // Trim spaces at start/end of each line, but preserve newlines
229+ cleanedContent = cleanedContent . split ( '\n' ) . map ( line => line . trim ( ) ) . join ( '\n' )
230+ cleanedContent = cleanedContent . trim ( )
227231
228232 return cleanedContent
229233 }
@@ -276,7 +280,8 @@ export async function translateNodeTranslationOnlyMode(
276280 return
277281 }
278282
279- translatedWrapperNode . innerHTML = translatedText
283+ // Convert newlines to <br> for proper rendering in innerHTML
284+ translatedWrapperNode . innerHTML = translatedText . replace ( / \n / g, '<br>' )
280285
281286 // Batch final DOM mutations to reduce layout thrashing
282287 batchDOMOperation ( ( ) => {
0 commit comments