Skip to main content

An opinionated HTML/XML soup formatter

Project description

https://travis-ci.org/collective/zpretty.svg?branch=master https://coveralls.io/repos/github/collective/zpretty/badge.svg?branch=master

A tool to format in a very opinionated way HTML, XML and text containing XML snippets.

It satisfies a primary need: decrease the pain of diffing HTML/XML.

For this reason zpretty formats the markup following these rules of thumb:

  • maximize the vertical space/decrease the line length

  • attributes should be sorted consistently

  • attribute sorting is first semantic and then alphabetic

This tool understands the TAL language and has some features dedicated to it.

See TODO section to know what is forecast for the future.

The source code and the issue tracker are hosted on GitHub.

INSTALL

The suggested instal method is using pip:

$ pip install zpretty

USAGE

Basic usage:

zpretty [-h] [--encoding ENCODING] [-i] [-x] [-z] [file [file ...]]

positional arguments:
  file                 The list of files to prettify (defaults to stdin)

optional arguments:
  -h, --help           show this help message and exit
  --encoding ENCODING  The file encoding (defaults to utf8)
  -i, --inplace        Format files in place (overwrite existing file)
  -x, --xml            Threat the input file(s) as XML
  -z, --zcml           Threat the input file(s) as XML. Follow the ZCML
                       styleguide

Without parameters constraining the file type (e.g. -x, -z, …) zpretty will try to guess the right options for you.

Example:

zpretty hello_world.html

DEVELOP

$ git clone ...
$ cd zpretty
$ make

RUNNING TESTS

$ make test

TODO

  • [ ] Python 3 support … ;)

  • [ ] Valueless attributes are not allowed in XML

  • [ ] Attributes are aligned in a strange way if previous sibling has no spaces

  • [ ] TBD: Style attributes should be multiline

Changelog

0.9.3 (2017-05-06)

  • Fix text method

  • Preserve entities in text

  • Added an –encoding parameter

  • Added an –xml parameter to force xml parsing

  • Choose the better parser according to the given filename if no parser is forced

  • Process stdin if ‘-’ is in the arguments or no arguments are passed [ale-rt]

0.9.2 (2017-02-27)

  • Small modification for the order of the zcml attributes

  • Auto add a new line to the end of the prettified files

  • Self heal open self closing tag. [ale-rt]

0.9.1.1 (2017-02-18)

  • Fixed bad release. [ale-rt]

0.9.1 (2017-02-18)

  • Initial support for zcml style guide (#3). [ale-rt]

0.9.0 (2017-02-11)

  • Initial release. [ale-rt]

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

zpretty-0.9.3.tar.gz (17.2 kB view hashes)

Uploaded Source

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