MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Plugins (https://www.mobileread.com/forums/forumdisplay.php?f=268)
-   -   [Plugin] CombineNCXHeadings (https://www.mobileread.com/forums/showthread.php?t=331485)

slowsmile 07-13-2020 01:28 AM

[Plugin] CombineNCXHeadings
 
1 Attachment(s)
Combines the chapter titles and chapter subtitles into single headings in the NCX TOC

Requirements
Plugin Type: Edit
MIT Licence(OSI)
Minimum Sigil requirement: v0.9.3 or higher
Python Requirements: Python 3.4+ (Bundled or External)
OS Requirements: Windows, OSX or Linux
*** Tested on Windows 10, OSX and Linux ***
Current Version: "0.1.2"

Installation
* Select Manage Plugins from the Plugins menu. In the dialog box, select either the Bundled Python or the External Python(Python 3.4+ should be installed on your computer to run this plugin externally).

* Click Add Plugin and select CombineNCXHeadings_vXXX.zip. This will load and install the plugin into Sigil, which you can then select and run using Plugins > Edit > CombineNCXHeadings.

Description
This plugin combines the chapter title headings(as h1) and chapter subtitle headings(as h2) from the html files into single headings in the NCX TOC. The plugin user will also be able to:
  • Separately and individually style the word case of the chapter title and chapter subtitle parts of the combined headings in the NCX TOC.
  • Add a separator of your choice between the chapter title and chapter subtitle parts of the combined NCX TOC headings.
  • Lone chapter title headings(with no chapter subtitles) will also be styled in the user's chosen word case style.
  • This plugin will only create a single level NCX TOC.
For title case only, the plugin user can also more tightly control the title case output by adding the appropriate words to the ignore_titlecase variable in the plugin's associated JSON file. All words in the JSON string will automatically be excluded from title case conversion and will be displayed in lower case instead.

Updates:
This plugin will now create a flat NCX TOC showing all sub-headings formatted with h3 - h6 (Fixed in v0.1.2).If you wish to add indents to your sub-heading entries in your NCX TOC, you can do this in Sigil using Tools > Edit Table of Contents in the normal way by selecting each of the relevant headings in turn and using the Arrow Keys on your keyboard to directly add/remove indents in the edit window as you prefer.

Changes:
Spoiler:

v0.1.2 -- Fixed a problem where, after running the plugin, any h3 - h6 sub-headings were not displayed in the NCX TOC. See Update section for more details. Thanks to AlanHK
v0.1.1 -- Removed README file and added MIT License file. Thanks to Ambaquista.
v0.1.0 -- Initial release

slowsmile 07-22-2020 09:26 AM

Can someone please add this plugin to the Sigil Plugin Index? With thanks.

KevinH 07-22-2020 10:57 AM

Now added.

Quote:

Originally Posted by slowsmile (Post 4014761)
Can someone please add this plugin to the Sigil Plugin Index? With thanks.


AlanHK 07-31-2020 12:50 AM

Could be useful.
What I've been doing when I have chapters like:


<h1>Chapter 4</h1>
<h2>Whatever happens</h2>


is use regex to make it
<h1>Chapter 4<br/>
<span class="chapsub">Whatever happens</span></h1>


Before I do "generate TOC" I convert
<br/>
<span class="chapsub">


to :<br/>
<span class="chapsub">


So I get
Chapter 4: Whatever happens
in the toc file. Then I delete the colon from the chapter files.

I'll still do this when there are other levels of heading (e.g. "Parts" ) that I want to retain, but if there are just chapters this might be simpler.

slowsmile 07-31-2020 07:06 AM

#AlanHK...I'm not really sure how your above example relates to my plugin. From your example, it's seems that you're actually removing the chapter subtitles from the epub TOC page. This plugin doesn't change or touch the epub TOC page. The plugin just combines the chapter title with the chapter subtitle in the toc.ncx file to give you a single-level NCX TOC. See example below:

It just changes the NCX headings from this:
Code:

      <navPoint id="navPoint-7" playOrder="7">
        <navLabel>
          <text>CHAPTER 1</text>
        </navLabel>
        <content src="section-0007.xhtml#auto_bookmark_toc_8"/>
      <navPoint id="navPoint-8" playOrder="8">
          <navLabel>
            <text>All About Kindle Create</text>
          </navLabel>
          <content src="section-0007.xhtml#a__Toc29195570"/>
      <navPoint id="navPoint-9" playOrder="9">
          <navLabel>
            <text>Limitations of this Book</text>
          </navLabel>
          <content src="section-0007.xhtml#a__Toc29195571"/>

To this:
Code:

    <navPoint id="navPoint-3" playOrder="3">
      <navLabel>
        <text>CHAPTER 1 — All About Kindle Create</text>
      </navLabel>
      <content src="section-0007.xhtml"/>
    </navPoint>
    <navPoint id="navPoint-4" playOrder="4">
      <navLabel>
        <text>CHAPTER 2 — Preparing a Word Doc Using Ms Word</text>
      </navLabel>
      <content src="section-0009.xhtml"/>


Doitsu 07-31-2020 07:26 AM

Quote:

Originally Posted by AlanHK (Post 4017932)
What I've been doing when I have chapters like:


<h1>Chapter 4</h1>
<h2>Whatever happens</h2>


is use regex to make it
<h1>Chapter 4<br/>
<span class="chapsub">Whatever happens</span></h1>

IMHO, it'd more efficient, if you used a regex to convert the heading to:

Code:

<h1 title="Chapter 4: Whatever happens">Chapter 4<br/>
<span class="chapsub">Whatever happens</span></h1>

Since Sigil will use title attributes to generate the TOC, you could simply re-generate the TOC without having to add/remove colons.

AlanHK 10-17-2020 02:43 AM

Quote:

Originally Posted by Doitsu (Post 4018003)
Since Sigil will use title attributes to generate the TOC, you could simply re-generate the TOC without having to add/remove colons.

Yes, but now you have to manually update the "Title=" bit. Probably that would be simpler though, unless you were changing several chapter heads.

I do use "Title=" on pages with no visible headings (dedication, etc).

Ambaquista 11-20-2020 03:48 AM

[QUOTE=slowsmile;4011146]
Combines the chapter titles and chapter subtitles into single headings in the NCX TOC

Something wrong!

In the page:
https://www.mobileread.com/forums/sh...d.php?t=331485
I click in:
"Attached Files
File Type: zip CombineNCXHeadings_v010.zip (22.3 KB, 135 views)"
and I get the plugin
"RemoveUnusedBookmarks
Removes all unused bookmarks from the epub file "

Can you please fix this?

Thank you
b rgds
Ambaquista

BeckyEbook 11-20-2020 04:04 AM

Plugin is OK. Only readme.html file is related to other plugin.

slowsmile 11-20-2020 04:12 AM

@Ambaquista...I downloaded the CombineNCXHeadings_v010.zip file from your link and installed it in Sigil. And when I tested the plugin, it worked without problems. Regarding the README file, please ignore that file. I will upload another version of this plugin later without the readme file.

slowsmile 11-20-2020 04:41 AM

Plugin Update(v0.1.1):

-- Removed README file and added MIT License file. Thanks to Ambaquista.

Ambaquista 11-20-2020 05:51 AM

OK
Thanks all the kind (and fast!) answers!
b rgds

AlanHK 07-11-2021 12:47 AM

A book had chapter heads like

<h1>17</h1>
<h2>Jack<h2>
<h3>Monday</h3>

There is some other formatting between heads that makes it difficult to combine them into a single heading in the text.

Sigil generated a TOC with three levels; I wanted all 3 titles to be combined in the TOC.

Using the plugin, it combined h1 and h2, but simply deleted the h3 text.

So adding at least one more level would be appreciated.

Also, it offers a choice of space, em or en dash and tilde as a separator.
Could add period and colon to those. Or just allow to type in any character.
(I know I can just use the tilde and replace it in the ncx myself.)

So I went back back to using regex to build a "title=" tag in the h1 from the other heads.

slowsmile 07-14-2021 06:18 AM

@AlanHK...The plugin's prime purpose is to allow the plugin user to easily combine just the chapter title and chapter subtitle in various ways on a single line in the NCX TOC. As I see it, there is no provision or requirement for adding a third heading level or extra subheading to the NCX line, which I think would perhaps over-complicate the plugin and cause more confusion than anything else, which is why I prefer not to add any further heading levels to the existing NCX heading displays for this plugin.

AlanHK 07-16-2021 04:28 AM

OK. 3 levels of heading isn't too common. So I'll sharpen up my regex.

However, simply deleting lower level headings in the TOC is not good.
If it doesn't combine them it should leave them.
Now it erases all subheads within a chapter.

And configurable separator character would be nice.

slowsmile 07-16-2021 07:08 PM

@AlanHK...

Quote:

However, simply deleting lower level headings in the TOC is not good. If it doesn't combine them it should leave them. Now it erases all subheads within a chapter.
Deleting what from where? Deleting subheads from the NCX TOC or deleting subheads from within the xhtml files? I tested the plugin with a test file which used h1, h2 plus a third heading(formatted with h3) and there were no problems or deletions in the NCX or epub html. I also tested my plugin using a much larger and more complicated epub file that also used 3 heading levels -- including subheadings. The plugin didn't have a problem with either test file and there were no subheading deletions. Of course if you don't format the appropriate headings using just h1 and h2 styling then you will probably get problems. But that's all explained in the plugin release notes which I'm sure you've read already.

Quote:

And configurable separator character would be nice.
When you say configurable separator character do you mean being able to configure different font characters/symbols with different font sizes etc? That's not really necessary since you can easily reconfigure/restyle those separator characters manually anyway after you run the plugin. I always prefer to keep plugins simple -- and if you want to do something more exotic you can usually achieve those changes manually in the CSS or you can do it using grep S&R.

AlanHK 07-23-2021 04:53 AM

Quote:

Originally Posted by slowsmile (Post 4139329)
Deleting what from where?

I had a toc with 3 levels of headings, as mentioned. Using the plugin combined level 1 and level 2, deleted level 3. Only affecting the ncx file, to clarify, the HTML files aren't affected.

This is the way the chapter headings were coded originally.
Code:

<body class="content">
  <div class="title-page-contributor-primary-block">
    <div class="heading1">
      <div class="heading-contents1">
        <div class="title-page-contributor-primary-block">
          <div class="element-number-block">
            <h1>5</h1>
          </div>
          <div class="title-page-contributor-primary-block">
            <h2>Jake</h2>
          </div>

          <h3>Day One</h3>
        </div>
      </div>
    </div>

Using Sigil's generate TOC tool gives 3 levels of headings.
Then using the plugin combines h1 and h2 text in the TOC, and the h3 heads disappear.



Quote:

Originally Posted by slowsmile (Post 4139329)
When you say configurable separator character do you mean being able to configure different font characters/symbols with different font sizes etc?

The character.
I know there is no formatting in the NCX, at least no way I know of.

The plugin offers space, em dash, en dash, tilde as separator.
Many use period or colon, (Chapter 2: The Story Continues) but rather than add more and more symbols, etc., simplest just have a default and let user change it to whatever, preferably retained for next use.

slowsmile 07-23-2021 10:11 PM

@AlanHK...

"I had a toc with 3 levels of headings, as mentioned. Using the plugin combined level 1 and level 2, deleted level 3. Only affecting the ncx file, to clarify, the HTML files aren't affected."
I draw the line at combining h1, h2 and h3 simply because I doubt many people will want to combine 3 headings per NCX heading. In other words your idea of combining 3 levels -- h1, h2 & h3 -- is unrealistic because I'm guessing that not many people will use it. More likely, they will prefer to combine just h1 & h2 headings in the NCX TOC. Add to this that such a plugin change -- to combine h1, separator, h2 & h3 -- would also make plugin usage more complicated. As I've already mentioned, I like to keep it simple for the user.

"Using Sigil's generate TOC tool gives 3 levels of headings.
Then using the plugin combines h1 and h2 text in the TOC, and the h3 heads disappear."

What you describe above is correct behaviour for the plugin because the plugin is only meant to combine just the h1 & h2 headings in the NCX TOC. The plugin does not combine or add h3. In other words, only combining h1 and h2 headings is what the plugin is supposed to do as is clearly stated in the plugin release notes -- it's certainly not a plugin error as you seem to be inferring.

"I know there is no formatting in the NCX, at least no way I know of."
Actually you can both generate and edit/change the headings in the NCX TOC quite easily in Sigil. Just click on Tools > Table of Contents > Generate Table of Contents or Edit Table of Contents and then right-click and edit each heading as you like. In this way you can edit/change each NCX heading in turn by manually typing in and adding h1, h2 headings with a separator and even, if you like, adding h3 headings appropriately to each NCX heading. And when your done, just press OK and your epub's NCX TOC will automatically update to your new NCX TOC heading format. And you could probably also use grep S&R within the toc.ncx file to achieve the same outcome or result.

AlanHK 08-17-2021 03:43 AM

Quote:

Originally Posted by slowsmile (Post 4141289)
The plugin does not combine or add h3. In other words, only combining h1 and h2 headings is what the plugin is supposed to do as is clearly stated in the plugin release notes -- it's certainly not a plugin error as you seem to be inferring.

The error is not that it doesn't combine h1+h2+h3 but that it combines h1+h2 and DELETES h3.
That is damaging the book. If you more than two levels of headings, you can't use this plugin.

Quote:

Originally Posted by slowsmile (Post 4141289)
"I know there is no formatting in the NCX, at least no way I know of."
Actually you can both generate and edit/change the headings in the NCX TOC quite easily in Sigil. Just click on Tools > Table of Contents > Generate Table of Contents or Edit Table of Contents and then right-click and edit each heading as you like. In this way you can edit/change each NCX heading in turn by manually typing in and adding h1, h2 headings with a separator and even, if you like, adding h3 headings appropriately to each NCX heading.

Not when I tried this.
Any codes you type into the the TOC editor get encoded and you just get visible code, not changes on format. e,g, adding <i> </i> to a heading, what I see is the literal codes and looking in the NCX what it did was

<text>&lt;i&gt;TIME AND THE GODS&lt;/i&gt;</text>

If I edit the NCX to make it <text><i>TIME AND THE GODS</i></text>
and then do "Create HTML TOC", the tags were not there. And epubcheck says

ERROR(RSC-005): Error while parsing file 'element "i" not allowed anywhere; expected the element end-tag or text'.

Anyway, not asking to insert any formatting into the NCX.
I leave that to the HTML TOC.
Just a choice of separator character.

slowsmile 08-20-2021 11:32 PM

@AlanHK...

"The error is not that it doesn't combine h1+h2+h3 but that it combines h1+h2 and DELETES h3. That is damaging the book. If you add more than two levels of headings, you can't use this plugin."
I'll have another look at that problem.

"<text>&lt;i&gt;TIME AND THE GODS&lt;/i&gt;</text>
If I edit the NCX to make it <text><i>TIME AND THE GODS</i></text>
and then do "Create HTML TOC", the tags were not there. And epubcheck says: ERROR(RSC-005): Error while parsing file 'element "i" not allowed anywhere; expected the element end-tag or text'. "

Why on earth would you ever expect Sigil's "Create HTML TOC" feature to allow you to format the text within the NCX TOC in the editor or directly within the toc.ncx file itself? Heck, the Create HTML TOC editor is a pure text editor for goodness sake -- it's not an html editor that will allow you to embed html code tags. Also, the toc.ncx file isn't an html file -- it's an XML file. You could perhaps add indents and alter the chapter headings to upper/lower/title case within the Create HTML TOC editor or within the toc.ncx file but that's about all you can do.

AlanHK 08-23-2021 03:53 AM

Quote:

Originally Posted by slowsmile (Post 4148008)
Why on earth would you ever expect Sigil's "Create HTML TOC" feature to allow you to format the text within the NCX TOC.

I didn't. Was pretty sure it would not work but you said

Quote:

Originally Posted by slowsmile
In this way you can edit/change each NCX heading in turn by manually typing in and adding h1, h2 headings with a separator and even,

So presumably you meant "add the text of the h1, h2 headings", not the h1, h2 heading tags.

slowsmile 08-25-2021 05:39 AM

@AlanHK
Quote:

"So presumably you meant "add the text of the h1, h2 headings", not the h1, h2 heading tags. "
In Sigil, if you open either the Tools > Table of Contents > Create TOC pop-up window then, if you want to capitalize, change text or add text to the displayed headings then all you have to do is just double click on any selected heading on the left and you can directly edit the text how you like. You can do that to all displayed headings but, as I've already mentioned, you cannot add html to those changes because it only allows text edits, not edits using html mark-up.

And I'm not sure whether you actually realize it but, due to a fairly recent Sigil change, you now have two ways to specifically edit the NCX TOC in Sigil. You can edit the TOC in the normal way using Tools > Table of Contents > Generate TOC and when you press "OK" this feature always creates an NCX TOC from scratch. But you can also now directly edit the existing NCX TOC(in the toc.ncx) by just clicking on Tools > Table of Contents > Edit TOC. And again this feature also allows you to directly change/edit heading text only(not html) and add indents. And when you click "OK" it automatically updates all your heading changes in the toc.ncx file.

AlanHK 08-27-2021 02:31 AM

Quote:

Originally Posted by slowsmile (Post 4149034)
@AlanHK

Sure. I knew all that. Don't know why you thought I didn't.
I've been using "Edit TOC" and also directly editing the NCX for years.

We just seem to be not communicating well.

slowsmile 08-30-2021 11:17 PM

Update(v0.1.2):
Fixed a problem with sub-headings h3 - h6 not displaying in the TOC NCX after running the plugin. Thanks to AlanHK.

This plugin will now create a flat NCX TOC showing all headings formatted with h1 - h6. If you wish to add indents to your sub-heading entries in your NCX TOC, you can do this in Sigil using Tools > Edit Table of Contents in the normal way by selecting each of the relevant headings in turn and using the arrow keys on your keyboard to directly add/remove indents in the edit window as you prefer.


All times are GMT -4. The time now is 08:35 PM.

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.