![]() |
#1 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,624
Karma: 3120635
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
|
Renumbering notes
Hi
I have a book with over 900 notes. After OCR and tweaking with Sigil FootnoteLinker plugin, these notes are now numbered from 1 to 900 and links are OK. However, the paper book lists notes by chapter. So, without touching the links, I need to change the note numbers, chapter by chapter. Code:
<h3 id="toc1">first</h3> <p class="note"><aside class="ntb" epub:type="footnote" id="ftn1"> <span class="notesymbol"><a class="note" href="chapter10.xhtml#bodyftn1">1</a> text-one.</span> </aside></p> <p class="note"><aside class="ntb" epub:type="footnote" id="ftn2"> <span class="notesymbol"><a class="note" href="chapter10.xhtml#bodyftn2">2</a> text-two</span> </aside></p> <p class="note"><aside class="ntb" epub:type="footnote" id="ftn3"> <span class="notesymbol"><a class="note" href="chapter10.xhtml#bodyftn3">3</a> text-three</span> </aside></p> .../... <h3 id="toc2">second</h3> <p class="note"><aside class="ntb" epub:type="footnote" id="ftn10"> <span class="notesymbol"><a class="note" href="chapter12.xhtml#bodyftn10">10</a> text-ten</span> </aside></p> <p class="note"><aside class="ntb" epub:type="footnote" id="ftn11"> <span class="notesymbol"><a class="note" href="chapter12.xhtml#bodyftn11">11</a> text-eleven</span> </aside></p> <p class="note"><aside class="ntb" epub:type="footnote" id="ftn12"> <span class="notesymbol"><a class="note" href="chapter12.xhtml#bodyftn12">12</a> text-twelve</span> </aside></p> 10 would become 1 11 would become 2 12 would become 3 and so on till the end of selected items. Does somebody knows a way to do it? I hope I have been clear... Last edited by roger64; 11-06-2020 at 08:19 AM. |
![]() |
![]() |
![]() |
#2 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,208
Karma: 1419583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite, Kindle Oasis
|
Looks like you want to reset your notes numbering in every new chapter. Is that it?
Looking at your code, I can see that your identifiers already work like this, so it would be easy to achieve it using regex: Find: Code:
bodyftn(\d*?)">\d*?< Code:
bodyftn\1">\1< |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,624
Karma: 3120635
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
|
Thanks for your interest. Forgive me I am not sure I have been clear enough.
First, have another look, I made a mistake entering my code, regarding the numbers. The bodyftn and ftn numbers all grow sequentially from 1 to 900 and are the same except for their names (bodyftn and ftn).. As the links are working, I see no point modifying these bodyftn and ftn numbers At the moment, the numbers for the notes follow exactly these sequential numbers from 1 to 900. I just wish to modify these notes numbers (those figures between > < tags) so that for each chapter they resume from 1. If this replies your question, this is the anchor code: Code:
<span class="Footnoteanchor"><a epub:type="noteref" href="chapter65.xhtml#ftn1" id="bodyftn1">[1]</a></span> Except for the anchor codes which are of course scattered in the text, the note code is put together in chapter 65. The chapters of the book are marked with h3 headers within this chapter 65. Last edited by roger64; 11-06-2020 at 08:41 AM. |
![]() |
![]() |
![]() |
#4 | ||
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,208
Karma: 1419583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite, Kindle Oasis
|
Quote:
Quote:
Can't help you there. I don't see an easy way to detect the increase in chapter number. |
||
![]() |
![]() |
![]() |
#5 |
Member
![]() ![]() ![]() Posts: 13
Karma: 280
Join Date: Aug 2017
Device: touch lux
|
A regex-function should solve your problem. One of the parameter you catch in the function is 'number', which give you the n-th occurrence been processed.
So, if you process your epub file by file (option 'current file' in the search panel), this number will start at 1 for each file and will increase at each occurrence. Ask the function to return str(number) in place the captured group (\d+) Other examples of regex-functions will show you how to do this. |
![]() |
![]() |
Advert | |
|
![]() |
#6 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,624
Karma: 3120635
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
|
Quote:
This is what I have been hoping for. Unhappily, I am not fluent using functions (even if I did use some basic ones) and if you were kind enough to provide me with something which can deal with incremental numbers in a file, I would be very grateful and happy to adapt it. |
|
![]() |
![]() |
![]() |
#7 |
Enthusiast
![]() Posts: 26
Karma: 38
Join Date: Nov 2019
Location: Paris, France
Device: none
|
To answer the question of your post #1, you can try the following regex:
Code:
"chapter(\d+)[^>]+>\K(\d+) Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs): if not data : data['chapter'] = 'Dummy' if data['chapter'] == match.group(1): data['note_number'] += 1 else: data['chapter'] = match.group(1) data['note_number'] = 1 return str(data['note_number']) You can do a previous count (ctrl + n in standard searches), but you have to execute "replace all", then "see what have changed", because the function uses the persistent dic data. You have to start at the beginning of the ebook. For your message #3, you can try the same function, but with the following regex (because of the brackets). I understood that the notes are grouped by chapter. That's it ? If not, we will have to modify the function and use "file_name" to note the change of xhtml file instead of the file number in href selected by the regex in match.group(1). Code:
"chapter(\d+)[^\[]+\[\K(\d+) "replace all", then "see what have changed". Last edited by EbookMakers; 11-26-2020 at 02:17 PM. |
![]() |
![]() |
![]() |
#8 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,624
Karma: 3120635
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
|
I tried and failed though I can't say it's not a mistake of mine.
As this needs more tweaking, probably on my side, maybe it would be appropriate to use PM and only report on this thread when a solution (hopefully) has been found? |
![]() |
![]() |
![]() |
#9 |
Enthusiast
![]() Posts: 47
Karma: 10
Join Date: Aug 2018
Location: Paris (France)
Device: Kobo Kindle Vivlio-Inkpad3
|
Code:
"chapter(\d+)[^\[]+\[\K(\d+) Code:
<span class="Footnoteanchor"><a epub:type="noteref" href="chapter65.xhtml#ftn1" id="bodyftn1">[1]</a></span> <span class="Footnoteanchor"><a epub:type="noteref" href="chapter65.xhtml#ftn1" id="bodyftn1">[2]</a></span> <span class="Footnoteanchor"><a epub:type="noteref" href="chapter66.xhtml#ftn1" id="bodyftn1">[1]</a></span> <span class="Footnoteanchor"><a epub:type="noteref" href="chapter66.xhtml#ftn1" id="bodyftn1">[2]</a></span> <span class="Footnoteanchor"><a epub:type="noteref" href="chapter66.xhtml#ftn1" id="bodyftn1">[3]</a></span> <span class="Footnoteanchor"><a epub:type="noteref" href="chapter67.xhtml#ftn1" id="bodyftn1">[1]</a></span> <span class="Footnoteanchor"><a epub:type="noteref" href="chapter67.xhtml#ftn1" id="bodyftn1">[2]</a></span> <span class="Footnoteanchor"><a epub:type="noteref" href="chapter68.xhtml#ftn1" id="bodyftn1">[1]</a></span> @EbookMakers : thanks for your code. I learnt at least two things : 1) \K which resets the starting point of the reported match 2) using of a rather simple Regex-function ![]() |
![]() |
![]() |
![]() |
#10 |
Enthusiast
![]() Posts: 26
Karma: 38
Join Date: Nov 2019
Location: Paris, France
Device: none
|
Yes. \K is the same as a positive Lookbehind. As in the latter, we can have capture groups in the subpattern preceding \K. I use it because it is compatible with the PCRE flavor which rejects variable length Lookbehind. And I am building my regex in regex101.com with the PCRE flavor and gmu flags.
Last edited by EbookMakers; 11-27-2020 at 02:45 AM. |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Tweaks renumbering books | gianni_1 | Library Management | 5 | 02-12-2016 04:05 PM |
Endnote renumbering | kerliza | Sigil | 4 | 11-02-2013 05:15 PM |
Footnotes renumbering automatically | emslondon | ePub | 4 | 01-15-2013 12:50 PM |
ToC renumbering | JSWolf | Sigil | 21 | 01-27-2012 07:01 PM |
renumbering a pdf | pimpoum | 1 | 04-30-2009 03:03 AM |