Quantcast
Channel: MobileRead Forums - Reading and Management
Viewing all articles
Browse latest Browse all 23795

[Plugin] RemoveInLineStyles Plugin

$
0
0
Hi All,

This "edit" plugin will search for and remove all inline styles (style attributes in xhtml tags) and replace them with the equivalent class stored in an external stylesheet.

Updated: May 18, 2016
Current Version: "0.2.0"

Requires: Python 3.4 or Later (will work fine with Sigil's built-in Python3 engine)

See the attached: RemoveInLineStyles_v020.zip

How it works:
It will parse all existing stylesheets using cssutils (part of the official internal Python 3 requirements included with Sigil) to create a list of all stylesheet file names and class names currently being used to prevent name collisions.

Then it will parse each and every xhtml file, examining each tag and if a style attribute is present, it will remove it, look in the current list of newly created rules to see if an exact match exists and if not add a new class name with that new rule. The correct class attribute is then added to replace the removed style attribute.

If inline styles are found, an external link to the newly created external stylesheet will be inserted into the head element just before the closing head tag.

No changes will be made if no inline styles are actually found in the xhtml file and no new css stylesheet will be created unless at least one inline style is found someplace in the ebook.

It should therefore be safe to run this plugin more than once if needed. Each time it is run it will create a new external stylesheet only if needed.

Warnings
1. Please note, any styles inside the style tag in the head tag will be ignored.

2. Please use this plugin with extreme caution if your ebook uses svg inline styles or mathml inline styles as this has not been properly tested. If needed, a list of tag names to ignore style attributes on can easily be added to deal with this case if problems are detected when used with svg styles and mathml styles.

Problems / Bug Reports / Suggestions for Improvements
If you do run into problems with this plugin, please report them here including a small sample of the problem xhtml/css code, along with information on your platform, Sigil version, etc. And I will try to quickly fix any bugs or issues you run into.

Hope this helps!

KevinH

Attached Files
File Type: zip RemoveInLineStyles_v020.zip (2.5 KB)

Viewing all articles
Browse latest Browse all 23795

Trending Articles