diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7a3b4d28..f77546e0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,15 @@
# Changelog
+## v1.7.5
+
+### Description
+
+
+### Closed Issues
+* Strict mode: js_source_text is not defined [CSS] ([#1286](https://github.com/beautify-web/js-beautify/issues/1286))
+* Made brace_style option more inclusive ([#1277](https://github.com/beautify-web/js-beautify/pull/1277))
+* White space before"!important" tag missing in CSS beautify ([#1273](https://github.com/beautify-web/js-beautify/issues/1273))
+
+
## v1.7.4
### Description
@@ -32,6 +43,7 @@ Lessons learned:
### Closed Issues
+* undindent-chained-methods option. Resolves #482 ([#1240](https://github.com/beautify-web/js-beautify/pull/1240))
* Add test and tools folder to npmignore ([#1239](https://github.com/beautify-web/js-beautify/issues/1239))
* incorrect new-line insertion after "yield" ([#1206](https://github.com/beautify-web/js-beautify/issues/1206))
* Do not modify built-in objects ([#1205](https://github.com/beautify-web/js-beautify/issues/1205))
diff --git a/README.md b/README.md
index 8f6fe06e..b35def4c 100644
--- a/README.md
+++ b/README.md
@@ -25,17 +25,17 @@ JS Beautifier is hosted on two CDN services: [cdnjs](https://cdnjs.com/libraries
To pull from one of these services include one set of the script tags below in your document:
```html
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
```
Disclaimer: These are free services, so there are [no uptime or support guarantees](https://github.com/rgrove/rawgit/wiki/Frequently-Asked-Questions#i-need-guaranteed-100-uptime-should-i-use-cdnrawgitcom).
@@ -65,8 +65,11 @@ res = jsbeautifier.beautify_file('some_file.js')
``` python
opts = jsbeautifier.default_options()
opts.indent_size = 2
+opts.space_in_empty_paren = True
res = jsbeautifier.beautify('some javascript', opts)
```
+The configuration option names are the same as the CLI names but with underscores instead of dashes. The example above would be set on the command-line as `--indent-size 2 --space-in-empty-paren`.
+
## JavaScript
@@ -83,18 +86,23 @@ You can also use `js-beautify` as a `node` library (install locally, the `npm` d
$ npm install js-beautify
```
+Import and call the approriate beautifier method for javascript (js), css, or html. All three method signatures are `beautify(code, options)`. `code` is a the string of code to be beautified. options is an object with the settings you would like used to beautify the code.
+
+The configuration option names are the same as the CLI names but with underscores instead of dashes. For example, `--indent-size 2 --space-in-empty-paren` would be `{ indent_size: 2, space_in_empty_paren: true }`.
+
```js
-var beautify = require('js-beautify').js_beautify,
+var beautify = require('js-beautify').js,
fs = require('fs');
fs.readFile('foo.js', 'utf8', function (err, data) {
if (err) {
throw err;
}
- console.log(beautify(data, { indent_size: 2 }));
+ console.log(beautify(data, { indent_size: 2, space_in_empty_paren: true }));
});
```
+
## Options
These are the command-line flags for both Python and JS scripts:
@@ -322,4 +330,4 @@ Thanks also to Jason Diamond, Patrick Hof, Nochum Sossonko, Andreas Schneider, D
Vasilevsky, Vital Batmanov, Ron Baldwin, Gabriel Harrison, Chris J. Shull,
Mathias Bynens, Vittorio Gambaletta and others.
-(README.md: js-beautify@1.7.4)
+(README.md: js-beautify@1.7.5)
diff --git a/js/lib/beautify-html.js b/js/lib/beautify-html.js
index c7fcf6d0..3db2c78c 100644
--- a/js/lib/beautify-html.js
+++ b/js/lib/beautify-html.js
@@ -318,8 +318,8 @@ function Beautifier(html_source, options, js_beautify, css_beautify) {
// Doctype and xml elements
'!doctype', '?xml',
- // ?php tag
- '?php',
+ // ?php and ?= tags
+ '?php', '?=',
// other tags that were in this list, keeping just in case
'basefont', 'isindex'
],
@@ -647,10 +647,8 @@ function Beautifier(html_source, options, js_beautify, css_beautify) {
// must check for space first otherwise the tag could have the first attribute included, and
// then not un-indent correctly
- if (tag_complete.indexOf(' ') !== -1) { //if there's whitespace, thats where the tag name ends
- tag_index = tag_complete.indexOf(' ');
- } else if (tag_complete.indexOf('\n') !== -1) { //if there's a line break, thats where the tag name ends
- tag_index = tag_complete.indexOf('\n');
+ if (tag_complete.search(/\s/) !== -1) { //if there's whitespace, thats where the tag name ends
+ tag_index = tag_complete.search(/\s/);
} else if (tag_complete.charAt(0) === '{') {
tag_index = tag_complete.indexOf('}');
} else { //otherwise go with the tag ending
@@ -915,6 +913,11 @@ function Beautifier(html_source, options, js_beautify, css_beautify) {
//unformatted?
var next_tag = this.get_tag(true /* peek. */ );
+ next_tag = next_tag || '';
+ if (typeof next_tag !== 'string') {
+ next_tag = next_tag[0];
+ }
+
// test next_tag to see if it is just html tag (no external content)
var tag = (next_tag || "").match(/^\s*<\s*\/?([a-z]*)\s*[^>]*>\s*$/);
diff --git a/js/src/html/beautifier.js b/js/src/html/beautifier.js
index 61f5f5a6..cf045f41 100644
--- a/js/src/html/beautifier.js
+++ b/js/src/html/beautifier.js
@@ -170,8 +170,8 @@ function Beautifier(html_source, options, js_beautify, css_beautify) {
// Doctype and xml elements
'!doctype', '?xml',
- // ?php tag
- '?php',
+ // ?php and ?= tags
+ '?php', '?=',
// other tags that were in this list, keeping just in case
'basefont', 'isindex'
],
@@ -499,10 +499,8 @@ function Beautifier(html_source, options, js_beautify, css_beautify) {
// must check for space first otherwise the tag could have the first attribute included, and
// then not un-indent correctly
- if (tag_complete.indexOf(' ') !== -1) { //if there's whitespace, thats where the tag name ends
- tag_index = tag_complete.indexOf(' ');
- } else if (tag_complete.indexOf('\n') !== -1) { //if there's a line break, thats where the tag name ends
- tag_index = tag_complete.indexOf('\n');
+ if (tag_complete.search(/\s/) !== -1) { //if there's whitespace, thats where the tag name ends
+ tag_index = tag_complete.search(/\s/);
} else if (tag_complete.charAt(0) === '{') {
tag_index = tag_complete.indexOf('}');
} else { //otherwise go with the tag ending
@@ -767,6 +765,11 @@ function Beautifier(html_source, options, js_beautify, css_beautify) {
//unformatted?
var next_tag = this.get_tag(true /* peek. */ );
+ next_tag = next_tag || '';
+ if (typeof next_tag !== 'string') {
+ next_tag = next_tag[0];
+ }
+
// test next_tag to see if it is just html tag (no external content)
var tag = (next_tag || "").match(/^\s*<\s*\/?([a-z]*)\s*[^>]*>\s*$/);
diff --git a/js/test/generated/beautify-html-tests.js b/js/test/generated/beautify-html-tests.js
index 4d3ea075..a900968d 100644
--- a/js/test/generated/beautify-html-tests.js
+++ b/js/test/generated/beautify-html-tests.js
@@ -2646,6 +2646,17 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
'