![]() |
#1 |
Junior Member
![]() Posts: 5
Karma: 10
Join Date: Sep 2014
Device: iPad 3
|
![]()
Hi,
I have an ebook that I am trying to tidy up. It was all one single text file and only had an asterisk to show where chapters ended. I managed to use find and replace to split the text into chapters and put each of those chapters into its own file. However, at the moment the chapter headings just read "Chapter". I would like to have the chapter numbers in the chapter headings but there are nearly 200 hundred chapters so I don't want to do it manually. Is there a way that I can get Sigil to automatically insert the chapter numbers? I was thinking there might be a way to do it with regex? Maybe something like: Find: Chapter Replace: Chapter ???? Where ???? inserts a number starting at one and increments every time it is inserted... Any ideas? (Sigil 0.7.4 on Mac 10.9.4) |
![]() |
![]() |
![]() |
#2 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
|
i did something similar one time. I used regex to "find" the number bit of the ID tag which was in each file, and which already incremented, then "replaced" that into the chapter heading location. so you have any such tags to work from ?
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Junior Member
![]() Posts: 5
Karma: 10
Join Date: Sep 2014
Device: iPad 3
|
Where would I find these ID tags?
|
![]() |
![]() |
![]() |
#4 |
Interested in the matter
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 421
Karma: 426094
Join Date: Dec 2011
Location: Spain, south coast
Device: Pocketbook InkPad 3
|
First, sorry for my horrible English.
![]() What I do to renumber notes. Required: The text in question in a single file. In your case put behind each "Chapter" a character that does not exist in the original file. For example @. Phyton 2.7 installed. Run the py, which attached, in the folder where the file is. And that's it! Note: Change the extension "Renumerar notas.txt" a "Renumerar notas.py". Of course, first you have to tune the py your needs. (With any text editor). n = start counter. (Usually 0) i = increased. (Usually 1) regex = search the strange character. In this case: re.compile (r "(@)") files = ["file name"] The file extension (shown as html), you put the need. I hope you find it useful. |
![]() |
![]() |
![]() |
#5 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,680
Karma: 23983815
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
@Keeth: You'll have to outsmart Sigil and make it add sequential ids to each heading tag. Assuming that each chapter is a separate .html file and contains only one heading tag at the beginning of the file, for example <h3>Chapter</h3> do the following: 1. Replace all <h3>Chapter</h3> with <h3>Chapter</h3><h4>Chapter</h4>. 2. Regenerate the TOC. You should end up with: <h3>Chapter</h3><h4 id="sigil_toc_id_1">Chapter</h4> for the first chapter. 3. Replace all <h3>Chapter</h3> with nothing. I.e. delete them. 4. Now you can finally add the chapter numbers. Change the mode to Regex and use the following expressions: Find:<h4 id="sigil_toc_id_(\d+)">(.*?)</h4> Replace:<h3 id="sigil_toc_id_\1">\2 \1</h3> 5. Regenerate the TOC. |
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Junior Member
![]() Posts: 5
Karma: 10
Join Date: Sep 2014
Device: iPad 3
|
|
![]() |
![]() |
![]() |
#7 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
|
I am guessing here, but i think if you tell sigil to build a TOC, it creates them for you and adds them to code view- or maybe it's calibre that creates them when you do an epub to epub conversion - you'd have to experiment but it should still be a lot quicker than typing in 200 of them manually.
update: I see a more comprehensive answer has already been provided - I suggest you just follow that. |
![]() |
![]() |
![]() |
#8 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,680
Karma: 23983815
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
![]() The search expression (\d+) searches for one or more numbers. (Putting it in brackets allows it to recycle the match as \1 in the replace statement.) The search expression (.*?) searches for any sequence of characters. Since it's the second bracketed expression, whatever matches it, can be referred to as \2 in the replace statement. There are lots of Regex tutorials that explain all of this in much more detail, and there's also a Sigil Regex subforum. |
|
![]() |
![]() |
![]() |
#9 |
Connoisseur
![]() Posts: 72
Karma: 10
Join Date: Nov 2012
Device: none
|
A Suggestion
All of this goes back to a fix for issue 1961 made in November 2012 (see https://www.mobileread.com/forums/sho...d.php?t=206193)
Now that Sigil is back in development, maybe the contemplated enhancements can be picked up again? Or at least make the appearance of the sigil_toc_id configurable in preferences so as to mimic the pre-issue-1961-fix behavior, so as to avoid merging all files into one. |
![]() |
![]() |
![]() |
#10 |
Junior Member
![]() Posts: 5
Karma: 10
Join Date: Sep 2014
Device: iPad 3
|
@Doitsu your solution has worked perfectly! Thank you
![]() Is there a similar thing I could do do rename the actual file names? I have a couple of hundred files named "index_split_000_001.xhtml" etc. Is there a way I can get them named "Chapter_1.xhtml" etc.? |
![]() |
![]() |
![]() |
#11 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,680
Karma: 23983815
Join Date: Dec 2010
Device: Kindle PW2
|
That feature is actually built into the software. Simply select all files in the book browser, right-click the files, select Rename, enter chapter1 and press Enter. Sigil will then automatically increment all remaining file names.
|
![]() |
![]() |
![]() |
#12 |
Junior Member
![]() Posts: 5
Karma: 10
Join Date: Sep 2014
Device: iPad 3
|
Great! Thank you so much for the help
|
![]() |
![]() |
![]() |
#13 | |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Quote:
|
|
![]() |
![]() |
![]() |
#14 | |
Interested in the matter
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 421
Karma: 426094
Join Date: Dec 2011
Location: Spain, south coast
Device: Pocketbook InkPad 3
|
Quote:
![]() But will have to be someone else, because I have no knowledge to do so. Can you be yourself? ![]() |
|
![]() |
![]() |
![]() |
Tags |
chapter, number, regex, sigil |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Sigil find and replace page numbers | montalex | Sigil | 8 | 03-28-2017 08:51 PM |
Mass Find and Replace | portersprings | Sigil | 5 | 08-20-2014 05:57 PM |
Find/Replace Won't Find | Rand Brittain | Sigil | 7 | 09-24-2011 04:35 AM |
Find, replace, split chapter? | laelaps | Sigil | 8 | 01-20-2011 04:01 PM |
fixing up chapter numbers | cybmole | Sigil | 4 | 01-12-2011 02:49 AM |