英文:
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.
英文:
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.
答案1
得分: 1
我明白了!我打开并读取文件存储在一个变量中,然后将该变量传递给set_content
函数。发布这个以便将来有人可以使用。
file = open('ch1.xhtml', 'r')
lines = file.read()
c2.set_content(lines)
file.close()
英文:
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()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论