Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/app-expo/assets/reader/reader.html
Original file line number Diff line number Diff line change
Expand Up @@ -3369,6 +3369,9 @@
'rp',
'sup',
'.readany-translation',
'.foliate-note-tooltip',
'#foliate-note-shared-tooltip',
'[data-readany-tts-skip]',
'[role="doc-noteref"]',
'[role="doc-footnote"]',
'[epub\\:type~="noteref"]',
Expand Down
3 changes: 3 additions & 0 deletions packages/app-expo/assets/reader/reader.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -3369,6 +3369,9 @@
'rp',
'sup',
'.readany-translation',
'.foliate-note-tooltip',
'#foliate-note-shared-tooltip',
'[data-readany-tts-skip]',
'[role="doc-noteref"]',
'[role="doc-footnote"]',
'[epub\\:type~="noteref"]',
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/components/reader/FoliateViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3417,6 +3417,7 @@ function ensureNoteTooltipSystem(doc: Document) {
const tooltip = doc.createElement("div");
tooltip.className = "foliate-note-tooltip";
tooltip.id = "foliate-note-shared-tooltip";
tooltip.setAttribute("data-readany-tts-skip", "true");
const content = doc.createElement("div");
content.className = "note-content";
tooltip.appendChild(content);
Expand Down
13 changes: 12 additions & 1 deletion packages/core/src/tts/text-utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { cleanText, isTTSFootnoteMarker } from "./text-utils";
import { cleanText, isTTSFootnoteMarker, shouldSkipTTSNode } from "./text-utils";

describe("TTS text utils", () => {
it("removes numeric footnote markers from narration text", () => {
Expand All @@ -20,4 +20,15 @@ describe("TTS text utils", () => {
expect(isTTSFootnoteMarker("(四)")).toBe(true);
expect(isTTSFootnoteMarker("正文[十二]")).toBe(false);
});

it("skips ReadAny note tooltip text", () => {
const tooltipChild = {
closest: (selector: string) =>
selector.includes(".foliate-note-tooltip") && selector.includes("[data-readany-tts-skip]")
? {}
: null,
} as unknown as Element;

expect(shouldSkipTTSNode(tooltipChild)).toBe(true);
});
});
12 changes: 6 additions & 6 deletions packages/core/src/tts/text-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const TTS_SKIPPED_ELEMENT_SELECTOR = [
"rp",
"sup",
".readany-translation",
".foliate-note-tooltip",
"#foliate-note-shared-tooltip",
"[data-readany-tts-skip]",
'[role="doc-noteref"]',
'[role="doc-footnote"]',
'[epub\\:type~="noteref"]',
Expand All @@ -25,8 +28,8 @@ const TTS_SKIPPED_ELEMENT_SELECTOR = [
'a[href^="#footnote"]',
'a[href*="footnote"]',
'a[href*="note"]',
'a.noteref',
'a.footnote',
"a.noteref",
"a.footnote",
".noteref",
".footnote",
".footnote-ref",
Expand All @@ -48,10 +51,7 @@ export function shouldSkipTTSNode(element: Element | null | undefined): boolean

/** Clean text for TTS: remove footnote references and extra whitespace. */
export function cleanText(text: string): string {
return text
.replace(FOOTNOTE_MARKER_PATTERN, "")
.replace(/\s+/g, " ")
.trim();
return text.replace(FOOTNOTE_MARKER_PATTERN, "").replace(/\s+/g, " ").trim();
}

/** Count characters (CJK = 2 units, others = 1) */
Expand Down