Skip to content

Beautify HTML, CSS, and Javascript in Adobe Brackets

License

Notifications You must be signed in to change notification settings

bdacode/brackets-beautify

 
 

Repository files navigation

Brackets Beautify

Brackets Extension that formats open HTML, CSS, and JavaScript files using js-beautify version 1.5.10.

Installation

Latest Release

To install the latest release of this extension use the built-in Brackets Extension Manager which downloads the extension from the extension registry.

Latest Commit

To install the latest commit of this extension use the built-in Brackets Extension Manager which has a function to Install from URL... using this link:

https://github.com/brackets-beautify/brackets-beautify/archive/master.zip

Usage

Brackets Beautify can be run manually on the whole file or on a selection. Use the menu entry Edit > Beautify, the context-menu entry Beautify, or one of the keyboard shortcuts Ctrl-Alt-B (Windows/Linux), Ctrl-Shift-L (Windows), Cmd-Shift-L (Mac), or define your own.

Alternatively it can be enabled to run automatically on save. Use the menu entry Edit > Beautify on Save or the more advanced settings to activate.

Configuration

Beautifier Options

Brackets Beautify supports the same options as js-beautify with the exception of indentation-based options (indent_size, indent_char, and indent_with_tabs) which are taken from the current settings in Brackets. The options can be specified in a .jsbeautifyrc file on project level and will be merged with the default. The default is defined in default.jsbeautifyrc and looks like this:

{
    "js": {
        "eol": "\n",
        "preserve_newlines": true,
        "max_preserve_newlines": 10,
        "space_after_anon_function": true,
        "brace_style": "collapse",
        "keep_array_indentation": true,
        "keep_function_indentation": false,
        "space_before_conditional": true,
        "break_chained_methods": false,
        "eval_code": false,
        "unescape_strings": false,
        "wrap_line_length": 0,
        "wrap_attributes": "auto",
        "end_with_newline": true
    },
    "css": {
        "eol": "\n",
        "end_with_newline": true,
        "selector_separator_newline": true,
        "newline_between_rules": true
    },
    "html": {
        "eol": "\n",
        "end_with_newline": true,
        "preserve_newlines": true,
        "max_preserve_newlines": 10,
        "indent_inner_html": false,
        "brace_style": "collapse",
        "indent_scripts": "normal",
        "wrap_line_length": 0,
        "wrap_attributes": "auto"
    }
}

File Options for Beautify on Save

Brackets Beautify leverages Brackets preferences, which means that you can specify per project settings by defining a .brackets.json in the root directory of your project. With Brackets preferences you can even define per file settings, which is really handy when dealing with third party libraries or minified resources.

Brackets Beautify also support per language settings, which enables you to enable/disabled Beautify on Save for your documents using the Brackets language layer.

The sample .brackets.json below generally enables Beautify on Save and disables it for any JavaScript file in thirdparty, any JavaScript file whose filename contains min and any PHP file.

{
    "bb.beautify.onSave": true,
    "path": {
        "thirdparty/**.js": {
            "bb.beautify.onSave": false
        },
        "**min**.js": {
            "bb.beautify.onSave": false
        }
    },
    "language": {
        "php": {
            "bb.beautify.onSave": false
        }
    }
}

User Key Map for Beautify

Open the keymap.json with the menu entry Debug > Open User Key Map and add an overrides entry.
For example:

{
    "documentation": "https://github.com/adobe/brackets/wiki/User-Key-Bindings",
    "overrides": {
        "Ctrl-Alt-F": "bb.beautify.beautify"
    }
}

External formatters

SASS

You need to supply an absolute path to the sass-convert executable for SASS formatting to work.

  • Install SASS
  • Get the absolute path to the executable
    Some example paths:
    • On MacOSX
      Using rbenv: /Users/<USER>/.rbenv/shims/sass-convert
      Using system Ruby (sudo gem install sass): /usr/bin/sass-convert
    • On Windows: C:\\Ruby193\\bin\\sass-convert.bat
  • Open the Brackets settings file and set the entry bb.beautify.external.sass to the path value.

Issues

Brackets Beautify uses js-beautify to beautify files and is therefore limited to its capabilities. For any issues concerning the actual formatting please refer to the js-beautify issues.

License

Brackets Beautify is licensed under the MIT license. js-beautify is also licensed under the MIT license.

About

Beautify HTML, CSS, and Javascript in Adobe Brackets

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 99.2%
  • HTML 0.8%