ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Indent​X

by socsieng ST2/ST3

A Sublime Text package for indenting and formatting XML and JSON content

Details

Installs

  • Total 19K
  • Win 10K
  • OS X 6K
  • Linux 3K
Oct 23 Oct 22 Oct 21 Oct 20 Oct 19 Oct 18 Oct 17 Oct 16 Oct 15 Oct 14 Oct 13 Oct 12 Oct 11 Oct 10 Oct 9 Oct 8 Oct 7 Oct 6 Oct 5 Oct 4 Oct 3 Oct 2 Oct 1 Sep 30 Sep 29 Sep 28 Sep 27 Sep 26 Sep 25 Sep 24 Sep 23 Sep 22 Sep 21 Sep 20 Sep 19 Sep 18 Sep 17 Sep 16 Sep 15 Sep 14 Sep 13 Sep 12 Sep 11 Sep 10 Sep 9 Sep 8
Windows 6 2 6 12 24 23 21 15 10 7 21 26 12 23 30 9 4 17 24 13 14 22 2 5 24 29 33 32 23 3 7 20 32 35 23 27 9 5 18 37 31 15 15 4 4 9
OS X 4 5 1 8 7 10 9 13 5 2 9 7 8 12 7 5 4 8 8 5 7 8 5 3 8 15 12 9 11 0 3 5 17 10 12 17 6 3 10 9 21 7 6 2 2 7
Linux 4 2 5 3 6 8 8 6 3 0 6 4 2 6 4 0 0 7 4 4 6 4 1 1 8 2 5 5 4 1 0 6 10 3 5 3 1 1 5 4 6 4 1 2 1 6

Readme

Source
raw.​githubusercontent.​com

IndentX

Build Status Coverage Status

IndentX is a forgiving indentation plugin for Sublime Text inspired by Indent Xml, aimed primarily at preserving attribute ordering and working with invalid content.

Supported content types:

  • XML-like content
  • JSON-like content

Available Commands

  • IndentX: Indent
  • IndentX: Indent & format JSON
  • IndentX: Convert JSON to YAML
  • IndentX: Unindent
  • IndentX: Report issue

Note: IndentX: Convert JSON to YAML should be considered alpha.

IndentX: Indent

The Indent command will format both XML and JSON like content (content guess based on the first character < for XML) and can be accessed using the following keyboard short-cuts (think angle brackets: control/command + k + <):

  • Windows: control + k + ,
  • Mac: command + k + ,
  • Linux: control + k + ,

XML before indenting:

Before XML indenting

XML after indenting:

After XML indenting

IndentX: Indent & format JSON

The Indent & format JSON will try and indent and convert JavaScript-like objects to JSON (e.g. wrapping attributes in " and converting ' strings to "). It can be accessed using the following keyboard short-cuts (think curly braces: control/command + k + {):

  • Windows: control + k + [
  • Mac: command + k + [
  • Linux: control + k + [

JSON before and after formatting:

Before JSON formattingAfter JSON formatting

Note: If starting with a JavaScript object and you want to maintain the JavaScipt object format, use the Indent command instead.

IndentX: Convert JSON to YAML

The Convert JSON to YAML command will try to convert a JSON document into YAML. As this feature is still very new, my personal experience with YAML is limited, this feature should be considered very alpha. Please submit any issues you may have.

JSON before and YAML after converting:

Before YAML conversionAfter YAML conversion

IndentX: Unindent

The Unindent command removes comments and whitespace to format content into one line.

IndentX: Report issue

Launches a browser window with the recommended issue structure.

How it works

IndentX uses regular expressions (probably more than it should) to identify tokens to:

  • insert new lines
  • increase indentation (begin tag/object)
  • decrease indentation (end tag/object)

This technique has the following benefits:

  • doesn't require valid strict XML or JSON (close enough should be good enough)
  • preserves attribute order

Installation

Install using Package Control.

Issues

Known issues

There is a known issue when upgrading from previous versions of IndentX where sub modules aren't reloaded. The work-around for this is to restart Sublime Text.

A solution to this issue should be available soon.

Reporting issues

Please report any issues with this plugin with the following sample structure in the body:

Issue with command: {command name}

Sample input:

```
// provide sample here

```

Expected result:

```
// provide expected result here

```

Alternatively, the IndentX: Report issue command will launch a browser with this content pre-filled.