mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Conversion: When converting TXT set <title> in HTML
TXT Input: Ensure that <title> in the generated HTML has a meaningful value. Fixes #1236923 [txt → epub When I don't give a title, the <title> tag is set to unknown. It should default to the chapter name and chapter ID for each fragment. Or use the name of the converted file](https://bugs.launchpad.net/calibre/+bug/1236923)
This commit is contained in:
parent
b9bfb53fa2
commit
39701cdaa8
@ -236,5 +236,14 @@ class TXTInput(InputFormatPlugin):
|
||||
from calibre.ebooks.oeb.transforms.metadata import meta_info_to_oeb_metadata
|
||||
mi = get_file_type_metadata(stream, file_ext)
|
||||
meta_info_to_oeb_metadata(mi, oeb.metadata, log)
|
||||
self.html_postprocess_title = mi.title
|
||||
|
||||
return oeb
|
||||
|
||||
def postprocess_book(self, oeb, opts, log):
|
||||
for item in oeb.spine:
|
||||
if hasattr(item.data, 'xpath'):
|
||||
for title in item.data.xpath('//*[local-name()="title"]'):
|
||||
if title.text == _('Unknown'):
|
||||
title.text = self.html_postprocess_title
|
||||
|
||||
|
@ -7,7 +7,7 @@ __copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
||||
Read meta information from TXT files
|
||||
'''
|
||||
|
||||
import re
|
||||
import re, os
|
||||
|
||||
from calibre.ebooks.metadata import MetaInformation
|
||||
|
||||
@ -15,7 +15,10 @@ def get_metadata(stream, extract_cover=True):
|
||||
'''
|
||||
Return metadata as a L{MetaInfo} object
|
||||
'''
|
||||
mi = MetaInformation(_('Unknown'), [_('Unknown')])
|
||||
name = getattr(stream, 'name', '').rpartition('.')[0]
|
||||
if name:
|
||||
name = os.path.basename(name)
|
||||
mi = MetaInformation(name or _('Unknown'), [_('Unknown')])
|
||||
stream.seek(0)
|
||||
|
||||
mdata = u''
|
||||
@ -29,7 +32,7 @@ def get_metadata(stream, extract_cover=True):
|
||||
mdata = mdata[:100]
|
||||
|
||||
mo = re.search('(?u)^[ ]*(?P<title>.+)[ ]*(\n{3}|(\r\n){3}|\r{3})[ ]*(?P<author>.+)[ ]*(\n|\r\n|\r)$', mdata)
|
||||
if mo != None:
|
||||
if mo is not None:
|
||||
mi.title = mo.group('title')
|
||||
mi.authors = mo.group('author').split(',')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user