Thread: Sigil Plugins!
View Single Post
Old 08-10-2013, 12:19 PM   #1
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,676
Karma: 205039118
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Sigil Plugins!

Ok, not officially anyway, but still ... sorta ... kinda.

I've been using the "Open with" feature of Sigil to launch Python scripts from *.bat files and bash scripts... with varying levels of success.

I thought I'd share in case anyone was interested in creating their own "plugins."

I'm using Python because that's what I know, but there's really nothing preventing someone from using their own preferred scripting/programming language if they so desired.

Having said that, however; if you want to try my attached samples (working on Windows and Linux), you'll need to have Python installed (and the interpreter on your PATH).

I've got three simple plugins that perform various things:
1) Smarten Punctuation (using SmartyPants)
2) Generate a new UUID in the OPF file (useful for those who use templates)
3) Add the Apple XML file to the ePub (so embedded fonts work in iBooks)

After ensuring you have a working Python installation, unzip the attached file to a folder/directory on your system. Then from within Sigil, right-click on a file and select "Open With." Then browse to the folder where you unzipped the files and select the plugin you want to use (*.bat on windows ... *.sh on linux). Optionally change the name of the "editor" to something relevant, and that's really it.

*Please* don't use these on something you've spent hours getting just right without having proper backups. They're working fairly well for me, but still... caution would definitely be in order.


Details:

Smarten Punctuation: smarten_punc.(bat|sh). Edit smarten_punc.py to tweak how things work (converting entities to characters, which entities, etc). I associate this plugin with (x)html files (and yes, it only works on one file at a time). This script is not discriminating in what kind of file it will work on, so please don't attempt to use it on anything other than your (x)html files. I don't know what the results would be!

Generate New UUID: new_uuid.(bat|sh) Edit new_uuid.py to tweak how things work. I associate this plugin with the OPF file.

Add Apple XML: apple_xml.(bat|sh) Edit apple_xml.py to tweak how things work. I associate this plugin with font files (even though it doesn't modify them). NOTE: you won't see the XML file in Sigil after running the plugin, but you will get an indication that the epub is in an unsaved state. If you save the ePub, rest assured the xml file will show up in Sigil 'Misc' folder next time you open the ePub.

Anyway, I hope someone can have fun with this. It's really meant as a "proof of concept" sort of thing. I'm more than willing to help people get things working in a general way, but just know that I'm not volunteering for a "make it do X!, or make it do Y!" sort of free-for-all.

Also, although SmartyPants does an admirable job, it's not perfect (and I didn't write it). So I'm not responsible for it behaving in a way you don't think it should.

For myself, I eventually foresee me creating a Tk graphical front-end that will allow me to choose from several common utilities to be performed for that file type. But I'm in no hurry.

** (If you want to use these in conjunction with Calibre's 'Open with' plugin to launch Sigil, you'll probably need to edit the bat/sh files and hardcode the path to your Python interpreter. Something about the Calibre environment prevents Sigil from finding the interpreter even when it's on the system path. I hard code them anyway, simply because I have multiple versions of Python installed.) **
Attached Files
File Type: zip sigil_plugins.zip (16.1 KB, 1632 views)

Last edited by DiapDealer; 08-10-2013 at 01:06 PM.
DiapDealer is offline   Reply With Quote