View Single Post
Old 10-19-2021, 03:50 PM   #15
DyckBook
Morlock
DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.DyckBook ought to be getting tired of karma fortunes by now.
 
DyckBook's Avatar
 
Posts: 34
Karma: 2734796
Join Date: Oct 2021
Device: Kindle Paperwhite
Quote:
Originally Posted by lomkiri View Post
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)
@lomkiri I want to thank you for posting this solution.

I had an e-book where the notes and the references were out of sync and I needed to add a digit or two to the id. Searching through the manual I found BuiltinAdd. But my skill set is too limited to allow me to be able to create a regex function that would make use of that.

To my surprise, while browsing the forum to see if my limited skills could still help someone else, I came across your solution to @Karellen's problem. It worked perfectly for me. The e-book is legible (and what's more--clickable) again. Yahoo!
DyckBook is offline   Reply With Quote