View Single Post
Old 09-30-2021, 07:01 AM   #4
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: 167
Karma: 1497966
Join Date: Jul 2021
Device: N/A
You could create in the editor a page that will serve as a template.
Then you save it as an HTML file.
Copy it 20 times (in your OS, with the file manager, not in the editor)
Import those 20 files in your book (menu Files/Import files in the book). As they are HTML files, they will be insert in the "Text" part of the epub.
Now you have just to modify chapter numbers and insert your text.

You may be interested also by the snippets, a very powerful way to insert some text or tags in the current of the cursor, with Ctrl-J. :
The interest over copying from clipboard is that it will be remembered in any of you editing session.

-----

As for incrementing the chapter number, you can create a regex-function to do so across your book.

Say you have all chapters in this form :
<h1>Chapter 1</h1>

Then, with the mode "Regex-function" active in you search box, you search for:
(<h1>Chapter\s)(\d+)(</h1>)

and you create a function "incr_chapter_number" :

Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):

    i = match.group(2)
    if i: 
        return match.group(1) + str(int(i) +1) + match.group(3)
    return  match.group(0)
NB : Adapt the search string to the form of your chapters. For example, if your chapters are of this form:
<h1>— 1 — This is the first chapter</h1>
they will be matched with (<h1>[^\d]+)(\d+)([^<]+)(</h1>)
and the return of the function should be :
return match.group(1) + str(int(i) +1) + match.group(3) + match.group(4)

Last edited by lomkiri; 09-30-2021 at 07:05 AM.
lomkiri is offline   Reply With Quote