From 1293f707111cbb78aa04657ce287fef03dc7d806 Mon Sep 17 00:00:00 2001 From: Einar Lielmanis Date: Tue, 15 Apr 2014 17:46:56 +0300 Subject: [PATCH] Uniformize default bool option code, fix #449 --- js/lib/beautify-css.js | 7 ++----- js/lib/beautify-html.js | 12 ++++++------ js/test/beautify-tests.js | 10 ++++++++++ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/js/lib/beautify-css.js b/js/lib/beautify-css.js index 0edd8fb9..391e11c3 100644 --- a/js/lib/beautify-css.js +++ b/js/lib/beautify-css.js @@ -63,11 +63,8 @@ options = options || {}; var indentSize = options.indent_size || 4; var indentCharacter = options.indent_char || ' '; - var selectorSeparatorNewline = true; - if (options.selector_separator_newline !== undefined) { - selectorSeparatorNewline = options.selector_separator_newline; - } - var endWithNewline = options.end_with_newline || false; + var selectorSeparatorNewline = (options.selector_separator_newline === undefined) ? true : options.selector_separator_newline; + var endWithNewline = (options.end_with_newline === undefined) ? false : options.end_with_newline; // compatibility if (typeof indentSize === "string") { diff --git a/js/lib/beautify-html.js b/js/lib/beautify-html.js index 1864310e..095453a9 100644 --- a/js/lib/beautify-html.js +++ b/js/lib/beautify-html.js @@ -100,15 +100,15 @@ options.wrap_line_length = options.max_char; } - indent_inner_html = options.indent_inner_html || false; - indent_size = parseInt(options.indent_size || 4, 10); - indent_character = options.indent_char || ' '; - brace_style = options.brace_style || 'collapse'; + indent_inner_html = (options.indent_inner_html === undefined) ? false : options.indent_inner_html; + indent_size = (options.indent_size === undefined) ? 4 : parseInt(options.indent_size, 10); + indent_character = (options.indent_char === undefined) ? ' ' : options.indent_char; + brace_style = (options.brace_style === undefined) ? 'collapse' : options.brace_style; wrap_line_length = parseInt(options.wrap_line_length, 10) === 0 ? 32786 : parseInt(options.wrap_line_length || 250, 10); unformatted = options.unformatted || ['a', 'span', 'bdo', 'em', 'strong', 'dfn', 'code', 'samp', 'kbd', 'var', 'cite', 'abbr', 'acronym', 'q', 'sub', 'sup', 'tt', 'i', 'b', 'big', 'small', 'u', 's', 'strike', 'font', 'ins', 'del', 'pre', 'address', 'dt', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']; - preserve_newlines = options.preserve_newlines || true; + preserve_newlines = (options.preserve_newlines === undefined) ? true : options.preserve_newlines; max_preserve_newlines = preserve_newlines ? parseInt(options.max_preserve_newlines || 32786, 10) : 0; - indent_handlebars = options.indent_handlebars || false; + indent_handlebars = (options.indent_handlebars === undefined) ? false : options.indent_handlebars; function Parser() { diff --git a/js/test/beautify-tests.js b/js/test/beautify-tests.js index 9655c1f8..a78d3329 100755 --- a/js/test/beautify-tests.js +++ b/js/test/beautify-tests.js @@ -1862,6 +1862,16 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify, '
Some test text that should wrap_inside_this\n' + ' section here.
'); + opts.indent_size = 1; + opts.indent_char = '\t'; + opts.preserve_newlines = false; + bth('
\n\tfoo\n
', '
foo
'); + + opts.preserve_newlines = true; + bth('
\n\tfoo\n
'); + + + // css beautifier opts.indent_size = 1; opts.indent_char = '\t';