Giter Site home page Giter Site logo

sigilplugin_cssremoveunusedselectors's Introduction

sigilPlugin_cssRemoveUnusedSelectors

Remove unused selectors and rules from stylesheets

This plugin uses cssutils (up to Sigil 0.9.17) or css-parser (starting from Sigil 0.9.18) to parse the stylesheets of an epub and lxml/csselect to check if css selectors match at least one element in xhtml files of that epub.

(Cssutils, lxml and cssselect are all bundled in Sigil installers).

All css selectors without corresponding elements in xhtml files are proposed to the user for deletion.

If css parser encounters errors, it raises a warning and the user can choose to proceed or to stop the plugin. In any case, for safety, the specific stylesheets that caused the errors will be left untouched (cssutils implements many but not all of the CSS3 features, e.g. @media rules nested inside other @media rules).

To make the survey in xhtml files, css selectors are converted in XPath by lxml/cssselect. Some of the selectors (those who contain ":hover", ":active", ":focus", ":target", ":visited") will never match anything, so the plugin lets them be. Same thing for selectors that are not yet implemented (*:first-of-type, *:last-of-type, *:nth-of-type, *:nth-last-of-type, *:only-of-type - they work only if an element type is specified). For reference: https://pythonhosted.org/cssselect/#supported-selectors.

Part of the code in customCssutils.py is derived from the package cssutils. cssutils is published under the GNU Lesser General Public License version 3, copyright 2005 - 2013 Christof Hoeke.

sigilplugin_cssremoveunusedselectors's People

Contributors

wrcisco avatar

Stargazers

RQYOU avatar

Watchers

 avatar Becky avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.