Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
40c5356
Merge pull request #2248 from beautifier/staging/main
bitwiseman Feb 16, 2024
bb335b4
Properly escape '\s' in test file
havardAasen Mar 22, 2024
e53d549
Merge pull request #2259 from havardAasen/regex-in-python3.12
bitwiseman Mar 24, 2024
d5176ef
Fixed #2260 - <style> and <script> tags indentation if also indenting…
gergely-gyorgy-both Mar 29, 2024
d812eec
Merge branch 'main' into fix-angular-control-flow-and-script-style-ta…
bitwiseman Apr 1, 2024
1de3d3b
Bump mocha from 10.3.0 to 10.4.0
dependabot[bot] Apr 1, 2024
df0085c
Merge pull request #2264 from beautifier/dependabot/npm_and_yarn/moch…
bitwiseman Apr 2, 2024
af2065c
Bump glob from 10.3.10 to 10.3.12
dependabot[bot] Apr 2, 2024
7a570c0
Merge pull request #2265 from beautifier/dependabot/npm_and_yarn/glob…
bitwiseman Apr 2, 2024
d8a51fb
Bump webpack from 5.90.2 to 5.91.0
dependabot[bot] Apr 2, 2024
097e378
Merge pull request #2261 from beautifier/dependabot/npm_and_yarn/webp…
bitwiseman Apr 3, 2024
dc47437
Bump serve from 14.2.1 to 14.2.2
dependabot[bot] Apr 22, 2024
fee011e
Merge pull request #2266 from beautifier/dependabot/npm_and_yarn/serv…
bitwiseman Apr 27, 2024
7f7484d
Merge branch 'main' into fix-angular-control-flow-and-script-style-ta…
bitwiseman Apr 27, 2024
18a518a
Update templatablepattern.js
bitwiseman Apr 27, 2024
7d8f600
Update tokenizer.js
bitwiseman Apr 27, 2024
71bd927
Bump serve from 14.2.2 to 14.2.3
dependabot[bot] Apr 29, 2024
c03f19d
Bump nopt from 7.2.0 to 7.2.1
dependabot[bot] May 6, 2024
98a54cc
Bump glob from 10.3.12 to 10.3.15
dependabot[bot] May 13, 2024
bf22eec
Merge pull request #2272 from beautifier/dependabot/npm_and_yarn/glob…
bitwiseman May 18, 2024
99bae32
Merge pull request #2271 from beautifier/dependabot/npm_and_yarn/nopt…
bitwiseman May 18, 2024
84bf9db
Merge pull request #2269 from beautifier/dependabot/npm_and_yarn/serv…
bitwiseman May 18, 2024
a7dbcb3
Document importing js-beautify through ESM imports
beep-beep-beep-boop Jun 3, 2024
6de9268
Merge pull request #2277 from beep-beep-beep-boop/document-esm-import
bitwiseman Jun 4, 2024
3e3d212
Bump glob from 10.3.15 to 10.4.2
dependabot[bot] Jun 24, 2024
58b5385
Use Cloudflare Polyfill CDN instead of polyfill[.]io
kapytein Jun 27, 2024
159b226
Merge pull request #2288 from kapytein/patch-1
bitwiseman Jun 29, 2024
538a59f
Merge pull request #2287 from beautifier/dependabot/npm_and_yarn/glob…
bitwiseman Jun 29, 2024
90f1882
Bump braces from 3.0.2 to 3.0.3
dependabot[bot] Jun 29, 2024
e00991e
Bump webpack from 5.91.0 to 5.92.1
dependabot[bot] Jun 29, 2024
90cb644
Bump mocha from 10.4.0 to 10.5.2
dependabot[bot] Jun 29, 2024
730ced4
Update dependabot.yml
bitwiseman Jun 29, 2024
d67ceb1
Merge branch 'main' into fix-angular-control-flow-and-script-style-ta…
bitwiseman Jun 29, 2024
49df420
Merge pull request #2263 from gergely-gyorgy-both/fix-angular-control…
bitwiseman Jun 29, 2024
6c9df59
Merge pull request #2279 from beautifier/dependabot/npm_and_yarn/brac…
bitwiseman Jun 29, 2024
5cfd99b
Merge pull request #2285 from beautifier/dependabot/npm_and_yarn/webp…
bitwiseman Jun 29, 2024
0863e19
Merge pull request #2290 from beautifier/dependabot/npm_and_yarn/moch…
bitwiseman Jul 1, 2024
4cf4772
Remove obsolete setuptools test integration (#2304)
cjwatson Jul 31, 2024
2c80a63
Bump webpack from 5.92.1 to 5.94.0 (#2308)
dependabot[bot] Sep 9, 2024
23126f9
fixed (#2291)
jkmnt Sep 9, 2024
eddf69d
Bump ansi-regex from 6.0.1 to 6.1.0 (#2311)
dependabot[bot] Sep 10, 2024
1ff8cce
Added a download button (#2312)
ozearkhan Sep 15, 2024
b91d6b8
build wheel for pypi package (#2314)
trim21 Sep 24, 2024
6c683ad
Bump glob from 10.4.2 to 11.0.0 (#2294)
dependabot[bot] Nov 17, 2024
e05727f
Bump requirejs from 2.3.6 to 2.3.7 (#2298)
dependabot[bot] Nov 17, 2024
4400f81
Bump nopt from 7.2.1 to 8.0.0 (#2310)
dependabot[bot] Nov 17, 2024
36229b2
Bump serve from 14.2.3 to 14.2.4 (#2322)
dependabot[bot] Nov 17, 2024
4238a89
Bump mocha from 10.5.2 to 10.8.2 (#2326)
dependabot[bot] Nov 17, 2024
31f6378
Bump webpack from 5.94.0 to 5.96.1 (#2325)
dependabot[bot] Nov 17, 2024
c6c461a
Bump cross-spawn from 7.0.3 to 7.0.5 (#2330)
dependabot[bot] Nov 17, 2024
aef38b4
Bump mocha from 10.8.2 to 11.0.1 (#2333)
dependabot[bot] Dec 3, 2024
5460c97
fix(cli): templating arguments getops (#2280)
joshuachp Dec 5, 2024
d99c521
Bump webpack from 5.96.1 to 5.97.1 (#2335)
dependabot[bot] Dec 13, 2024
06b94cf
Bump glob from 11.0.0 to 11.0.1 (#2340)
dependabot[bot] Jan 25, 2025
ac09b0e
Bump webpack-cli from 5.1.4 to 6.0.1 (#2336)
dependabot[bot] Jan 25, 2025
73a195c
Bump mocha from 11.0.1 to 11.1.0 (#2342)
dependabot[bot] Feb 7, 2025
fc98484
Bump nopt from 8.0.0 to 8.1.0 (#2343)
dependabot[bot] Feb 7, 2025
adb5a57
Update Changelog
Feb 7, 2025
08b1853
Bump version numbers for 1.15.2
Feb 7, 2025
99b86e4
Merge remote-tracking branch 'origin/staging/main' into staging/release
Feb 7, 2025
6014e7a
Release: 1.15.2
Feb 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
rebase-strategy: "disabled"
schedule:
interval: "weekly"
open-pull-requests-limit: 15
- package-ecosystem: "pip" # See documentation for possible values
directory: "/python" # Location of package manifests
rebase-strategy: "disabled"
schedule:
interval: "weekly"
open-pull-requests-limit: 15
- package-ecosystem: "github-actions"
directory: "/"
rebase-strategy: "disabled"
schedule:
# Check for updates to GitHub Actions every week
interval: "weekly"
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/milestone-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ jobs:
git remote add trigger git@js-beautify-github.com:beautifier/js-beautify.git
git fetch --all
- name: Install python twinE
run: pip install twine
run: pip install twine wheel
- name: Run release script for ${{ github.event.milestone.title }}
env:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
MILESTONE_VERSION: ${{ github.event.milestone.title }}
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
TWINE_USERNAME: ${{secrets.PYPI_USERNAME}}
TWINE_PASSWORD: ${{secrets.PYPI_PASSWORD}}
TWINE_USERNAME: ${{secrets.PYPI_USERNAME}}
TWINE_PASSWORD: ${{secrets.PYPI_PASSWORD}}
run: |
./tools/release-all.sh ${MILESTONE_VERSION}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v1.15.2
* Patch SNYK-JS-CROSSSPAWN-8303230 issue brought it through old glob package ([#2328](https://github.com/beautifier/js-beautify/issues/2328))
* release wheels on pypi ([#2313](https://github.com/beautifier/js-beautify/issues/2313))
* ModuleNotFoundError: No module named 'setuptools.command.test' as of latest setuptools package release ([#2301](https://github.com/beautifier/js-beautify/issues/2301))
* [Python]Compatible with setuptools>=72 ([#2300](https://github.com/beautifier/js-beautify/issues/2300))

## v1.15.1
* Turn new angular templating off by default in html ([#2247](https://github.com/beautifier/js-beautify/pull/2247))
* Perf regression in latest release (1.15.0) ([#2246](https://github.com/beautifier/js-beautify/issues/2246))
Expand Down
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ JS Beautifier is hosted on two CDN services: [cdnjs](https://cdnjs.com/libraries

To pull the latest version from one of these services include one set of the script tags below in your document:
```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.1/beautify.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.1/beautify-css.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.1/beautify-html.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.2/beautify.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.2/beautify-css.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.2/beautify-html.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.1/beautify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.1/beautify-css.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.1/beautify-html.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.2/beautify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.2/beautify-css.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.2/beautify-html.min.js"></script>
```

Example usage of a JS tag in html:
Expand All @@ -76,7 +76,7 @@ Example usage of a JS tag in html:

. . .

<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.1/beautify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.2/beautify.min.js"></script>
<script src="script.js"></script>
</body>
</html>
Expand Down Expand Up @@ -152,6 +152,17 @@ fs.readFile('foo.js', 'utf8', function (err, data) {
});
```

If you are using ESM Imports, you can import `js-beautify` like this:

```js
// 'beautify' can be any name here.
import beautify from 'js-beautify';

beautify.js(data, options);
beautify.html(data, options);
beautify.css(data, options);
```

## Python
After installing, to beautify using Python:

Expand Down Expand Up @@ -434,4 +445,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.15.1)
(README.md: js-beautify@1.15.2)
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<title>Online JavaScript beautifier</title>
<link rel="icon" href="web/favicon.png" type="image/png">

<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=default&flags=gated"></script>
<script src="https://cdnjs.cloudflare.com/polyfill/v2/polyfill.min.js?features=default&flags=gated"></script>

<!-- Codemirror from https://cdnjs.com/libraries/codemirror -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/codemirror.min.css" integrity="sha512-uf06llspW44/LZpHzHT6qBOIVODjWtv4MxCricRxkzvopAlSWnTf6hpZTFxuuZcuNE9CBQhqE0Seu1CoRk84nQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
Expand Down Expand Up @@ -97,6 +97,7 @@ <h1 class="logo">
<div class="buttons-box">
<button class="submit"><strong>Beautify Code</strong> <em>(ctrl&#8209;enter)</em></button>
<button class="control" type="button" onclick="copyText()"><strong>Copy to Clipboard</strong></button>
<button class="control" type="button" onclick="downloadBeautifiedCode()"><strong>Download</strong></button>
<button class="control" type="button" onclick="selectAll()"><strong>Select All</strong></button>
<button class="control" type="button" onclick="clearAll()"><strong>Clear</strong></button>
<input type="file" onchange="changeToFileContent(this)">
Expand Down
53 changes: 35 additions & 18 deletions js/lib/beautifier.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/lib/beautifier.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/lib/beautifier.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/lib/beautifier.min.js.map

Large diffs are not rendered by default.

53 changes: 35 additions & 18 deletions js/lib/beautify-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,10 @@ TemplatablePattern.prototype.__set_templated_pattern = function() {
if (!this._disabled.handlebars) {
items.push(this.__patterns.handlebars._starting_pattern.source);
}
if (!this._disabled.angular) {
// Handlebars ('{{' and '}}') are also special tokens in Angular)
items.push(this.__patterns.handlebars._starting_pattern.source);
}
if (!this._disabled.erb) {
items.push(this.__patterns.erb._starting_pattern.source);
}
Expand Down Expand Up @@ -2040,7 +2044,7 @@ Beautifier.prototype.beautify = function() {
type: ''
};

var last_tag_token = new TagOpenParserToken();
var last_tag_token = new TagOpenParserToken(this._options);

var printer = new Printer(this._options, baseIndentString);
var tokens = new Tokenizer(source_text, this._options).tokenize();
Expand Down Expand Up @@ -2363,7 +2367,7 @@ Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_to
return parser_token;
};

var TagOpenParserToken = function(parent, raw_token) {
var TagOpenParserToken = function(options, parent, raw_token) {
this.parent = parent || null;
this.text = '';
this.type = 'TK_TAG_OPEN';
Expand Down Expand Up @@ -2430,13 +2434,14 @@ var TagOpenParserToken = function(parent, raw_token) {
}

// handlebars tags that don't start with # or ^ are single_tags, and so also start and end.
// if they start with # or ^, they are still considered single tags if indenting of handlebars is set to false
this.is_end_tag = this.is_end_tag ||
(this.tag_start_char === '{' && (this.text.length < 3 || (/[^#\^]/.test(this.text.charAt(handlebar_starts)))));
(this.tag_start_char === '{' && (!options.indent_handlebars || this.text.length < 3 || (/[^#\^]/.test(this.text.charAt(handlebar_starts)))));
}
};

Beautifier.prototype._get_tag_open_token = function(raw_token) { //function to get a full tag and parse its type
var parser_token = new TagOpenParserToken(this._tag_stack.get_parser_token(), raw_token);
var parser_token = new TagOpenParserToken(this._options, this._tag_stack.get_parser_token(), raw_token);

parser_token.alignment_size = this._options.wrap_attributes_indent_size;

Expand Down Expand Up @@ -2903,6 +2908,7 @@ Tokenizer.prototype._get_next_token = function(previous_token, open_token) { //
token = token || this._read_open_handlebars(c, open_token);
token = token || this._read_attribute(c, previous_token, open_token);
token = token || this._read_close(c, open_token);
token = token || this._read_script_and_style(c, previous_token);
token = token || this._read_control_flows(c, open_token);
token = token || this._read_raw_content(c, previous_token, open_token);
token = token || this._read_content_word(c, open_token);
Expand Down Expand Up @@ -2988,8 +2994,8 @@ Tokenizer.prototype._read_open_handlebars = function(c, open_token) {
var resulting_string = null;
var token = null;
if (!open_token || open_token.type === TOKEN.CONTROL_FLOW_OPEN) {
if (this._options.indent_handlebars && c === '{' && this._input.peek(1) === '{') {
if (this._input.peek(2) === '!') {
if ((this._options.templating.includes('angular') || this._options.indent_handlebars) && c === '{' && this._input.peek(1) === '{') {
if (this._options.indent_handlebars && this._input.peek(2) === '!') {
resulting_string = this.__patterns.handlebars_comment.read();
resulting_string = resulting_string || this.__patterns.handlebars.read();
token = this._create_token(TOKEN.COMMENT, resulting_string);
Expand All @@ -3005,8 +3011,8 @@ Tokenizer.prototype._read_open_handlebars = function(c, open_token) {
Tokenizer.prototype._read_control_flows = function(c, open_token) {
var resulting_string = '';
var token = null;
// Only check for control flows if angular templating is set AND indenting is set
if (!this._options.templating.includes('angular') || !this._options.indent_handlebars) {
// Only check for control flows if angular templating is set
if (!this._options.templating.includes('angular')) {
return token;
}

Expand Down Expand Up @@ -3099,14 +3105,29 @@ Tokenizer.prototype._is_content_unformatted = function(tag_name) {
this._options.unformatted.indexOf(tag_name) !== -1);
};


Tokenizer.prototype._read_raw_content = function(c, previous_token, open_token) { // jshint unused:false
var resulting_string = '';
if (open_token && open_token.text[0] === '{') {
resulting_string = this.__patterns.handlebars_raw_close.read();
} else if (previous_token.type === TOKEN.TAG_CLOSE &&
previous_token.opened.text[0] === '<' && previous_token.text[0] !== '/') {
// ^^ empty tag has no content
var tag_name = previous_token.opened.text.substr(1).toLowerCase();
if (this._is_content_unformatted(tag_name)) {

resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
}
}

if (resulting_string) {
return this._create_token(TOKEN.TEXT, resulting_string);
}

return null;
};

Tokenizer.prototype._read_script_and_style = function(c, previous_token) { // jshint unused:false
if (previous_token.type === TOKEN.TAG_CLOSE && previous_token.opened.text[0] === '<' && previous_token.text[0] !== '/') {
var tag_name = previous_token.opened.text.substr(1).toLowerCase();
if (tag_name === 'script' || tag_name === 'style') {
// Script and style tags are allowed to have comments wrapping their content
Expand All @@ -3116,17 +3137,12 @@ Tokenizer.prototype._read_raw_content = function(c, previous_token, open_token)
token.type = TOKEN.TEXT;
return token;
}
resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
} else if (this._is_content_unformatted(tag_name)) {

resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
var resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
if (resulting_string) {
return this._create_token(TOKEN.TEXT, resulting_string);
}
}
}

if (resulting_string) {
return this._create_token(TOKEN.TEXT, resulting_string);
}

return null;
};

Expand All @@ -3144,6 +3160,7 @@ Tokenizer.prototype._read_content_word = function(c, open_token) {
if (resulting_string) {
return this._create_token(TOKEN.TEXT, resulting_string);
}
return null;
};

module.exports.Tokenizer = Tokenizer;
Expand Down
Loading