05-08-2014, 12:26 PM | #1 |
Groupie
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 |
05-08-2014, 03:58 PM | #2 |
Addict
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. |
05-09-2014, 04:56 AM | #3 |
Groupie
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> It might work. |
05-09-2014, 05:16 AM | #4 |
Addict
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. |
05-09-2014, 05:23 AM | #5 |
Groupie
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. |
05-09-2014, 05:33 AM | #6 |
Addict
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.
|
05-09-2014, 05:43 AM | #8 |
Addict
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. Last edited by odedta; 05-09-2014 at 05:47 AM. |
05-10-2014, 07:10 AM | #9 |
Groupie
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 |
05-10-2014, 07:35 AM | #10 | |
Wizard
Posts: 2,297
Karma: 12126329
Join Date: Jul 2012
Device: Kobo Forma, Nook
|
Quote:
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> Code:
<div class="sgc-toc-level-1">In principio era il gioco di parole<a href="../Text/Section0004.xhtml"></a></div> 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> Code:
<div class="sgc-toc-level-1"><a href="../Text/Section0004.xhtml">In principio era il gioco di parole</a></div> 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. Last edited by Tex2002ans; 05-10-2014 at 07:38 AM. |
|
05-10-2014, 07:56 AM | #11 |
Groupie
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 |
05-10-2014, 09:13 AM | #12 |
Wizard
Posts: 2,297
Karma: 12126329
Join Date: Jul 2012
Device: Kobo Forma, Nook
|
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. |
05-10-2014, 12:48 PM | #13 |
Well trained by Cats
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
|
|
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 |