TXT Input: Fix regression that broke inclusion of images. Fixes #3067 (OS X - Problem including image in .mobi output)

This commit is contained in:
Kovid Goyal 2009-08-06 16:19:05 -06:00
parent fc228bd5b5
commit c6f13474c6
3 changed files with 27 additions and 4 deletions

View File

@ -189,8 +189,8 @@ class EPUBOutput(OutputFormatPlugin):
Create a generic cover for books that dont have a cover
'''
try:
from calibre.gui2 import images_rc # Needed for access to logo
from PyQt4.Qt import QApplication, QFile, QIODevice
from calibre.gui2 import images_rc, is_ok_to_use_qt # Needed for access to logo
from PyQt4.Qt import QFile, QIODevice
except:
return None
from calibre.ebooks.metadata import authors_to_string
@ -199,7 +199,7 @@ class EPUBOutput(OutputFormatPlugin):
title = unicode(m.title[0])
a = [unicode(x) for x in m.creator if x.role == 'aut']
author = authors_to_string(a)
if QApplication.instance() is None: QApplication([])
if not is_ok_to_use_qt(): return
f = QFile(':/library')
f.open(QIODevice.ReadOnly)
img_data = str(f.readAll())

View File

@ -31,12 +31,35 @@ class TXTInput(InputFormatPlugin):
raise ValueError('This txt file has malformed markup, it cannot be'
'converted by calibre. See http://daringfireball.net/projects/markdown/syntax')
from calibre.customize.ui import plugin_for_input_format
html_input = plugin_for_input_format('html')
for opt in html_input.options:
setattr(options, opt.option.name, opt.recommended_value)
base = os.getcwdu()
if hasattr(stream, 'name'):
base = os.path.dirname(stream.name)
htmlfile = open(os.path.join(base, 'temp_calibre_txt_input_to_html.html'),
'wb')
htmlfile.write(html.encode('utf-8'))
htmlfile.close()
cwd = os.getcwdu()
odi = options.debug_input
options.debug_input = None
oeb = html_input(open(htmlfile.name, 'rb'), options, 'html', log,
{}, cwd)
options.debug_input = odi
os.remove(htmlfile.name)
return oeb
log.debug('Writing html output...')
with open('index.html', 'wb') as index:
index.write(html.encode('utf-8'))
from calibre.ebooks.metadata.meta import get_metadata
log.debug('Retrieving source document metadata...')
stream.seek(0)
mi = get_metadata(stream, 'txt')
manifest = [('index.html', None)]
spine = ['index.html']

View File

@ -17,7 +17,7 @@ def txt_to_markdown(txt, title=''):
md = markdown.Markdown(
extensions=['footnotes', 'tables', 'toc'],
safe_mode=False,)
html = u'<html><head><title>%s</title></head><body>%s</body></html>' % (title,
html = u'<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>%s</title></head><body>%s</body></html>' % (title,
md.convert(txt))
return html