From e13ef02c61e576e67101a26222d8cad618d0f840 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 7 Nov 2010 11:28:06 -0700 Subject: [PATCH 1/2] Conversion pipeline: When using the Level x Table of Contents expressions, if a tag is empty but has a non-empty title attribute, use that instead of ignoring the tag --- .../ebooks/oeb/transforms/structure.py | 6 +++++- src/calibre/manual/conversion.rst | 21 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/oeb/transforms/structure.py b/src/calibre/ebooks/oeb/transforms/structure.py index 07235b4fb0..0db9b153df 100644 --- a/src/calibre/ebooks/oeb/transforms/structure.py +++ b/src/calibre/ebooks/oeb/transforms/structure.py @@ -133,7 +133,11 @@ class DetectStructure(object): def elem_to_link(self, item, elem, counter): - text = xml2text(elem) + text = xml2text(elem).strip() + if not text: + text = elem.get('title', '') + if not text: + text = elem.get('alt', '') text = text[:100].strip() id = elem.get('id', 'calibre_toc_%d'%counter) elem.set('id', id) diff --git a/src/calibre/manual/conversion.rst b/src/calibre/manual/conversion.rst index cfc2871396..fea20a3163 100644 --- a/src/calibre/manual/conversion.rst +++ b/src/calibre/manual/conversion.rst @@ -377,7 +377,7 @@ They are XPath expressions that match tags in the intermediate XHTML produced by how to construct XPath expressions. Next to each option is a button that launches a wizard to help with the creation of basic XPath expressions. The following simple example illustrates how to use these options. -Suppose you have an input document taht results in XHTML that look like this: +Suppose you have an input document that results in XHTML that look like this: .. code-block:: html @@ -418,6 +418,25 @@ This will result in an automatically generated two level Table of Contents that Not all output formats support a multi level Table of Contents. You should first try with EPUB Output. If that works, then try your format of choice. +Using images as chapter titles when converting HTML input documents +--------------------------------------------------------------------- + +Suppose you want to use an image as your chapter title, but still want |app| to be able to automatically generate a Table of Contents for you from the chapter titles. +Use the following HTML markup to achieve this + +.. code-block:: html + + + +

Chapter 1

+

chapter 1 text...

+

+

chapter 2 text...

+ + + +Set the :guilabel:`Level 1 TOC` setting to ``//h:h2``. Then, for chapter two, |app| will take the title from the value of the ``title`` attribute on the ``

`` tag, since the tag has no text. + How options are set/saved for Conversion ------------------------------------------- From 06004fca5699403af54e96331a0c58a60a3d4c61 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 7 Nov 2010 11:54:25 -0700 Subject: [PATCH 2/2] E-book viewer: Fix clicking entries in TOC that point to the currently loaded document not scrolling view to the top of the document --- src/calibre/gui2/viewer/main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/viewer/main.py b/src/calibre/gui2/viewer/main.py index 4a098785b1..81a372a3ca 100644 --- a/src/calibre/gui2/viewer/main.py +++ b/src/calibre/gui2/viewer/main.py @@ -472,8 +472,12 @@ class EbookViewer(MainWindow, Ui_EbookViewer): if path != self.current_page: self.pending_anchor = frag self.load_path(path) - elif frag: - self.view.scroll_to(frag) + else: + if frag: + self.view.scroll_to(frag) + else: + # Scroll to top + self.view.scroll_to('#') else: open_url(url)