beautify-css

2016-07-10 19:55 UTC
  • Xyne

Metadata

Description:

A command-line stream parser for beautifying CSS.

Latest Version:

2013

Architecture:

  • i686
  • x86_64

Build Dependencies:

  • ghc
  • haskell-parsec

Arch Repositories:

  • [xyne-i686]
  • [xyne-x86_64]

AUR Page:

beautify-css

Arch Forum Thread:

166537

Tags:

About

This is a Parsec-based Haskell CSS parser that follows the W3C CSS3 module syntax draft. For now it simply parses CSS piped to STDIN and prints formatted CSS to STDOUT.

Comments are (currently) stripped from the CSS file because the draft's grammar ignores them.

In addition to formatting whitespace and removing comments, selectors and declarations are also sorted.

This does not fix CSS errors. It will fail when it encounters them.1

Here's a list of things that I will likely do when I have some time and motivation:

  • Create a proper Haskell module (and maybe upload it to Hackage).
  • Accept command line arguments (e.g. input file, maybe formatting options).
  • Maybe add support for keeping comments, but maintaining associations between comments and tokens when sorting declarations requires careful thought and may be more complex than it is worth.
  • Add different printers for e.g. compact printing.

Note that I only wrote this as a fun2 little exercise to distract me for a bit from a larger Haskell project that I was working on, so don't bother asking me why I didn't use some existing application instead.

Usage

Remote CSS file:

curl 'https://bbs.archlinux.org/style/ArchLinux.css' | beautify-css

Local CSS file:

beautify-css < ArchLinux.css > ArchLinux.pretty.css

Examples

Compare the before and after versions in the examples directory.


  1. If it fails on valid input, let me know. The grammar does not fully specify some parsers so there is trial-and-error involved.

  2. I am aware that my definition of fun is different from most people's, but there's something about systematic problem solving that I enjoy.

Contact
echo xyne.archlinux.ca | sed 's/\./@/'
Feeds
Blog News
Validation
XHTML 1.0 Strict CSS level 3 Atom 1.0