View Single Post
Old 02-21-2017, 05:53 PM   #12
Tex2002ans
Wizard
Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.
 
Posts: 2,306
Karma: 13057279
Join Date: Jul 2012
Device: Kobo Forma, Nook
Quote:
Originally Posted by chaot View Post
Inhalt Start of Contents of one book of six. Alltogether more then thousand headings. That needs a sophisticated system.
Thousands of headings? What is this book, a collection of poems?

If your book has all the headings marked as <h3>, then you could use Sigil to help you.

Take your original code:

Spoiler:
Code:
<h2>Vorwort</h2>
<h3>Wo die Kartousch singt!</h3>
<p>Example Text Example Text.</p>
<h3>Golkonda</h3>
<p>Example Text Example Text.</p>
<h3>Der Regisseur</h3>
<p>Example Text Example Text.</p>
<h3>Film im Freistaat</h3>
<p>Example Text Example Text.</p>


If you run Sigil's Tools -> Table of Contents -> Generate Table of Contents. Now your HTML will get the BOLD parts added:

Spoiler:
Quote:
<h2>Vorwort</h2>

<h3 id="sigil_toc_id_1">Wo die Kartousch singt!</h3>

<p>Example Text Example Text.</p>

<h3 id="sigil_toc_id_2">Golkonda</h3>

<p>Example Text Example Text.</p>

<h3 id="sigil_toc_id_3">Der Regisseur</h3>

<p>Example Text Example Text.</p>

<h3 id="sigil_toc_id_4">Film im Freistaat</h3>

<p>Example Text Example Text.</p>


Then you use Sigil to just generate the HTML Table of Contents:

Spoiler:
Code:
  <div class="sgc-toc-level-1">
    <a href="../Text/Vorwort.xhtml">Vorwort</a> 

    <div class="sgc-toc-level-2">
      <a href="../Text/Vorwort.xhtml#sigil_toc_id_1">Wo die Kartousch singt!</a>
    </div>

    <div class="sgc-toc-level-2">
      <a href="../Text/Vorwort.xhtml#sigil_toc_id_2">Golkonda</a>
    </div>

    <div class="sgc-toc-level-2">
      <a href="../Text/Vorwort.xhtml#sigil_toc_id_3">Der Regisseur</a>
    </div>

    <div class="sgc-toc-level-2">
      <a href="../Text/Vorwort.xhtml#sigil_toc_id_4">Film im Freistaat</a>
    </div>


Now you can use Sigil's unique IDs as a basis to Regex (instead of your convoluted crazy "u3458976345" system).

Now, for some reason, you want to jump from your HTML headings BACK to the TOC... so you might want to do this:

Search: <a href="([^\#"]+#)([^"]+)">
Replace: <a id="\2" href="\1\2">

Spoiler:
Quote:
<div class="sgc-toc-level-1">
<a href="../Text/Vorwort.xhtml">Vorwort</a>

<div class="sgc-toc-level-2">
<a id="sigil_toc_id_1" href="../Text/Vorwort.xhtml#sigil_toc_id_1">Wo die Kartousch singt!</a>
</div>

<div class="sgc-toc-level-2">
<a id="sigil_toc_id_2" href="../Text/Vorwort.xhtml#sigil_toc_id_2">Golkonda</a>
</div>

<div class="sgc-toc-level-2">
<a id="sigil_toc_id_3" href="../Text/Vorwort.xhtml#sigil_toc_id_3">Der Regisseur</a>
</div>

<div class="sgc-toc-level-2">
<a id="sigil_toc_id_4" href="../Text/Vorwort.xhtml#sigil_toc_id_4">Film im Freistaat</a>
</div>


Then you go back to the text and do this:

Search: <h3 id="([^"]+)">(.+?)</h3>
Replace: <h3 id="\1"><a href="../Text/TOC.xhtml#\1">\2</a></h3>

This will allow your <h3>s to point right back to their spot in the TOC:

Spoiler:
Quote:
<h2>Vorwort</h2>

<h3 id="sigil_toc_id_1"><a href="../Text/TOC.xhtml#sigil_toc_id_1">Wo die Kartousch singt!</a></h3>

<p>Example Text Example Text.</p>

<h3 id="sigil_toc_id_2"><a href="../Text/TOC.xhtml#sigil_toc_id_2">Golkonda</a></h3>

<p>Example Text Example Text.</p>

<h3 id="sigil_toc_id_3"><a href="../Text/TOC.xhtml#sigil_toc_id_3">Der Regisseur</a></h3>

<p>Example Text Example Text.</p>

<h3 id="sigil_toc_id_4"><a href="../Text/TOC.xhtml#sigil_toc_id_4">Film im Freistaat</a></h3>

<p>Example Text Example Text.</p>


Quote:
Originally Posted by stumped View Post
What do the IDs actually do anyway. I have stripped all of them from some epub books with no apparent impact on readability. Everthing still seems to work ?
As others have stated, in your typical Fiction, it probably wouldn't have too many uses (although each book is unique, I wouldn't go ripping IDs out without seeing if they serve some purpose).

But take Non-Fiction for example, you might have something like this:

Quote:
<p class="equation" id="Equation1.1">E = mc<sup>2</sup></p>

[...]

<p>As Einstein said in <a href="../Text/Chap1.xhtml#Equation1.1">Equation 1.1</a>, energy is mass, and mass is energy.</p>
or let us say you had an annotated version. You might use the ID to point to a specific paragraph:

Quote:
<p id="ActIII.Scene1.p20"><b>Hamlet.</b> To be, or not to be―that is the question:</p>

[...]

<p>One of the most famous lines in all of literature <a href="../Text/ActIII.xhtml#ActIII.Scene1.p20">was spoken by Hamlet</a>.</p>
So let us say you ripped out all of the IDs out of Hamlet... on the surface everything looks A-OK... but if you pushed the link, it wouldn't lead you to the correct location (or the link might not work at all).

Last edited by Tex2002ans; 02-21-2017 at 06:11 PM.
Tex2002ans is offline   Reply With Quote