diff --git a/src/core/engine.ts b/src/core/engine.ts index 305ff38..f5605d5 100644 --- a/src/core/engine.ts +++ b/src/core/engine.ts @@ -129,7 +129,7 @@ export class TranslationEngine { let translation: string; try { - if (cleanText.length > this.maxSentenceLength) { + if (cleanText.length > this.maxSentenceLength && !effectiveOptions.html) { translation = this._translateLongText(cleanText, effectiveOptions); } else { translation = this._translateInternal(cleanText, effectiveOptions); diff --git a/tests/engine-html.test.ts b/tests/engine-html.test.ts new file mode 100644 index 0000000..737790d --- /dev/null +++ b/tests/engine-html.test.ts @@ -0,0 +1,30 @@ +import { describe, expect, test } from 'bun:test'; +import { TranslationEngine } from '@/core/engine'; + +describe('TranslationEngine HTML handling', () => { + test('long html skips plain text splitting', () => { + const engine = new TranslationEngine() as any; + engine.isReady = true; + + let usedLongText = false; + let usedInternal = false; + + engine._translateLongText = () => { + usedLongText = true; + return 'split'; + }; + + engine._translateInternal = (text: string, options: { html?: boolean }) => { + usedInternal = true; + expect(options.html).toBe(true); + return text; + }; + + const html = `

${'Hello world '.repeat(80)}example

`; + const result = engine.translate(html, { html: true }); + + expect(result).toBe(html); + expect(usedInternal).toBe(true); + expect(usedLongText).toBe(false); + }); +});