diff --git a/src/calibre/ebooks/txt/input.py b/src/calibre/ebooks/txt/input.py index 86d5e23d10..f6900a5a2a 100644 --- a/src/calibre/ebooks/txt/input.py +++ b/src/calibre/ebooks/txt/input.py @@ -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')