View Single Post
Old 11-27-2021, 10:42 AM   #5
chouette
Junior Member
chouette began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Nov 2021
Device: Calibre on PC
Quote:
Originally Posted by lomkiri View Post
If, e.g., your note-anchor is something like this :
Code:
<a class="noteAnchor" href="../Text/footnotes.xhtml#footnote-0003">[3]</a>
and you want to insert the note [80] (i.e. the old n. 80 (and over) will be renumbered)

— Make a backup of you book
— Put as a search string (you'll have to adapt it to the form of the note-anchors of your ebook) :
Code:
<a[^>]+>\[\K(\d+)(\])
— Set the search as regex-function and create the function with the code:
Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
    start_at = 80
    if (n := int(match.group(1))) >= start_at:
        return str(n+1) + match.group(2)
    return match.group(0)
Of course, you must change the var. "start_at" to feet your needs.
— Replace all
— Insert your own note as n. 80

Same process for the notes themselves, just adapt the regex to their form..
If you don't know how to adapt the regexes to your case, give an example of the note-anchor and of the body of the note.
Thank you so much! My note link is as follows:
Code:
<a id="back_note_3" href="notes.html#note_3" title="3" class="noteref">3</a>
And the note itself is like this:
Code:
<dl id="note_3" class="footnote"><dt class="calibre42">[<a href="ch3.html#back_note_3" title="3" class="calibre43">←3</a>]</dt><dd class="calibre44"><p class="block_91"> Note text goes here.</p></dd></dl>
chouette is offline   Reply With Quote