Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This is a BBEdit text filter for indenting (and beautifying) JavaScript.
// PBS 12/5/13
// This is a BBEdit text filter for indenting (and beautifying) JavaScript.
// It goes in ~/Library/Application Support/BBEdit/Text Filters/
// On my machine I assigned it a keyboard shortcut: cmd-'
// It requires the js-beautify Node module:
// The trick, in the script, was providing the full path to the globally-installed js-beautify module.
// I figured out how to write a BBEdit/Node text filter from the very nice example here:
var jsbeautify = require('/usr/local/lib/node_modules/js-beautify').js_beautify;
process.stdin.on('data', function(chunk) {
var s = jsbeautify(chunk, {
indent_size: 2,
brace_style: "end-expand"
Copy link

twhid commented Apr 3, 2014

Glad it was of some use :-) Trying to write a filter using UglifyJS right now but running into issues... oy.

Copy link

greg-raven commented Apr 18, 2021

I don't use NodeJS, so this is the approach I used:


## requires pip3 install jsbeautify
## requires pip3 install cssbeautify
## no htmlbeautify for pip installs
## no Homebrew version
## online at
## and


if [ "$BB_DOC_LANGUAGE" == "CSS" ]; then
elif [ "$BB_DOC_LANGUAGE" == "JavaScript" ]; then
	js-beautify --jslint-happy
elif [ "$BB_DOC_LANGUAGE" == "JSON" ]; then
	python3 -m json.tool
	echo "unknown language: $BB_DOC_LANGUAGE"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment