diff --git a/examples/simple-jsbeautifyrc/.jsbeautifyrc b/examples/simple-jsbeautifyrc/.jsbeautifyrc index f4b0e8c..650b9c1 100644 --- a/examples/simple-jsbeautifyrc/.jsbeautifyrc +++ b/examples/simple-jsbeautifyrc/.jsbeautifyrc @@ -7,5 +7,6 @@ "preserve_newlines": true, "max_preserve_newlines": 2, "jslint_happy": true, - "indent_handlebars": true + "indent_handlebars": true, + "object": {} } diff --git a/examples/simple-jsbeautifyrc/test.html b/examples/simple-jsbeautifyrc/test.html index c6f5bdf..c7b26c9 100644 --- a/examples/simple-jsbeautifyrc/test.html +++ b/examples/simple-jsbeautifyrc/test.html @@ -2,14 +2,14 @@ - Test Page +Test Page -

Hello

-

- World! -

+

Hello

+

+World! +

diff --git a/lib/atom-beautify.js b/lib/atom-beautify.js index d665755..9f47838 100644 --- a/lib/atom-beautify.js +++ b/lib/atom-beautify.js @@ -159,6 +159,10 @@ function beautify() { var softTabs = editor.softTabs; var tabLength = editor.getTabLength(); + // Supported unique configuration keys + // Used for detecting nested configurations in .jsbeautifyrc + var languages = ['js', 'html', 'css', 'sql']; + var defaultOptions = { 'indent_size': softTabs ? tabLength : 1, 'indent_char': softTabs ? ' ' : '\t', @@ -182,7 +186,7 @@ function beautify() { encoding: 'utf8' }))); } catch (e) { - console.log('Failed parsing config JSON at '+configPath); + console.log('Failed parsing config JSON at ' + configPath); externalOptions = {}; } } else { @@ -218,7 +222,8 @@ function beautify() { // Check to see if config file uses nested object format to split up js/css/html options for (key in currOptions) { - if (typeof currOptions[key] === 'object') { + if (_.indexOf(languages, key) >= 0 && // Check if is supported language + typeof currOptions[key] === 'object') { // Check if nested object (more options in value) containsNested = true; break; // Found, break out of loop, no need to continue }