Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Editor

Notices

Reply
 
Thread Tools Search this Thread
Old 11-05-2020, 11:38 PM   #1
roger64
Wizard
roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.
 
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>
Here for example you can see three numbers I'd like to change by selecting the items under the second h3 title and performing .. something.

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.
roger64 is offline   Reply With Quote
Old 11-06-2020, 07:27 AM   #2
thiago.eec
Wizard
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
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*?<
Replace:
Code:
bodyftn\1">\1<
The code you posted is from you endnotes. Now, you also have to change the notes in every chapter, so the numbering will match. The logic is the same, but I can't tell you the exact find/replace terms because you didn't post the code.
thiago.eec is offline   Reply With Quote
Advert
Old 11-06-2020, 08:28 AM   #3
roger64
Wizard
roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.
 
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>
At the moment, as you can see, in the anchor code, the note number is between brackets, but I can easily suppress the brackets if that gives trouble.

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.
roger64 is offline   Reply With Quote
Old 11-06-2020, 09:54 AM   #4
thiago.eec
Wizard
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 1,208
Karma: 1419583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite, Kindle Oasis
Quote:
Originally Posted by roger64 View Post
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)..
Well, my suggestion was based on your code. In this case, it no longer works.

Quote:
Originally Posted by roger64 View Post
As the links are working, I see no point modifying these bodyftn and ftn numbers
The regular expression suggested does not modify the ids (bodyftn and ftn). It changes only the clickable text (1, 2, 3, etc).

Quote:
Originally Posted by roger64 View Post
I just wish to modify these notes numbers (those figures between > < tags) so that for each chapter they resume from 1.
Can't help you there. I don't see an easy way to detect the increase in chapter number.
thiago.eec is offline   Reply With Quote
Old 11-25-2020, 05:26 AM   #5
max-min
Member
max-min has a complete set of Star Wars action figures.max-min has a complete set of Star Wars action figures.max-min has a complete set of Star Wars action figures.
 
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.
max-min is offline   Reply With Quote
Advert
Old 11-25-2020, 09:06 PM   #6
roger64
Wizard
roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.
 
Posts: 2,624
Karma: 3120635
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
Quote:
Originally Posted by max-min View Post
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.
Thank you very much for your reply.

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.
roger64 is offline   Reply With Quote
Old 11-26-2020, 03:54 AM   #7
EbookMakers
Enthusiast
EbookMakers began at the beginning.
 
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+)
with the following function:

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'])
We start at 1. As long as the chapter number does not change, we increase the note number by 1 before making the 'return'. When the chapter number changes, we start again from 1.

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+)
Start at the beginning of the ebook.
"replace all", then "see what have changed".

Last edited by EbookMakers; 11-26-2020 at 02:17 PM.
EbookMakers is offline   Reply With Quote
Old 11-26-2020, 09:04 PM   #8
roger64
Wizard
roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.
 
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?
roger64 is offline   Reply With Quote
Old 11-27-2020, 12:01 AM   #9
jjk
Enthusiast
jjk began at the beginning.
 
Posts: 47
Karma: 10
Join Date: Aug 2018
Location: Paris (France)
Device: Kobo Kindle Vivlio-Inkpad3
Code:
"chapter(\d+)[^\[]+\[\K(\d+)
Here, this EbookMakers' code is working :
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>
@Roger64 : you have to execute that R/R in one shot, that is All replace, on current file or all html files for example.

@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
jjk is offline   Reply With Quote
Old 11-27-2020, 02:42 AM   #10
EbookMakers
Enthusiast
EbookMakers began at the beginning.
 
Posts: 26
Karma: 38
Join Date: Nov 2019
Location: Paris, France
Device: none
Quote:
Originally Posted by jjk View Post
\K which resets the starting point of the reported match
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.
EbookMakers is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
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 PDF 1 04-30-2009 03:03 AM


All times are GMT -4. The time now is 08:47 AM.


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