You may have a look on
this thread or
this message to see how to use a regex-function to numerate by increment
In your case, the function could be something like :
Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
data['counter'] = data.get('counter', 0) + 1
return f'<h2 class="class_sez">Chapter {data["counter"]}</h2>'
Note : Works only "replacing all"
For a correct numeration, be sure to be on the first page of the epub when starting the "replace all"
If you want to reset the counter at each "Part nn", capture the expression of the title of the part in a group (group 1 in my exemple) with an expression like :
(<h1[^<>]*>Part \d</h1>)|(?:<h2[^<>]*>.+?</h2>)
(up to you to adapt it to your epub)
and use a function like :
Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
# Found a new part:
if match.group(1):
data['counter'] = 0
return match.group(0)
# else, found a chapter:
data['counter'] = data.get('counter', 0) + 1
return f'<h2 class="class_sez">Chapter {data["counter"]}</h2>'