Hello @lomkiri, Thank you for the detailed response.
Quote:
Originally Posted by lomkiri
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
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
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
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">
<p class="chapterh2"></p>
<hr class="lineshort"></hr>
<h2><span class="hide"> – </span></h2>
<p class="noindent"><span class="firstletter"></span>
This is how it looks once filled in:
PHP Code:
<body class="largetop">
<p class="chapterh2">Seventeen</p>
<hr class="lineshort"></hr>
<h2><span class="hide">17 – </span>Basil Wenceslas</h2>
<p 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