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')
'5pt'
>>> resolved.pop('border-right-width')
'5pt'
>>> resolved.pop('border-bottom-width')
'0pt'
>>> resolved.pop('border-top-width')
'0pt'
>>> 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 <https://github.com/pandas-dev/pandas/pull/15530>`_).
Issues will continue to be prioritised to improve CSS support there, in the absence of other clear use-cases.


.. _Pandas: http://pandas.pydata.org


.. |py-versions| image:: https://img.shields.io/pypi/pyversions/Django.svg
:alt: Python versions supported

.. |version| image:: https://badge.fury.io/py/cssdecl.svg
:alt: Latest version on PyPi
:target: https://badge.fury.io/py/cssdecl

.. |build| image:: https://travis-ci.org/jnothman/cssdecl.svg?branch=master
:alt: Travis CI build status
:scale: 100%
:target: https://travis-ci.org/jnothman/cssdecl

.. |coverage| image:: https://coveralls.io/repos/github/jnothman/cssdecl/badge.svg
:alt: Test coverage
:target: https://coveralls.io/github/jnothman/cssdecl

.. |docs| image:: https://readthedocs.org/projects/cssdecl/badge/?version=latest
:alt: Documentation Status
:scale: 100%
:target: https://cssdecl.readthedocs.io/en/latest/?badge=latest

Project details


Download files

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

Source Distribution

cssdecl-0.1.2.tar.gz (4.8 kB view details)

Uploaded Source

File details

Details for the file cssdecl-0.1.2.tar.gz.

File metadata

  • Download URL: cssdecl-0.1.2.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for cssdecl-0.1.2.tar.gz
Algorithm Hash digest
SHA256 05db0d001fbb822a9ee2e04b32eb4a34481a2568caff424e4092aced1725658c
MD5 72ec0166cefe9a05b456b6123fb1b29b
BLAKE2b-256 e5e3a6a8e330e4cd06e7a5d93edb3fc2fffbf2b5a51bbc9c1b5905e35d656df4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page