View Single Post
Old 06-30-2020, 09:18 PM   #24
Mister L
Groupie
Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.
 
Posts: 162
Karma: 91148
Join Date: Jun 2010
Device: Sony 350
Quote:
Originally Posted by slowsmile View Post
I've also had a go at trying to create a plugin for your problem. I doubt whether it will satisfy all your requirements but it might be useful to you.

For this plugin I've tried to imagine worst case scenarios where you either have bad formatting or you have to split an ebook or you have to add some files in Sigil.

This plugin only deals with the main chapter headings for each file that you select in Sigil's Book Browser. It does not deal with h2, h3, h4 etc. That's really up to you. It also doesn't matter what tag is used on the chapter heading in the file because the plugin will always attempt to find the topmost line containing text in every file(which, fingers crossed, should be the main heading). Thus the topmost line with text in any selected file is assumed to be the chapter heading for that file.

With regard to 'proper' title case, I've also included a JSON file which has already been pre-populated to allow certain words to be in lower case like ''of', 'from', 'by', 'to' etc in the title attribute. The JSON file only contains one item -- called 'ignore-titlecase' which contains a space delimited string. You can also add your own words to this string to avoid title case and keep lower case so that you can more easily control title case outcomes in the 'title' attributes for the headings.

To use the plugin you must first click and select all the files in the Book Browser that you want processed by the plugin. You can also use Shift-Click to select a group of files. Then just run the plugin and the title attribute with current heading name will be added to the topmost html tag for each selected file.

Also note that this plugin will not work well if fake smallcaps are used in the headings. See link below:
Thanks very much, I will try this one out too. If I understand correctly, both your and Doitsu's plugins are starting from the title tags already in the files, rather than starting from the toc; while it's not the solution I'm looking for to my original problem I do think it can be useful when you are making the toc for the first time and maybe save a little bit of regex work so I'm glad to have both of them.

Quote:
Originally Posted by DiapDealer View Post
"In many cases" is not useful programmatically. Not when trying to create a script that must work in ALL cases (if harm is to be avoided).
I was trying to distinguish between cases where there is a toc id on a tag somewhere inside the file, and cases where the toc points just to the file, and since Sigil understands those cases (and can in fact generate the necessary ID's when making the toc) I would think it should be possible for the plugin to understand them too, if it's starting from the toc.

Either way, as I have already mentioned, there is a solution which works for ALL cases unless I'm missing something, which is to insert the text in an html comment. Does what I am after (the user can then easily grab the text and stick it into whatever tag is appropriate with a regex), causes no harm, simplest possible solution that I can think of.
Mister L is offline   Reply With Quote