diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 932261c45d..ab6d772121 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -265,12 +265,13 @@ class MOBIMetadataWriter(MetadataWriterPlugin): from calibre.ebooks.epub.input import EPUBInput from calibre.ebooks.mobi.input import MOBIInput +from calibre.ebooks.txt.input import TXTInput from calibre.ebooks.oeb.output import OEBOutput from calibre.ebooks.txt.output import TXTOutput from calibre.ebooks.pdf.output import PDFOutput from calibre.customize.profiles import input_profiles, output_profiles -plugins = [HTML2ZIP, EPUBInput, MOBIInput, OEBOutput, TXTOutput, PDFOutput] +plugins = [HTML2ZIP, EPUBInput, MOBIInput, TXTInput, OEBOutput, TXTOutput, PDFOutput] plugins += [x for x in list(locals().values()) if isinstance(x, type) and \ x.__name__.endswith('MetadataReader')] plugins += [x for x in list(locals().values()) if isinstance(x, type) and \ diff --git a/src/calibre/ebooks/txt/input.py b/src/calibre/ebooks/txt/input.py new file mode 100644 index 0000000000..a42c72866f --- /dev/null +++ b/src/calibre/ebooks/txt/input.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +from __future__ import with_statement + +__license__ = 'GPL 3' +__copyright__ = '2009, John Schember ' +__docformat__ = 'restructuredtext en' + +import os + +from calibre.customize.conversion import InputFormatPlugin +from calibre.ebooks.markdown import markdown +from calibre.ebooks.metadata.opf import OPFCreator +from calibre.ebooks.metadata import MetaInformation +#from calibre.ebooks.metadata.meta import metadata_from_formats + +class TXTInput(InputFormatPlugin): + + name = 'TXT Input' + author = 'John Schember' + description = 'Convert TXT files to HTML' + file_types = set(['txt']) + + def convert(self, stream, options, file_ext, log, + accelerators): + txt = stream.read() + + md = markdown.Markdown( + extensions=['footnotes', 'tables', 'toc'], + safe_mode=False,) + html = ''+md.convert(txt)+'' + with open('index.html', 'wb') as index: + index.write(html.encode('utf-8')) + + #mi = metadata_from_formats([stream.name]) + mi = MetaInformation(_('Unknown'), _('Unknown')) + opf = OPFCreator(os.getcwd(), mi) + opf.create_manifest([('index.html', None)]) + opf.create_spine(['index.html']) + with open('metadata.opf', 'wb') as opffile: + opf.render(opffile) + + return os.path.join(os.getcwd(), 'metadata.opf')