/html-indent

Primary LanguageRustOtherNOASSERTION

html-indent

html-indent is a html file indenter and checker.

It can be used for a single file, an entire tree, or from stdin (for editor plugin integration).

It supports multi-line tags, and preserves relative indentation in scripts and comments sections. Except spaces, the document structure is preserved and the only validation check is for balanced tags.

Command line options

Usage: html-indent [FILE] [options]

Options:
    -h, --help          print this help menu
    -r, --recursive     process all files in directory tree
    -e, --extension ext file extension for recursive processing
    -n, --dry-run       dry run, don't write files
        --numeric       output indentation value
    -c, --check         check malformed tags
    -l, --lines [start]-[end]
                        limit output to selected lines
    -p, --print         print html result to stdout

Installation

html-indent is written in Rust. For the moment the only option is to build it from source, so install Rust then type

$ cargo install

Editor integration

There is a Vim plugin under tools directory. Just drop it in ~/.vim/indent/ and don't forget to have

filetype plugin indent on

in your .vimrc.

Known alternatives

  • HTML Tidy : Tidy is designed to clean-up html complete documents and I didn't succeed to indent html fragments with the command line version.
  • GNU Emacs editor universe environment. The included html-mode and web-mode, like many Emacs's major modes have implemented indent-region function.
  • Atom editor. Unfortunately, the indentation doesn't work with newlines inside tags.

TODO

  • Better error handling
  • PHP integration
  • Sublime text plugin