Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 08-11-2020, 05:08 AM   #1
robert.swita
Member
robert.swita began at the beginning.
 
Posts: 13
Karma: 10
Join Date: Aug 2020
Device: none
[Editor Plugin] Reformat plugin

This plugin simplifies, corrects and reformats books in EPUB format. It gets rid of the nested <span> and <div> tags, removes dummy paragraph classes and many more. The desired effect is an ebook in unified format, described below. Default CSS classes are contained in a special file default.css (no references added to this file in a document, it serves as a guideline and source of class definitions). The goal of this Games of Books is to use only CSS classes contained in default.css without changing book's intended appearance.

Installation
Download the attached .zip file and install via Preferences->Advanced>Plugins->Load Plugin or as described in the Introduction to plugins thread. Plugin Reformat will be available in Calibre’s e-Book Editor in Plugins menu.

Main Features & EPUB ebook formatting guidelines
  1. An ebook should preferably consist only of :
    1. Cover (generated automatically by Calibre)
    2. Title, Author, Publisher (<h1-h4> tags in <intro> block)
    3. Dedication, Maps, Introduction (like in chapters)
    4. Chapters (<h1-h3> headers, <center>-<left>-<right> blocks, <diary>-<letter>-<stanza> for italicized blocks, <p> for paragraphs, <h4> for keywords)
    5. Glossary, Index (<dl>,<dt>,<dd> tags)
    6. Copyright note (<center> with <br> tags)
  2. Info about the Author, more books from this author, publisher details – should be outside of the book, preferable in a special ebook ‘About.epub’
  3. Ebook text will be divided into chapter files based on <section>’s tags or <h1-h2> headers (when there are no <sections> yet) or TOC or bolded style class of a paragraph. Remove <section> tag to merge, or add extra </section><section> tags to split files.
  4. Remove inline TOC chapter
  5. All <div> tags will be replaced by default with <center> tag (if it contains some text or image) or reduced (removed, but with keeping it’s children). Blocks should be precisely defined with <diary-letter-stanza> tags or/and with formatting <center-left-right> tags. Blocks always add extra top & bottom margins. The <br/> and <p> tag inside a <p> paragraph is not allowed, and will split the paragraph in two. Paragraph starting with lower letter is joined with previous paragraph.
  6. Attributes allowed in tags:
    1. (inline)<b,u,br,sub,sup,small,em,strong>: none
    2. <span>: any
    3. <i>: ‘lang’
    4. <a>: ‘id’, ‘href’
    5. <img>: ‘src’
    6. <td>,<th>: ‘rowspan’
    7. <ol>: ‘type’
    8. other: ‘class’
  7. Regex expression will try to correct format, remove page numbers and unnecessary white characters (spaces, tabs, line breaks).
  8. Common style classes are included in a special file ‘default.css’. You can use classes from this file, and plugin will insert automatically their definition into CSS file.
  9. TOC is generated automatically based on <h1-h3> headers, except for <intro> blocks.
  10. References in text can be implemented using anchors e.g.
    <a id=”ref0” href=”#ref1”>
    with list of reference notes at the end of the book in the form:
    <dt><a id=”ref1” href=”#ref0”>[1]</a></dt><dd>note</dd>

    Attributes href will be automatically corrected to include proper file reference. Broken anchor links will be reduced. Reference names can be changed using CSS property ‘content’ of the class ‘a’ selector.
  11. This plugin is meant to be called several times (after manual corrections), until the desired effect. Stylesheet is every time updated, removing unused styles and adding new classes from default.css file if needed. You can undo reformatting from Edit menu.

Example of using default CSS classes:

<section>
<intro>
<h2 class=”author”>author</h2>
<h1 class=”title”>title</h1>
</intro>
</section>

<section>
<h1>Part I<h5>PartTitle</h5></h1>
<center><img image.jpg></center>
</section>

<section>
<h2>Chapter 1<h5>ChapterTitle</h5></h2>
<p class=”left">paragraph</p>
<p>paragraph</p>
...
<center>
<stanza>
To be, or not to be,<br/>
That is a question
</stanza>
</center>
...
<letter>
<left>Dear readers</left>
<p> paragraph </p>
<right>author</right>
</letter>
...
</section>

...
<h4>THE END</h4>

Version History
Spoiler:

2.3.5
Arranging files into default folders

2.2.0
Few minor patches
Stable version

2.1.0
Initial splitting includes original splits

2.0.5
Attributes restrictions for tags
Leaves CSS font rules intact

2.0.0
Removes severed links (e.g. after inline TOC removal)
Deals with paragraphs inside paragraphs

1.9.0
Handling of the <br/> tag

1.8.0
Clears comments and namespaces
Minor corrections in anchors

1.7.0
Works with repeating IDs in different files
Better recognition of subchapters
More picky about tag attributes

1.6.0
Rewritten merging.
Major changes in anchor handling

1.0
Rewritten splitting
Attached Files
File Type: docx Formatting guidelines.docx (18.5 KB, 361 views)
File Type: zip Reformat.zip (11.3 KB, 43708 views)

Last edited by robert.swita; 11-06-2021 at 10:29 AM. Reason: update to v2.4.0
robert.swita is offline   Reply With Quote
Old 08-24-2020, 04:11 AM   #2
robert.swita
Member
robert.swita began at the beginning.
 
Posts: 13
Karma: 10
Join Date: Aug 2020
Device: none
Reformat v0.9

Some corrections.
This Calibre ebook-Edit Plugin has no GUI, it's meant to be called several times (after manual corrections), until the desired effect - that is - ebook in unified epub format, described little (by an example) in default.css file. Format is maybe controversial, as it uses default and custom tags (rarely classes).
TOC is generated automatically based on h1-h3 headers, except for <intro> blocks.
Splitting is generated based on <section>'s or h1-h2 headers (if there are no sections yet).

Last edited by robert.swita; 10-16-2020 at 02:29 AM.
robert.swita is offline   Reply With Quote
Advert
Old 09-02-2020, 09:41 AM   #3
robert.swita
Member
robert.swita began at the beginning.
 
Posts: 13
Karma: 10
Join Date: Aug 2020
Device: none
Reformat v.095
Minor bug fixes

Last edited by robert.swita; 10-16-2020 at 02:30 AM.
robert.swita is offline   Reply With Quote
Old 09-02-2020, 10:00 AM   #4
robert.swita
Member
robert.swita began at the beginning.
 
Posts: 13
Karma: 10
Join Date: Aug 2020
Device: none
Reformat v0.95
Updated info in _init_.py

Last edited by robert.swita; 10-16-2020 at 02:30 AM.
robert.swita is offline   Reply With Quote
Old 09-13-2020, 08:59 AM   #5
robert.swita
Member
robert.swita began at the beginning.
 
Posts: 13
Karma: 10
Join Date: Aug 2020
Device: none
Reformat v1.0

Rewritten splitting (much faster now)

Last edited by robert.swita; 10-16-2020 at 09:41 AM.
robert.swita is offline   Reply With Quote
Advert
Old 09-17-2020, 07:23 AM   #6
robert.swita
Member
robert.swita began at the beginning.
 
Posts: 13
Karma: 10
Join Date: Aug 2020
Device: none
Reformat v1.1

Fixing minor bugs, improving chapter detection heuristics

Last edited by robert.swita; 10-16-2020 at 05:35 AM.
robert.swita is offline   Reply With Quote
Old 09-18-2020, 03:56 PM   #7
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 73,952
Karma: 128903250
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Will this be updated to work with Python 3?
JSWolf is online now   Reply With Quote
Old 09-19-2020, 06:56 AM   #8
robert.swita
Member
robert.swita began at the beginning.
 
Posts: 13
Karma: 10
Join Date: Aug 2020
Device: none
Reformat v1.2

This plugin should be compatible with python 2 & 3.
I've installed beta-version 4.99 of portable Calibre to check it out.
It loads plugin fine, but book-editor doesn't update it's menu and debug-info doesn't help much.
I've tried popular plugin ACE with the same result.
Can you confirm, that attached plugin is not python 3 - compatible and point out which plugin is? (and eventually how to check it)

Last edited by robert.swita; 10-16-2020 at 05:36 AM.
robert.swita is offline   Reply With Quote
Old 09-19-2020, 07:13 AM   #9
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 73,952
Karma: 128903250
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by robert.swita View Post
This plugin should be compatible with python 2 & 3.
I've installed beta-version 4.99 of portable Calibre to check it out.
It loads plugin fine, but book-editor doesn't update it's menu and debug-info doesn't help much.
I've tried popular plugin ACE with the same result.
Can you confirm, that attached plugin is not python 3 - compatible and point out which plugin is? (and eventually how to check it)
I'm not running the beta because not all the plugins i use are compatible. But I am planning on giving your plugin a try. But I don't want to install any new plugins that are not Calibre 5 ready. Thank you.
JSWolf is online now   Reply With Quote
Old 09-20-2020, 04:53 PM   #10
thiago.eec
Guru
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 927
Karma: 1177583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
Quote:
Originally Posted by robert.swita View Post
It loads plugin fine, but book-editor doesn't update it's menu and debug-info doesn't help much.
I've tried popular plugin ACE with the same result.
Hi, I don't understand what is the problem. Can you explain it?
ACE is running fine here, using calibre 4.99.17 on Windows 10.
thiago.eec is offline   Reply With Quote
Old 09-21-2020, 04:14 AM   #11
robert.swita
Member
robert.swita began at the beginning.
 
Posts: 13
Karma: 10
Join Date: Aug 2020
Device: none
Hi, Sorry for the alarm. Everything is working under 4.99.
Strange behavior of the editor must've been a result of co-existing with earlier version of Calibre.
robert.swita is offline   Reply With Quote
Old 09-27-2020, 03:26 AM   #12
robert.swita
Member
robert.swita began at the beginning.
 
Posts: 13
Karma: 10
Join Date: Aug 2020
Device: none
Reformat v1.25

Minor corrections to the default.css file (see Format guidelines)

Last edited by robert.swita; 10-16-2020 at 05:36 AM.
robert.swita is offline   Reply With Quote
Old 10-09-2020, 04:38 PM   #13
robert.swita
Member
robert.swita began at the beginning.
 
Posts: 13
Karma: 10
Join Date: Aug 2020
Device: none
Reformat v1.3

Removed bug, which could (rarely) cause loosing data inside <span>'s.
Minor fixes.

Last edited by robert.swita; 10-16-2020 at 09:42 AM.
robert.swita is offline   Reply With Quote
Old 10-09-2020, 05:32 PM   #14
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 73,952
Karma: 128903250
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Are you going to fix the first post so the plugin will be available in the plugin list in Calibre?
JSWolf is online now   Reply With Quote
Old 10-10-2020, 02:37 AM   #15
robert.swita
Member
robert.swita began at the beginning.
 
Posts: 13
Karma: 10
Join Date: Aug 2020
Device: none
Thank you. Didn't really know, that the posts can be edited
robert.swita is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Editor Plugin] LanguageTool Doitsu Plugins 17 04-20-2024 02:21 PM
[Editor Plugin] EpubCheck Doitsu Plugins 146 09-07-2023 01:43 PM
[Plugin] ReworkChapterHeads - Add, replace and reformat chapter headings slowsmile Plugins 87 08-03-2023 05:04 AM
[Editor Plugin] - Enabling 'Customize plugin' dialog directly from the Editor thiago.eec Development 7 01-09-2019 08:05 PM
Editor plugin question DiapDealer Development 2 07-28-2014 10:23 PM


All times are GMT -4. The time now is 02:36 PM.


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