View Single Post
Old 03-31-2022, 04:34 PM   #8
lomkiri
Groupie
lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.
 
lomkiri's Avatar
 
Posts: 170
Karma: 1497966
Join Date: Jul 2021
Device: N/A
Here is an exemple how you can renumber your paragraphs, using "search all"
Change what you want (different titles?) in the regex-function. The numbers wont appears in your book (only in the ToC) if you put in your CSS the class:
.toc_text{display: hidden;}

I've put (in the function) :
" chapter n" for PAGE-BREAK
" cn n" for CN
" level n" for CO
change it to fit your needs
_________

Search (select "regex-function"):
find:
Code:
class="((?:CN)|(?:PAGE-BREAK)|(?:CO))("[^>]*>)([^<]*)</p>
function:
Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
    if number == 1:
        data['pg_br'], data['cn'], data['co'] = (0, 0, 0)
    span_d = '<span class="toc_text">'
    span_e = '</span>'
    
    if match.group(1) == "PAGE-BREAK":
        data['pg_br'] += 1
        n = data['pg_br'] 
        text = f'{span_d} chapter {n}{span_e}'
        
    elif match.group(1) == "CN":
        data['cn'] += 1
        n = data['cn']        
        text = f'{span_d} cn {n}{span_e}'
        
    elif match.group(1) == "CO":
        data['co'] += 1
        n = data['co']
        text = f'{span_d} level3 {n}{span_e}'
        
    return f'class="{match.group(1)}{match.group(2)}{match.group(3)}{text}</p>'
It's important to choose "search all", if not, the numbers won't increase
I've test the regex-function and the creation of the ToC (with only PAGE-BREAK as H1 and CN as H2), and it's working, here's the result of the test (screenshot)

Edit:
If you want that CN reinitiate at 1 after every PAGE-BREAK, or something similar, say it, it is easy to integrate this in the code.
Attached Thumbnails
Click image for larger version

Name:	Screenshot_2022-03-31_17-24-50.png
Views:	130
Size:	6.5 KB
ID:	193020  

Last edited by lomkiri; 03-31-2022 at 04:42 PM.
lomkiri is offline   Reply With Quote