From ce5f89c2b4a26d8f13954291eee362ed2b133152 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 1 Dec 2009 18:43:31 +0000 Subject: [PATCH] LIT Input: Handle LIT files that are really TXT files, by simply splitting the text into pararaphs at blank lines. --- src/calibre/ebooks/lit/input.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/calibre/ebooks/lit/input.py b/src/calibre/ebooks/lit/input.py index 409482da29..8655d8b189 100644 --- a/src/calibre/ebooks/lit/input.py +++ b/src/calibre/ebooks/lit/input.py @@ -21,4 +21,26 @@ class LITInput(InputFormatPlugin): from calibre.ebooks.conversion.plumber import create_oebbook return create_oebbook(log, stream, options, self, reader=LitReader) + def postprocess_book(self, oeb, opts, log): + from calibre.ebooks.oeb.base import XHTML_NS, XPath, XHTML + for item in oeb.spine: + root = item.data + if not hasattr(root, 'xpath'): continue + body = XPath('//h:body')(root) + if body: + body = body[0] + if len(body) == 1 and body[0].tag == XHTML('pre'): + pre = body[0] + from calibre.ebooks.txt.processor import convert_basic + from lxml import etree + import copy + html = convert_basic(pre.text).replace('', + ''%XHTML_NS) + root = etree.fromstring(html) + body = XPath('//h:body')(root) + pre.tag = XHTML('div') + pre.text = '' + for elem in body: + ne = copy.deepcopy(elem) + pre.append(ne)