View Single Post
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