Skip to main content

A Python tool to tidy and format CSS files

Project description

CSS Tidy

Code Size PyPI - Version

MIT License Stars

A Python tool to tidy and format CSS files.

Features

  • CSS Formatting: Automatically format CSS code to make it more readable
  • Syntax Validation: Check CSS syntax errors
  • Batch Processing: Support batch processing of multiple CSS files
  • Custom Options: Customize indentation, line breaks, and other formatting options
  • Selector Grouping: Automatically group related CSS selectors by prefix
  • Command Line Tool: Provide simple and easy-to-use command line interface

Installation

pip install css-tidy

Usage

css-tidy [css-file-path] [options]

Command Line Usage

# Format a single CSS file
css-tidy style.css

# Format and output to a new file
css-tidy input.css -o output.css

# Batch process all CSS files in a directory
css-tidy *.css

# Use custom indentation
css-tidy style.css --indent 4

# Minify CSS
css-tidy style.css --minify

# Group selectors
css-tidy style.css --group

Command Line Options

| Option                  | Description |
|------------------------|-------------|
| **[Output Control]**    |             |
| `-o, --output TEXT`     | Output file path |
| `-m, --minify`          | Minify CSS output |
| **[Formatting Options]** |             |
| `-i, --indent INTEGER`  | Indentation size (default: 2) |
| `-s, --sort`            | Sort CSS properties |
| **[Content Processing]** |             |
| `-c, --remove-comments` | Remove CSS comments |
| `-g, --group`           | Group CSS selectors by prefix |
| `-d, --remove-duplicates` | Remove duplicate CSS rules |
| `--duplicate-report`    | Generate JSON report of duplicate rules |
| **[Validation & Info]** |             |
| `--validate-only`       | Only validate CSS, do not format |
| `-v, --verbose`         | Enable verbose output |
| `--version`             | Show version and exit |
| `--help`                | Show this message and exit |

Python API Usage

from css_tidy import CSSFormatter

# Create formatter
formatter = CSSFormatter()

# Format CSS string
css_code = """
body{margin:0;padding:0}div{color:red}
"""
formatted_css = formatter.format(css_code)
print(formatted_css)

# Format file
formatter.format_file('input.css', 'output.css')

# Use custom options
formatter = CSSFormatter(indent_size=4, max_line_length=80)
formatted_css = formatter.format(css_code)

# Group selectors
formatter = CSSFormatter(group_selectors=True)
formatted_css = formatter.format(css_code)

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.


License

This project is licensed under the MIT License. See the LICENSE file for details.


Support

If you have questions or need help, please open an issue on GitHub.

Thank you to all contributors and the open-source community for your support.

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

css_tidy-0.1.3.tar.gz (25.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

css_tidy-0.1.3-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file css_tidy-0.1.3.tar.gz.

File metadata

  • Download URL: css_tidy-0.1.3.tar.gz
  • Upload date:
  • Size: 25.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for css_tidy-0.1.3.tar.gz
Algorithm Hash digest
SHA256 6569f9cf999e0f70835709253865dc04f70faff70d37d3e99399837c92e5b8a7
MD5 cd3472cf60295f2fcb915a7f5d034ca0
BLAKE2b-256 92af20cabfa6237e6304bf8ea1458a2a678cc2ac00c0f7ea531eb5329069c15c

See more details on using hashes here.

File details

Details for the file css_tidy-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: css_tidy-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for css_tidy-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4a811ff6cfd3db6f926c5ec972267c35ee7b8e6527d869de72de6bd542d68d9b
MD5 5ef64c3b0fc3fd9b3c96f39a8b4a781a
BLAKE2b-256 0fd63cac0b5620612feddc58a6179db9d9b49e72f56c0abb645ace41b7d09bdc

See more details on using hashes here.

Supported by

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