mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Text input plugin
This commit is contained in:
parent
118fd6ece0
commit
fca3f98e6a
@ -265,12 +265,13 @@ class MOBIMetadataWriter(MetadataWriterPlugin):
|
|||||||
|
|
||||||
from calibre.ebooks.epub.input import EPUBInput
|
from calibre.ebooks.epub.input import EPUBInput
|
||||||
from calibre.ebooks.mobi.input import MOBIInput
|
from calibre.ebooks.mobi.input import MOBIInput
|
||||||
|
from calibre.ebooks.txt.input import TXTInput
|
||||||
from calibre.ebooks.oeb.output import OEBOutput
|
from calibre.ebooks.oeb.output import OEBOutput
|
||||||
from calibre.ebooks.txt.output import TXTOutput
|
from calibre.ebooks.txt.output import TXTOutput
|
||||||
from calibre.ebooks.pdf.output import PDFOutput
|
from calibre.ebooks.pdf.output import PDFOutput
|
||||||
from calibre.customize.profiles import input_profiles, output_profiles
|
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 \
|
plugins += [x for x in list(locals().values()) if isinstance(x, type) and \
|
||||||
x.__name__.endswith('MetadataReader')]
|
x.__name__.endswith('MetadataReader')]
|
||||||
plugins += [x for x in list(locals().values()) if isinstance(x, type) and \
|
plugins += [x for x in list(locals().values()) if isinstance(x, type) and \
|
||||||
|
42
src/calibre/ebooks/txt/input.py
Normal file
42
src/calibre/ebooks/txt/input.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import with_statement
|
||||||
|
|
||||||
|
__license__ = 'GPL 3'
|
||||||
|
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
||||||
|
__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 = '<html><body>'+md.convert(txt)+'</body></html>'
|
||||||
|
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')
|
Loading…
x
Reference in New Issue
Block a user