mirror of
https://github.com/readest/readest.git
synced 2026-11-29 19:02:28 +00:00
fix(tts): skip bare superscript note markers when reading aloud (#6791)
Read Aloud already skipped a note marker inside a link (<a>17</a>), but an unlinked one such as <sup>17</sup> was spoken mid-sentence. A superscript holding only a marker (digits, [n], (n), *, †, ‡, §) is now skipped the same way; one with letters, like 1<sup>st</sup>, is still read. The live reader and the timeline enumeration share this filter, so both change together. Closes #6790. Reported by Oshibuki on GitHub. Verified: the two new marker tests fail without the change ("expected '他停下了脚步17,然后转身离开。' not to contain '17'") and pass with it; the 1<sup>st</sup> test passes both ways; tts.test.ts 51/51, the TTS and document test files (78) and pnpm lint pass. Not run: listening in the app with a real voice. A number-only superscript that is not a note (m<sup>2</sup>) is now skipped too. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2e88ccdea7
commit
9f0866f1a5
2 changed files with 38 additions and 1 deletions
|
|
@ -323,6 +323,38 @@ describe('TTS', () => {
|
|||
expect(combined).not.toContain('Transformed footnote');
|
||||
});
|
||||
|
||||
// #6790: an unlinked note marker such as <sup>17</sup> interrupts the
|
||||
// sentence it sits in, like the linked markers the <a> rule skips.
|
||||
it('should not read a bare superscript note marker', () => {
|
||||
const doc = createHTMLDoc('<p>他停下了脚步<sup>17</sup>,然后转身离开。</p>');
|
||||
const tts = new TTS(doc, textWalker, ttsNodeFilter, highlight, 'word');
|
||||
const combined = collectBlocks(tts).join(' ');
|
||||
|
||||
expect(combined).toContain('他停下了脚步');
|
||||
expect(combined).toContain('然后转身离开');
|
||||
expect(combined).not.toContain('17');
|
||||
});
|
||||
|
||||
it('should not read bracketed or starred superscript note markers', () => {
|
||||
for (const marker of ['[3]', '(12)', '*', '†']) {
|
||||
const doc = createHTMLDoc(`<p>Before the mark<sup>${marker}</sup> and after it.</p>`);
|
||||
const tts = new TTS(doc, textWalker, ttsNodeFilter, highlight, 'word');
|
||||
const combined = collectBlocks(tts).join(' ');
|
||||
|
||||
expect(combined).toContain('Before the mark');
|
||||
expect(combined).toContain('and after it');
|
||||
expect(combined).not.toContain(marker);
|
||||
}
|
||||
});
|
||||
|
||||
it('should still read superscripts that carry words', () => {
|
||||
const doc = createHTMLDoc('<p>It was the 1<sup>st</sup> of May.</p>');
|
||||
const tts = new TTS(doc, textWalker, ttsNodeFilter, highlight, 'word');
|
||||
const combined = collectBlocks(tts).join(' ');
|
||||
|
||||
expect(combined).toContain('st');
|
||||
});
|
||||
|
||||
it('should not read duokan footnote content', () => {
|
||||
const doc = createHTMLDoc(
|
||||
'<p>Real text.</p>' + '<div class="duokan-footnote-content"><p>Duokan footnote.</p></div>',
|
||||
|
|
|
|||
|
|
@ -23,7 +23,12 @@ export const createTTSNodeFilter = () => {
|
|||
tokens: ['footnote', 'endnote', 'note', 'rearnote'],
|
||||
},
|
||||
],
|
||||
contents: [{ tag: 'a', content: /^[\[\(]?[\*\d]+[\)\]]?$/ }],
|
||||
// Note markers: a linked one, or a bare superscript such as <sup>17</sup>
|
||||
// (#6790). A superscript with letters (1<sup>st</sup>) is still read.
|
||||
contents: [
|
||||
{ tag: 'a', content: /^[\[\(]?[\*\d]+[\)\]]?$/ },
|
||||
{ tag: 'sup', content: /^\s*[\[\(]?[\*\d†‡§]+[\)\]]?\s*$/ },
|
||||
],
|
||||
});
|
||||
// Ruby is decided per base-run/reading pair rather than by tag name: a kana
|
||||
// <rt> is spoken in place of the kanji it annotates, anything else keeps the
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue