diff --git a/src/calibre/ebooks/mobi/debug.py b/src/calibre/ebooks/mobi/debug.py index 8034117f9b..47450842d1 100644 --- a/src/calibre/ebooks/mobi/debug.py +++ b/src/calibre/ebooks/mobi/debug.py @@ -1430,16 +1430,17 @@ class MOBIFile(object): # {{{ print (str(self.mobi_header).encode('utf-8'), file=f) # }}} -def inspect_mobi(path_or_stream, prefix='decompiled'): # {{{ +def inspect_mobi(path_or_stream, ddir=None): # {{{ stream = (path_or_stream if hasattr(path_or_stream, 'read') else open(path_or_stream, 'rb')) f = MOBIFile(stream) - ddir = prefix + '_' + os.path.splitext(os.path.basename(stream.name))[0] + if ddir is None: + ddir = 'decompiled_' + os.path.splitext(os.path.basename(stream.name))[0] try: shutil.rmtree(ddir) except: pass - os.mkdir(ddir) + os.makedirs(ddir) with open(os.path.join(ddir, 'header.txt'), 'wb') as out: f.print_header(f=out) diff --git a/src/calibre/ebooks/mobi/mobiml.py b/src/calibre/ebooks/mobi/mobiml.py index d108742f3c..eefa9d9e03 100644 --- a/src/calibre/ebooks/mobi/mobiml.py +++ b/src/calibre/ebooks/mobi/mobiml.py @@ -532,7 +532,7 @@ class MobiMLizer(object): bstate.pbreak = True if isblock: para = bstate.para - if para is not None and para.text == u'\xa0': + if para is not None and para.text == u'\xa0' and len(para) < 1: para.getparent().replace(para, etree.Element(XHTML('br'))) bstate.para = None bstate.istate = None diff --git a/src/calibre/ebooks/mobi/output.py b/src/calibre/ebooks/mobi/output.py index aeab8518a9..4451bc66b8 100644 --- a/src/calibre/ebooks/mobi/output.py +++ b/src/calibre/ebooks/mobi/output.py @@ -50,6 +50,11 @@ class MOBIOutput(OutputFormatPlugin): help=_('When adding the Table of Contents to the book, add it at the start of the ' 'book instead of the end. Not recommended.') ), + OptionRecommendation(name='extract_to', recommended_value=None, + help=_('Extract the contents of the MOBI file to the' + ' specified directory. If the directory already ' + 'exists, it will be deleted.') + ), OptionRecommendation(name='mobi_navpoints_only_deepest', recommended_value=False, help=_('When adding navpoints for the chapter-to-chapter' @@ -185,3 +190,8 @@ class MOBIOutput(OutputFormatPlugin): write_page_breaks_after_item=write_page_breaks_after_item) writer(oeb, output_path) + if opts.extract_to is not None: + from calibre.ebooks.mobi.debug import inspect_mobi + ddir = opts.extract_to + inspect_mobi(output_path, ddir=ddir) + diff --git a/src/calibre/manual/template_ref_generate.py b/src/calibre/manual/template_ref_generate.py index f4c1ead165..ab9995dc16 100644 --- a/src/calibre/manual/template_ref_generate.py +++ b/src/calibre/manual/template_ref_generate.py @@ -67,11 +67,15 @@ def generate_template_language_help(): for func in all_builtin_functions: class_name = func.__class__.__name__ + if class_name == 'BuiltinMergeLists': + class_name = 'BuiltinListUnion' func_sig = getattr(func, 'doc') x = func_sig.find(' -- ') if x < 0: print 'No sig for ', class_name continue + if func_sig.startswith('merge_lists('): + continue func_sig = func_sig[:x] func_cat = getattr(func, 'category') funcs[func_cat][func_sig] = class_name