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

  • 0.8.0
  • github.​com
  • github.​com
  • 12 months ago
  • 10 minutes ago
  • 3 years ago

Installs

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

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.