Skip to main content

Manipulate HTML by moving <style> to style=".

Project description

Py Style Flattener

Introduction

This module is useful to move all the css from style tags to inline style attribute

Makes use of pyquery and regex (due to stdlib's re module not supporting recursion)

Keeps all the @font-face but removes everything else

Installation

pip install py_style_flattener

Usage

It can be used from cli:

$ py-style-flattener INPUT OUTPUT

(note that INPUT and OUTPUT can be either paths or stdin/stdout)

Or as a python module

>>> import py_style_flattener
>>> # using files, you need to open them before.
>>> py_style_flattener.using_files(INPUT, OUTPUT)
>>> # using plain strings
>>> OUTPUT = dpy_style_flattener.using_strings(INPUT)

Current limitations:

  • doesn't fetch remote style
  • cannot set pseudo elements (limitation inherited from cssselect used by pyquery)
  • only takes care of @media screen{} avoiding all other media queries

Contributing

build & release

pip install build twine
python -m build
python -m twine upload --config-file .pypirc dist/*

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

py_style_flattener-0.0.3.tar.gz (16.1 kB view hashes)

Uploaded Source

Built Distribution

py_style_flattener-0.0.3-py3-none-any.whl (16.6 kB view hashes)

Uploaded Python 3

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