View Single Post
Old 10-21-2020, 03:40 AM   #1
EbookMakers
Enthusiast
EbookMakers began at the beginning.
 
Posts: 26
Karma: 38
Join Date: Nov 2019
Location: Paris, France
Device: none
Regex-function to merge endnotes files in editor

Do you have old epubs with one xhtml page per endnote? It is from version 3 of calibre that Kovid proposed a checkbox (in the docx configuration) preventing this separation between the endnotes during a docx -> epub conversion by calibre. An epub -> epub conversion can't change it.

The interface of calibre makes it easy to manually group the notes into a single page, the longest being to determine which files are affected...

I try to do this with a regex-function to run in automatic mode. It runs without an error message.

I have two issues:

1) The editor interface is not updated at the end of the regex-function. If I save a copy of the epub, and examine that file, it shows that the merge was successful. Without really knowing whether to look this side, I tried using apply_container_update_to_gui, but I was unsuccessful. How to update the interface?

2) The function is executed in the "spine order". But how to indicate that we want to start with the 1st file of the book regardless of the current file, in order to group the notes in the 1st note file.

A test file is joined.

Spoiler:

The principle of the regex-function is as follows:

The regex selects something from files with a single note and only those. They must respect the html syntax resulting from a conversion by calibre. Counting by the regex shows whether it is useful to run the regex-function or not.

The important thing is not what is selected but to retrieve the name of the file to add it to a list of files to be merged. This list of filenames grows with more occurrences of the regex.

The function chooses the 1st file as the master file. Merge will only run if there are at least 2 files to merge.
Attached Files
File Type: epub Test endnotes.epub (146.7 KB, 374 views)

Last edited by EbookMakers; 11-23-2020 at 09:30 PM.
EbookMakers is offline   Reply With Quote