moonlaney
moonlaney

Reputation: 11

How do insert a HTML file in the content of a chapter when using ebooklib?

I'm making an EPUB using the EbookLib library and I'm following along their documentation. I am trying to set the content of a chapter to be the content of a HTML file. The only way I got it to work was giving plain HTML when setting the content.

c1 = epub.EpubHtml(title='Chapter one', file_name='ch1.xhtml', lang='en')

c1.set_content(u'<html><body><h1>Introduction</h1><p>Introduction paragraph.</p></body></html>')'

Is it possible to give a HTML file to be the content of the chapter?

I've tried things like c1.set_content(file_name='ch1.xhtml') but that didn't work, it only accepts plain HTML.

Upvotes: 0

Views: 156

Answers (1)

moonlaney
moonlaney

Reputation: 11

I figured it out! I'm opening and reading the file in a variable and then passing that variable to the set_content function. Posting this so it could be of use to someone in the future.

file = open('ch1.xhtml', 'r')
lines = file.read()
c2.set_content(lines)
file.close()

Upvotes: 1

Related Questions