Skip to content

Injecting custom CSS files in each WebView #72

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

You must be logged in to vote

We plan to work soonish on an Injectable API to inject custom JavaScript and CSS but there's nothing available yet.

However, you can implement a custom transformer for the HTML resources to use with the TransformingFetcher and inject the CSS yourself.

You can wrap the publication fetcher from the Streamer.open(onCreatePublication:) closure:

func injectCSS(_ resource: Resource) -> Resource {
    ...
}

streamer.open(
    ...,
    onCreatePublication: { _, _, fetcher, _ in
        fetcher = TransformingFetcher(fetcher: fetcher, transformers: [injectCSS]),
    }
)

Take a look at the EPUBHTMLInjector for an example:

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@838
Comment options

@mickael-menu
Comment options

@838
Comment options

Answer selected by 838
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