Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Editor

Notices

Reply
 
Thread Tools Search this Thread
Old 09-30-2021, 02:40 AM   #1
Karellen
Wizard
Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.
 
Karellen's Avatar
 
Posts: 1,611
Karma: 9500498
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
Batch create xhtml pages

Hello,

When editing an ebook, I create a new xhtml file then paste html code for chapter headings, then fill in the chapter headings and then copy across the text. I do this for each chapter one at a time.

Is there any way to batch create, say, 20 pages which includes my html code for the chapter headings?

It would be even more helpful if the chapter numbers in the html code could be added also. (but that might be asking too much)
Karellen is offline   Reply With Quote
Old 09-30-2021, 04:04 AM   #2
jbacelar
Interested in the matter
jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.
 
jbacelar's Avatar
 
Posts: 421
Karma: 426094
Join Date: Dec 2011
Location: Spain, south coast
Device: Pocketbook InkPad 3
https://manual.calibre-ebook.com/edit.html#id34

You can also split a single HTML file at multiple locations automatically, by right clicking inside the file in the editor and choosing Split at multiple locations. This will allow you to easily split a large file at all heading tags or all tags having a certain class and so on.
jbacelar is offline   Reply With Quote
Old 09-30-2021, 04:10 AM   #3
Karellen
Wizard
Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.
 
Karellen's Avatar
 
Posts: 1,611
Karma: 9500498
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
Quote:
Originally Posted by jbacelar View Post

You can also split a single HTML file at multiple locations automatically, by right clicking inside the file in the editor and choosing Split at multiple locations. This will allow you to easily split a large file at all heading tags or all tags having a certain class and so on.
Thanks. I am aware of this, but this is not what I am after. I need to create new additional pages.
Karellen is offline   Reply With Quote
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
Old 09-30-2021, 07:23 AM   #5
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
Ooops sorry, for the regex-function, you don't want to increment the existing chapter number, but to create a number from 1 to x, so the code would be (saying the form is "<h1>Chapter 1</h1>")

Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
    data.setdefault('chapnum', 0)
    
    if match.group(2): 
        data['chapnum'] += 1
        return match.group(1) + str(data['chapnum']) + match.group(3)
    return  match.group(0)
lomkiri is offline   Reply With Quote
Old 09-30-2021, 11:10 PM   #6
Karellen
Wizard
Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.
 
Karellen's Avatar
 
Posts: 1,611
Karma: 9500498
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
Hello @lomkiri, Thank you for the detailed response.

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.
Oh, perfect. I was so intent of finding a way of doing it within Calibre, I didn't yet think of doing it outside of Calibre. Great, I have now setup 10 templates, and I can quickly run Bulk Rename Utility over them to change the filename and import into Calibre.

Quote:
Originally Posted by lomkiri View Post

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.
Thanks, I am aware of this feature. I was using search and replace to insert the header codes, which worked equally as well. But required manually entering chapter numbers. Not really a problem, but would be nice to automate it.

Quote:
Originally Posted by lomkiri View Post
As for incrementing the chapter number, you can create a regex-function to do so across your book.
I've not used the Regex-function mode. A little above my coding level, but happy to learn.

Quote:
Originally Posted by lomkiri View Post
Ooops sorry, for the regex-function, you don't want to increment the existing chapter number, but to create a number from 1 to x, so the code would be (saying the form is "<h1>Chapter 1</h1>")

Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
    data.setdefault('chapnum', 0)
    
    if match.group(2): 
        data['chapnum'] += 1
        return match.group(1) + str(data['chapnum']) + match.group(3)
    return  match.group(0)
This is my chapter heading code
PHP Code:
<body class="largetop">

  <
class="chapterh2"></p>
  <
hr class="lineshort"></hr>
  <
h2><span class="hide"– </span></h2>

  <
class="noindent"><span class="firstletter"></span
This is how it looks once filled in:
PHP Code:
<body class="largetop">

  <
class="chapterh2">Seventeen</p>
  <
hr class="lineshort"></hr>
  <
h2><span class="hide">17 – </span>Basil Wenceslas</h2>

  <
class="noindent"><span class="firstletter">W</span>hen 
The numbers would be inserted where "17" is. (Is there a way to convert that to the word "Seventeen" also, for the first line?) Image shows end result.

I have modified the Search regex to:
PHP Code:
(<h2><span class="hide">\s)(\s)(</span></h2>) 
Which will find the empty line to insert the number, but when I run the replace, it erases the EN DASH and replaces it with the chapter number. I have tried a few hit and miss attempts to modify "incr_chapter_number", but no luck so far.

Any chance you could show me what to change.
Thanks for your efforts above
Attached Thumbnails
Click image for larger version

Name:	ch17.jpg
Views:	222
Size:	26.1 KB
ID:	189461  

Last edited by Karellen; 09-30-2021 at 11:26 PM.
Karellen is offline   Reply With Quote
Old 09-30-2021, 11:25 PM   #7
Karellen
Wizard
Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.
 
Karellen's Avatar
 
Posts: 1,611
Karma: 9500498
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
Ok, I figured it out. My Search Regex was wrong.

I changed it to this...
PHP Code:
(<h2><span class="hide">)(\s–\s)(</span></h2>) 
And adjusted "incr_chapter_number" to...
PHP Code:
def replace(matchnumberfile_namemetadatadictionariesdatafunctions, *args, **kwargs):
    
data.setdefault('chapnum'19)
    
    if 
match.group(2): 
        
data['chapnum'] += 1
        
return match.group(1) + str(data['chapnum']) + match.group(2) + match.group(3)
    return  
match.group(0
And now it works correctly.

Do you know of any way to convert Number to Word eg 17 to Seventeen?
Karellen is offline   Reply With Quote
Old 10-01-2021, 05:57 AM   #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: 167
Karma: 1497966
Join Date: Jul 2021
Device: N/A
Quote:
Originally Posted by Karellen View Post
Ok, I figured it out. My Search Regex was wrong.
And now it works correctly.
Nice! As you figured out, data is a dict provided by Kovid in the regex-function system to hold persistent values from one call to another. If it is of some use for you, in the other parameters, number gives the number of iterations of the function when in mode "replace all" and file_name, well... ;-)

Quote:
Originally Posted by Karellen View Post
Ok, I figured it out. My Search Regex was wrong.
And now it works correctly.

Do you know of any way to convert Number to Word eg 17 to Seventeen?
I don't, but some others do ;-) A ddg search gives me this or this (same answer, in fact), so we have just to adapt it to your case :

Saying your search string is
(^\s*<[^>]+>)([^<\n]*)(<[^>]+>\n)
to target a line with a number inside a tag, ex: <h2>seventeen</h2> or <p>twenty one</p> (adapt it better if necessary) the function will be :
Code:
def words2int(textnum, numwords={}):
    # create our default word-lists
    if not numwords:

      # singles
      units = [
        "zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
        "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
        "sixteen", "seventeen", "eighteen", "nineteen",
      ]

      # tens
      tens = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]

      # larger scales
      scales = ["hundred", "thousand", "million", "billion", "trillion"]

      # divisors
      numwords["and"] = (1, 0)

      # perform our loops and start the swap
      for idx, word in enumerate(units):    numwords[word] = (1, idx)
      for idx, word in enumerate(tens):     numwords[word] = (1, idx * 10)
      for idx, word in enumerate(scales):   numwords[word] = (10 ** (idx * 3 or 2), 0)

    # primary loop
    current = result = 0
    # loop while splitting to break into individual words
    for word in textnum.replace("-"," ").split():
        # if problem then fail-safe
        if word not in numwords:
          raise Exception("Illegal word: " + word)

        # use the index by the multiplier
        scale, increment = numwords[word]
        current = current * scale + increment
        
        # if larger than 100 then push for a round 2
        if scale > 100:
            result += current
            current = 0

    # return the result plus the current
    return result + current


def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
    wrd = match.group(2)
    if wrd:
        return match.group(1) + str(words2int(wrd)) + match.group(3)
        # or, same thing : return "{}{}{}".format(match.group(1), words2int(wrd), match.group(3))
    return  match.group(0)

Last edited by lomkiri; 10-01-2021 at 06:01 AM.
lomkiri is offline   Reply With Quote
Old 10-01-2021, 06:09 AM   #9
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
Quote:
Originally Posted by lomkiri View Post
Code:
    # loop while splitting to break into individual words
    for word in textnum.replace("-"," ").split():
        # if problem then fail-safe
        if word not in numwords:
          raise Exception("Illegal word: " + word)
NOTE : This function raises an exception if the targeted string is not a number, maybe you want to change this so in that case it returns the input without changes and doesn't raise an exception. If you keep it like this, just be sure that you capture only numbers in your regex.
lomkiri is offline   Reply With Quote
Old 10-01-2021, 08:02 AM   #10
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
Quote:
Quote:
Do you know of any way to convert Number to Word eg 17 to Seventeen?
I don't, but some others do ;-) A ddg search gives me [...]
Looking too far, we don't see what's just under our nose :-). Just here, few days ago in the very same rubric of the same forum: Regex Function words to integers :-D
(the OP has taken the same path indeed, the code of his function comes from the same stackoverflow's link)
lomkiri is offline   Reply With Quote
Old 10-03-2021, 07:52 PM   #11
Karellen
Wizard
Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.
 
Karellen's Avatar
 
Posts: 1,611
Karma: 9500498
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
Hi @lomkiri

Sorry for the delay in responding. I was a bit busy on the weekend.

Thank you for the above. (and silly me for not putting in more of an effort to spot that other thread)

Looking at the above, it may take me a bit of time to comprehend the code and adjust it. My python skills = 0% So let me play with it over the coming week and see if I can figure it out. But part of me is thinking the effort may not be worth it as I can just as quickly type the words as needed. So this will be more of a "challenge" as I have the time available.



ps (I tried to give you some karma points, but apparently I can't until I give others karma points first )
Karellen is offline   Reply With Quote
Old 10-03-2021, 08:03 PM   #12
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 46,206
Karma: 168983734
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
At one time, I created a dummy epub file which I use as a template. It has a cover, 15 chapter files and several copyright, dedication, etc. xhtml files. Basically, I just open it and save it as the new file name after the first basic edits.
DNSB is online now   Reply With Quote
Old 10-03-2021, 08:30 PM   #13
Karellen
Wizard
Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.
 
Karellen's Avatar
 
Posts: 1,611
Karma: 9500498
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
Quote:
Originally Posted by DNSB View Post

At one time, I created a dummy epub file which I use as a template. It has a cover, 15 chapter files and several copyright, dedication, etc. xhtml files. Basically, I just open it and save it as the new file name after the first basic edits.
Thats another good idea. After I finish this current book, I'll look at blanking all the pages and keeping the chapter numbers in place. Should make the next book in the series easier to fix.

This book has short, but many chapters - 118 chapters in this book which is why I was looking for shortcuts. The big help was the shortcut suggested by lomkiri and copying pages outside of calibre, then the regex-function to add the numbers. Then I run a search and replace to add prefixes such as "Fifty-", "Sixty-" etc. So I am about 95% of the way there and its not too painful.
Karellen is offline   Reply With Quote
Old 10-04-2021, 06:00 AM   #14
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
Quote:
Originally Posted by Karellen View Post
Looking at the above, it may take me a bit of time to comprehend the code and adjust it.
Normally, you shouldn't need to adjust it, the regex-function is working out of the box (except for the capture groups, if you need to adjust the regex, as you figured out correctly in the former regex-function). The only thing you should take care is in the part of the regex, if you want to "replace all", you'll have to capture only numbers in your capture group. If you cannot figure out how to do, just use "replace and find" instead of "replace all", it will be quicker than replacing the words by yourself anyway: if there is a word that the function doesn't recognize, you'll be warned with an error-box, nothing more happens.

From the code you've shown us, your number will always be included in a paragraph of this form:
<p class="chapterh2">Seventeen</p>
so the regex part is pretty easy:
(<p class="chapterh2">)([^<]+)(</p>) seems to be enough to do the job in auto.

Quote:
Originally Posted by Karellen View Post
My python skills = 0% So let me play with it over the coming week and see if I can figure it out.
This book (online, pdf or epub) is free and rather basic, maybe it can help you?
https://python.swaroopch.com/
lomkiri is offline   Reply With Quote
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
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Create new section.xhtml from Python dxcore35 Editor 2 03-02-2020 07:47 AM
Can I create a template for the xhtml files? Banjo Sigil 9 01-02-2019 07:37 PM
mkepub tool to create epub from xhtml sethportman ePub 0 02-03-2012 08:59 AM
PRS-T1 How to create a highlight across 2 pages? diddy Sony Reader 0 01-15-2012 02:16 PM
Python script: batch create mobi's from epubs (if they don't exist) jmeb Conversion 0 05-20-2011 01:14 PM


All times are GMT -4. The time now is 01:34 AM.


MobileRead.com is a privately owned, operated and funded community.