mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
missing file added
This commit is contained in:
parent
5451c38d5d
commit
c12aee04c2
42
src/calibre/ebooks/html/output.py
Normal file
42
src/calibre/ebooks/html/output.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
from __future__ import with_statement
|
||||||
|
__license__ = 'GPL 3'
|
||||||
|
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
|
import os, re
|
||||||
|
|
||||||
|
from lxml import etree
|
||||||
|
|
||||||
|
from calibre.customize.conversion import OutputFormatPlugin
|
||||||
|
from calibre import CurrentDir
|
||||||
|
from calibre.customize.conversion import OptionRecommendation
|
||||||
|
|
||||||
|
from urllib import unquote
|
||||||
|
|
||||||
|
class HTMLOutput(OutputFormatPlugin):
|
||||||
|
|
||||||
|
name = 'HTML Output'
|
||||||
|
author = 'Fabian Grassl'
|
||||||
|
file_type = 'html'
|
||||||
|
|
||||||
|
recommendations = set([('pretty_print', True, OptionRecommendation.HIGH)])
|
||||||
|
|
||||||
|
def convert(self, oeb_book, output_path, input_plugin, opts, log):
|
||||||
|
self.log = log
|
||||||
|
self.opts = opts
|
||||||
|
if not os.path.exists(output_path):
|
||||||
|
os.makedirs(output_path)
|
||||||
|
with CurrentDir(output_path):
|
||||||
|
with open('index.html', 'wb') as f:
|
||||||
|
root = oeb_book.html_toc()
|
||||||
|
html_txt = etree.tostring(root, pretty_print=True, encoding='utf-8', xml_declaration=False)
|
||||||
|
f.write(html_txt)
|
||||||
|
for item in oeb_book.manifest:
|
||||||
|
log('write: %s '%item.href)
|
||||||
|
path = os.path.abspath(unquote(item.href))
|
||||||
|
dir = os.path.dirname(path)
|
||||||
|
if not os.path.exists(dir):
|
||||||
|
os.makedirs(dir)
|
||||||
|
with open(path, 'wb') as f:
|
||||||
|
f.write(str(item))
|
||||||
|
item.unload_data_from_memory(memory=path)
|
Loading…
x
Reference in New Issue
Block a user