Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old 05-08-2014, 12:26 PM   #1
1v4n0
Groupie
1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.
 
Posts: 171
Karma: 40000
Join Date: Oct 2013
Device: kindle
Sort TOC alphabetically

Hello.

Anyone knows a way to sort alphabetically the links in the table of contents of an EPUB?

If I C/P the code in excel it sorts them reading the code, but I want it to follow the order of the words which appear in the book (i.e. the ones outside the tags)

Thanks
1v4n0 is offline   Reply With Quote
Old 05-08-2014, 03:58 PM   #2
odedta
Addict
odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.
 
Posts: 398
Karma: 96448
Join Date: Dec 2013
Device: iPad
Lol, while I was writing a wrong answer for your reply I came up with a simple idea that might work well for you, there is a plugin for HTML called table sorter I used quite a few times.

Table sorter: http://tablesorter.com/docs/

It's not the most elegant solution I bet but it should work like a charm, you basically create a table of two columns, 1 would be the name of the link and one the url (href), then hit the sort button and copy paste the output source.

If nobody has a better idea and you like doing this more than one time I will take the challenge to write something more convenient to use this on a more regular basis.

EDIT: There is also list sorter: http://listjs.com/ which would be more compatible with what you're trying to accomplish since TOCs are basically lists.

EDIT2: If you still want to use excel you can do pretty much what I offered but manually, copy paste your TOC (FROM VIEW MODE - NO CODE) to Excel, sort and then match the right links, TOCs are not THAT long so it shouldn't take more than a couple of minutes anyway. Then again, if you do this often a better solution would be nice to find

Last edited by odedta; 05-08-2014 at 04:02 PM.
odedta is offline   Reply With Quote
Old 05-09-2014, 04:56 AM   #3
1v4n0
Groupie
1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.
 
Posts: 171
Karma: 40000
Join Date: Oct 2013
Device: kindle
Hello, thanks for your answers.

The first 2 solutions imply the use of javascript, but how do you use that while working offline? I'm a bit confused on what to do. Besides, what I have is not a table, but a list of links.

The solution w/ excel seems to work, except that when you c/p the text from excel into sigil the link references get lost, and you get sthg like

Code:
<a href="">link text</a>
In the meantime I might have found another workaround, but it is a bit complicated. I can turn the code into a two column table (search and replace in notepad, save and open the file w/ excel), in which the first column is the link attribute and the second the name. Then w/ excel I sort the latter, and finally I turn it the other way around back to a link list.

It might work.
1v4n0 is offline   Reply With Quote
Old 05-09-2014, 05:16 AM   #4
odedta
Addict
odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.
 
Posts: 398
Karma: 96448
Join Date: Dec 2013
Device: iPad
I told you that if you do this in excel you will have to c/p the links or the names (one of them) manually so it works well if you do this once or twice for TOCs, but if you want to do this a lot a more permanent solution needs to be found.

Javascript is a client-side scripting language, meaning, you can run it on your PC, I provided a link to a file called List.js which basically sorts a list in Alphabetical order and should retain the links for you.
I can see you don't have much experience in these matters so i'll create a simple template for you to use unless someone else comes up with a better idea.

There is a bit simpler method if you use Calibre, basically do the Excel sort you did last time, now open up Calibre then Edit Book, then edit toc and just use the arrows to sort your TOC according to the result in your Excel spreadsheet.

Last edited by odedta; 05-09-2014 at 05:32 AM.
odedta is offline   Reply With Quote
Old 05-09-2014, 05:23 AM   #5
1v4n0
Groupie
1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.
 
Posts: 171
Karma: 40000
Join Date: Oct 2013
Device: kindle
Aha yeah, I get now what you mean w/ excel. In this case though the TOC is actually very long, so I can't do it manually.

Anyway it's true I don't have much experience w/ JS, but I'm willing to learn

I will try list.js

TY once again.
1v4n0 is offline   Reply With Quote
Old 05-09-2014, 05:33 AM   #6
odedta
Addict
odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.
 
Posts: 398
Karma: 96448
Join Date: Dec 2013
Device: iPad
Alright, let me know how it goes and if you need any help with setting it up.
odedta is offline   Reply With Quote
Old 05-09-2014, 05:38 AM   #7
1v4n0
Groupie
1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.
 
Posts: 171
Karma: 40000
Join Date: Oct 2013
Device: kindle
Yeah. So basically I open the TOC pace w/ sigil or another editor, and c/p the code they provide me here, linking the JS and so on, then I open the file w/ a browser and is should display the button.
1v4n0 is offline   Reply With Quote
Old 05-09-2014, 05:43 AM   #8
odedta
Addict
odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.odedta read the news today, oh boy.
 
Posts: 398
Karma: 96448
Join Date: Dec 2013
Device: iPad
You got the idea but it's a bit trickier than that

The sort button shows you only the end result, if you do "view source" you can see the list elements have not really changed place... you basically need a real-time viewer for the html code, then you c/p that into your epub.

The solution you talked about can be good if you want to allow the user to sort the TOC.

EDIT:

Oh, never mind, I found something that will help you:
1. After you sort your list, in Chrome hit F12.
2. Use the find button and hit the first element in the visual sorted list, the end result.
3. In the code window you will see the code is focused on the first element you searched for. (see attached)
4. Right click <html>
5. Copy as HTML
6. Open Notepad++, paste

voila, you have the sorted list you were looking for.
Attached Thumbnails
Click image for larger version

Name:	Capture.PNG
Views:	244
Size:	40.4 KB
ID:	122775  

Last edited by odedta; 05-09-2014 at 05:47 AM.
odedta is offline   Reply With Quote
Old 05-10-2014, 07:10 AM   #9
1v4n0
Groupie
1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.
 
Posts: 171
Karma: 40000
Join Date: Oct 2013
Device: kindle
I tried, but I gave up (cit.). Here's the file. Can you do sthng w/ it?

I think te problem might be that it's not a <UL> but just a list of links.

Thanks
Attached Files
File Type: rar TOC.rar (12.0 KB, 158 views)
1v4n0 is offline   Reply With Quote
Old 05-10-2014, 07:35 AM   #10
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,297
Karma: 12126329
Join Date: Jul 2012
Device: Kobo Forma, Nook
Quote:
Originally Posted by 1v4n0 View Post
I tried, but I gave up (cit.). Here's the file. Can you do sthng w/ it?
I ran this Regex to pull the text outside of the links to take the text out of the link + compress it into a single line:

Search: <div class="sgc-toc-level-1">\s+<a href="../Text/([^"]+)">([^<]+)</a>\s+</div>
Replace: <div class="sgc-toc-level-1">\2<a href="../Text/\1"></a></div>

Example:

Code:
<div class="sgc-toc-level-1">
  <a href="../Text/Section0004.xhtml">In principio era il gioco di parole</a>
</div>
to:

Code:
<div class="sgc-toc-level-1">In principio era il gioco di parole<a href="../Text/Section0004.xhtml"></a></div>
Then I copied/pasted all the HTML code into this and had it sort it (could have probably used any sorting site/tool):

http://alphabetizer.flap.tv/index.php

I pushed the Alphebatize button, it shoved them all in alphabetical order (according to name).

I then copied/pasted back into Sigil and ran this Regex to shove the text back into the link:

Search: <div class="sgc-toc-level-1">([^<]+)<a href="../Text/([^"]+)"></a></div>
Replace: <div class="sgc-toc-level-1"><a href="../Text/\2">\1</a></div>

Example:

Code:
<div class="sgc-toc-level-1">In principio era il gioco di parole<a href="../Text/Section0004.xhtml"></a></div>
to:

Code:
<div class="sgc-toc-level-1"><a href="../Text/Section0004.xhtml">In principio era il gioco di parole</a></div>
Attached = all alphabetized TOC.

Anyway, may I ask what the purpose of having it sorted in alphabetical order? It seems as if you have a bunch of duplicates, and it might make it very confusing to try to navigate a TOC that does not match the order of the book.
Attached Files
File Type: epub TOCSorted.epub (13.4 KB, 178 views)

Last edited by Tex2002ans; 05-10-2014 at 07:38 AM.
Tex2002ans is offline   Reply With Quote
Old 05-10-2014, 07:56 AM   #11
1v4n0
Groupie
1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.
 
Posts: 171
Karma: 40000
Join Date: Oct 2013
Device: kindle
Thank you. In the end I managed to do a similar thing

- search and replace w/ notepad++, basically turning the link list into a two column ods file, one with the url and one with the name
-ordered a -> z from the latter, save
- open the ods file w/ n++, one more search/replace to turn it back to xhtml.

I could've used sigil, but I don't know all its regex.

The purpose... well the main purpose is learning

Anyway it is a book of quotations, so it's good to have them sorted alphabetically. All these links point to short quotations, not chapters or whatever.

Thank you once again, this website is awesome
1v4n0 is offline   Reply With Quote
Old 05-10-2014, 09:13 AM   #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,297
Karma: 12126329
Join Date: Jul 2012
Device: Kobo Forma, Nook
Quote:
Originally Posted by 1v4n0 View Post
I could've used sigil, but I don't know all its regex.
Well Notepad++ and Sigil use the same Regex engine, so those Regexes would work in Notepad++ as well.

Also, Notepad++ has sort built-in by using TextFX - TextFX Tools - Sort lines case (in)sensitive (at column). That is personally what I use all the time.
Tex2002ans is offline   Reply With Quote
Old 05-10-2014, 12:48 PM   #13
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,781
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
It sounds like you are creating an Index section (reference typically at the end of a book) , not a TOC
theducks is online now   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Manual Sort or Sort by custom column Dethmaul Marvin 2 04-28-2014 11:54 AM
Multiple HTML files w/ TOC to MOBI, not added in order listed in TOC dysfunction Conversion 3 01-03-2014 12:40 AM
Books not listed alphabetically on glo Nascarfan1972 Kobo Reader 2 12-27-2012 03:48 PM
setting author surname alphabetically makeitsimple Library Management 1 03-07-2011 02:52 AM
Can I use Calibre to sort SD card collections alphabetically? Casander7 Calibre 3 07-12-2010 02:34 PM


All times are GMT -4. The time now is 12:06 PM.


MobileRead.com is a privately owned, operated and funded community.