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

Indent​X

by socsieng ALL

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

Details

Installs

  • Total 45K
  • Win 24K
  • Mac 14K
  • Linux 7K
Jul 26 Jul 25 Jul 24 Jul 23 Jul 22 Jul 21 Jul 20 Jul 19 Jul 18 Jul 17 Jul 16 Jul 15 Jul 14 Jul 13 Jul 12 Jul 11 Jul 10 Jul 9 Jul 8 Jul 7 Jul 6 Jul 5 Jul 4 Jul 3 Jul 2 Jul 1 Jun 30 Jun 29 Jun 28 Jun 27 Jun 26 Jun 25 Jun 24 Jun 23 Jun 22 Jun 21 Jun 20 Jun 19 Jun 18 Jun 17 Jun 16 Jun 15 Jun 14 Jun 13 Jun 12 Jun 11
Windows 6 2 7 12 3 2 1 8 5 6 6 5 1 2 4 4 8 6 5 0 0 0 6 4 4 3 0 0 6 9 4 5 4 0 1 5 2 4 5 5 2 3 6 5 9 4
Mac 1 5 2 3 5 0 1 5 2 1 4 4 1 0 1 4 4 5 4 0 2 4 1 6 3 2 0 0 5 4 2 6 4 0 0 1 3 2 1 2 1 0 4 3 1 5
Linux 1 0 2 3 1 0 0 0 0 0 2 0 1 0 1 2 1 0 0 0 0 2 0 1 1 1 0 1 0 2 1 1 0 1 1 1 2 1 0 2 0 0 1 4 2 1

Readme

Source
raw.​githubusercontent.​com

IndentX

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 formatting After 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 conversion After 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.