Skip to content

feat: support TTSNavigator and text search for WebPubs with HTML content #682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ package org.readium.r2.streamer.parser.readium

import android.content.Context
import org.readium.r2.shared.DelicateReadiumApi
import org.readium.r2.shared.ExperimentalReadiumApi
import org.readium.r2.shared.InternalReadiumApi
import org.readium.r2.shared.publication.Manifest
import org.readium.r2.shared.publication.Publication
import org.readium.r2.shared.publication.services.InMemoryCacheService
import org.readium.r2.shared.publication.services.PerResourcePositionsService
import org.readium.r2.shared.publication.services.WebPositionsService
import org.readium.r2.shared.publication.services.cacheServiceFactory
import org.readium.r2.shared.publication.services.content.DefaultContentService
import org.readium.r2.shared.publication.services.content.contentServiceFactory
import org.readium.r2.shared.publication.services.content.iterators.HtmlResourceContentIterator
import org.readium.r2.shared.publication.services.locatorServiceFactory
import org.readium.r2.shared.publication.services.positionsServiceFactory
import org.readium.r2.shared.publication.services.search.StringSearchService
import org.readium.r2.shared.publication.services.search.searchServiceFactory
import org.readium.r2.shared.util.AbsoluteUrl
import org.readium.r2.shared.util.DebugError
import org.readium.r2.shared.util.Try
Expand Down Expand Up @@ -52,6 +58,7 @@ import timber.log.Timber
* of positions in a reflowable resource of a web publication conforming to the
* EPUB profile.
*/
@OptIn(ExperimentalReadiumApi::class)
public class ReadiumWebPubParser(
private val context: Context? = null,
private val httpClient: HttpClient,
Expand Down Expand Up @@ -115,6 +122,16 @@ public class ReadiumWebPubParser(
else ->
null
}

// Add content- and search-service for WebPubs with HTML contents.
if (manifest.readingOrder.any { it.mediaType?.isHtml == true }) {
contentServiceFactory = DefaultContentService.createFactory(
resourceContentIteratorFactories = listOf(
HtmlResourceContentIterator.Factory()
)
)
searchServiceFactory = StringSearchService.createDefaultFactory()
}
}

val publicationBuilder = Publication.Builder(manifest, container, servicesBuilder)
Expand Down