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 17K
  • Win 9K
  • OS X 5K
  • Linux 3K
Aug 20 Aug 19 Aug 18 Aug 17 Aug 16 Aug 15 Aug 14 Aug 13 Aug 12 Aug 11 Aug 10 Aug 9 Aug 8 Aug 7 Aug 6 Aug 5 Aug 4 Aug 3 Aug 2 Aug 1 Jul 31 Jul 30 Jul 29 Jul 28 Jul 27 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
Windows 0 4 12 16 8 21 9 4 3 18 17 15 13 11 4 4 14 14 13 14 23 5 4 14 13 19 15 18 5 2 15 16 22 15 22 4 6 16 15 16 21 11 1 5 16 15
OS X 0 2 13 8 12 7 16 3 4 2 10 6 5 7 4 5 8 7 6 7 5 3 3 11 10 6 7 5 6 2 8 10 15 10 7 0 2 7 6 5 8 10 1 1 7 6
Linux 0 2 6 6 2 5 5 3 1 2 6 9 4 6 0 0 2 3 2 4 5 2 0 2 5 5 8 6 1 2 4 4 3 5 3 2 0 6 3 4 7 3 2 0 2 5

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.