fix(tts): set document lang attribute when missing or invalid for TTS, closes #3291 (#3393)

This commit is contained in:
Huang Xin
2026-02-27 00:17:51 +08:00
committed by GitHub
parent 6cb4278b98
commit fe3ab011ca
@@ -9,6 +9,7 @@ import { NativeTTSClient } from './NativeTTSClient';
import { EdgeTTSClient } from './EdgeTTSClient';
import { TTSUtils } from './TTSUtils';
import { TTSClient } from './TTSClient';
import { isValidLang } from '@/utils/lang';
type TTSState =
| 'stopped'
@@ -155,6 +156,12 @@ export class TTSController extends EventTarget {
doc = currentSection.doc;
} else {
doc = await section.createDocument();
const html = doc.querySelector('html');
const lang = html?.getAttribute('lang') || html?.getAttribute('xml:lang') || '';
if (html && !isValidLang(lang) && this.ttsLang) {
html.setAttribute('lang', this.ttsLang);
html.setAttribute('xml:lang', this.ttsLang);
}
}
if (this.view.tts && this.view.tts.doc === doc) {