mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
A more sensible error when markdown fails
This commit is contained in:
parent
e3fabe843a
commit
3fecb610dc
@ -10,7 +10,7 @@ from calibre.customize.conversion import InputFormatPlugin
|
||||
from calibre.ebooks.txt.processor import txt_to_markdown, opf_writer
|
||||
|
||||
class TXTInput(InputFormatPlugin):
|
||||
|
||||
|
||||
name = 'TXT Input'
|
||||
author = 'John Schember'
|
||||
description = 'Convert TXT files to HTML'
|
||||
@ -22,16 +22,20 @@ class TXTInput(InputFormatPlugin):
|
||||
if options.input_encoding:
|
||||
ienc = options.input_encoding
|
||||
txt = stream.read().decode(ienc)
|
||||
|
||||
html = txt_to_markdown(txt)
|
||||
|
||||
try:
|
||||
html = txt_to_markdown(txt)
|
||||
except RuntimeError:
|
||||
raise ValueError('This txt file has malformed markup, it cannot be'
|
||||
'converted by calibre. See http://daringfireball.net/projects/markdown/syntax')
|
||||
with open('index.html', 'wb') as index:
|
||||
index.write(html.encode('utf-8'))
|
||||
|
||||
|
||||
from calibre.ebooks.metadata.meta import get_metadata
|
||||
mi = get_metadata(stream, 'txt')
|
||||
manifest = [('index.html', None)]
|
||||
spine = ['index.html']
|
||||
opf_writer(os.getcwd(), 'metadata.opf', manifest, spine, mi)
|
||||
|
||||
|
||||
return os.path.join(os.getcwd(), 'metadata.opf')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user