Skip to main content

Python CSS declaration computer

Project description

``cssdecl`` Python CSS declaration computer

|version| |py-versions|

|build| |docs| |coverage|

This package provides basic computation of CSS declarations in order to:

* handle overwriting of properties

>>> from cssdecl import CSS22Resolver
>>> resolve = CSS22Resolver().resolve_string
>>> resolve('font-size: 10pt; font-size: 12pt')
{'font-size': '12pt'}

* expand shorthands like `border-width: 0 5pt`

>>> resolved = resolve('border-width: 0 5pt')
>>> resolved.pop('border-left-width')
>>> resolved.pop('border-right-width')
>>> resolved.pop('border-bottom-width')
>>> resolved.pop('border-top-width')
>>> resolved

* (TODO!) expand shorthands like `font: 5px sans-serif bold` into `font-family: sans-serif`, `font-size: 5px`, `font-weight: bold`
* resolve sizes to a common unit (i.e. pt)

>>> resolve('font-size: 20px')
{'font-size': '15pt'}
>>> resolve('font-size: 1em')
{'font-size': '12pt'}
>>> resolve('font-size: 1em', inherited={'font-size': '20pt'})
{'font-size': '20pt'}
>>> resolve('font-size: small')
{'font-size': '9.600000pt'}

* resolve `inherit` given some inherited declarations

>>> resolve('color: red; color: inherit', inherited={'color': 'blue'})
{'color': 'blue'}

Some properties that are not shorthands in CSS 2.2 become
shorthands in CSS 3, such as `text-decoration`. We therefore
hope to provide :class:`cssdecl.CSS22Resolver` and :class:`cssdecl.CSS3Resolver`.

This module does *not* process CSS selectors (e.g. ``#some-id > * > div.some-class``) and their applicability to elements, including specificity (e.g. ``!important``).

This was first developed for use in Pandas_ (`#15530 <>`_).
Issues will continue to be prioritised to improve CSS support there, in the absence of other clear use-cases.

.. _Pandas:

.. |py-versions| image::
:alt: Python versions supported

.. |version| image::
:alt: Latest version on PyPi

.. |build| image::
:alt: Travis CI build status
:scale: 100%

.. |coverage| image::
:alt: Test coverage

.. |docs| image::
:alt: Documentation Status
:scale: 100%

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
cssdecl-0.1.2.tar.gz (4.8 kB) Copy SHA256 hash SHA256 Source None May 4, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page