Skip to content

Auto-highlighting specific words in paginated text #238

Answered by mickael-menu
eton1234 asked this question in Q&A
Discussion options

You must be logged in to vote

Pretty interesting use case!

You're in luck, we just merged something that will help with that. It's not yet released but available in develop. Take a look at the user guide for the Content iteration.

This will extract full paragraphs, but you can split them by words using a tokenizer. The default one handles splitting by words:

guard let content = publication.content() else {
    return
}

let wordTokenizer = makeTextContentTokenizer(
    defaultLanguage: publication.metadata.language,
    textTokenizerFactory: { language in
        makeDefaultTextTokenizer(unit: .word, language: language)
    }
)

let words: [TextContentElement.Segment] = try content
    .elements()
    .flatMap { try w…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
5 replies
@eton1234
Comment options

@mickael-menu
Comment options

@eton1234
Comment options

@mickael-menu
Comment options

@eton1234
Comment options

Answer selected by eton1234
Comment options

You must be logged in to vote
1 reply
@mickael-menu
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants