Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Jul 17, 2019
2 parents f2815f2 + c9ae202 commit 481a9ac
Show file tree
Hide file tree
Showing 9 changed files with 513 additions and 1,441 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![Join the chat at https://gitter.im/beautify-web/js-beautify](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/beautify-web/js-beautify?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Twitter Follow](https://img.shields.io/twitter/follow/js_beautifier.svg?style=social&label=Follow)](https://twitter.com/intent/user?screen_name=js_beautifier)

[![NPM stats](https://nodei.co/npm/js-beautify.svg?downloadRank=true&downloads=true)](https://www.npmjs.org/package/js-beautify)
[![NPM stats](https://nodei.co/npm/js-beautify.svg?downloadRank=true&downloads=true)](https://www.npmjs.org/package/js-beautify) [![Greenkeeper badge](https://badges.greenkeeper.io/beautify-web/js-beautify.svg)](https://greenkeeper.io/)


This little beautifier will reformat and re-indent bookmarklets, ugly
Expand Down Expand Up @@ -61,17 +61,17 @@ 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.10.0/beautify.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.10.0/beautify-css.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.10.0/beautify-html.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.10.1-rc1/beautify.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.10.1-rc1/beautify-css.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.10.1-rc1/beautify-html.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.10.0/beautify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.10.0/beautify-css.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.10.0/beautify-html.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.10.1-rc1/beautify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.10.1-rc1/beautify-css.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.10.1-rc1/beautify-html.min.js"></script>

<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.10.0/js/lib/beautify.js"></script>
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.10.0/js/lib/beautify-css.js"></script>
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.10.0/js/lib/beautify-html.js"></script>
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.10.1-rc1/js/lib/beautify.js"></script>
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.10.1-rc1/js/lib/beautify-css.js"></script>
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.10.1-rc1/js/lib/beautify-html.js"></script>
```

Older versions are available by changing the version number.
Expand All @@ -93,7 +93,7 @@ You can beautify javascript using JS Beautifier in your web browser, or on the c
## Web Browser
Open [beautifier.io](https://beautifier.io/). Options are available via the UI.

## Web Libary
## Web Library
The script tags above expose three functions: `js_beautify`, `css_beautify`, and `html_beautify`.

## Node.js JavaScript
Expand Down Expand Up @@ -399,4 +399,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: [email protected].0)
(README.md: [email protected].1-rc1)
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ <h1>Online JavaScript Beautifier <span id="version-number"></span></h1>
</div>

<p id="open-issue" hidden>Not pretty enough for you?
<button type="button" onclick="submitIssue()" name="issue-button">Report an issue</button>
<button type="button" onclick="submitIssue()" name="issue-button">Report a problem with this input</button>
</p>

<div class="blurb">
Expand Down
37 changes: 28 additions & 9 deletions js/src/html/tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var Tokenizer = function(input_string, options) {
handlebars_open: pattern_reader.until(/[\n\r\t }]/),
handlebars_raw_close: pattern_reader.until(/}}/),
comment: pattern_reader.starting_with(/<!--/).until_after(/-->/),
cdata: pattern_reader.starting_with(/<!\[cdata\[/).until_after(/]]>/),
cdata: pattern_reader.starting_with(/<!\[CDATA\[/).until_after(/]]>/),
// https://en.wikipedia.org/wiki/Conditional_comment
conditional_comment: pattern_reader.starting_with(/<!\[/).until_after(/]>/),
processing: pattern_reader.starting_with(/<\?/).until_after(/\?>/)
Expand Down Expand Up @@ -125,24 +125,24 @@ Tokenizer.prototype._get_next_token = function(previous_token, open_token) { //
token = token || this._read_raw_content(c, previous_token, open_token);
token = token || this._read_close(c, open_token);
token = token || this._read_content_word(c);
token = token || this._read_comment(c);
token = token || this._read_comment_or_cdata(c);
token = token || this._read_processing(c);
token = token || this._read_open(c, open_token);
token = token || this._create_token(TOKEN.UNKNOWN, this._input.next());

return token;
};

Tokenizer.prototype._read_comment = function(c) { // jshint unused:false
Tokenizer.prototype._read_comment_or_cdata = function(c) { // jshint unused:false
var token = null;
var resulting_string = null;
var directives = null;

if (c === '<') {
var peek1 = this._input.peek(1);
//if we're in a comment, do something special
// We treat all comments as literals, even more than preformatted tags
// we just look for the appropriate close tag
if (c === '<' && (peek1 === '!' || peek1 === '?')) {
// we only look for the appropriate closing marker
if (peek1 === '!') {
resulting_string = this.__patterns.comment.read();

// only process directive on html comments
Expand All @@ -153,8 +153,6 @@ Tokenizer.prototype._read_comment = function(c) { // jshint unused:false
}
} else {
resulting_string = this.__patterns.cdata.read();
resulting_string = resulting_string || this.__patterns.conditional_comment.read();
resulting_string = resulting_string || this.__patterns.processing.read();
}
}

Expand All @@ -167,6 +165,27 @@ Tokenizer.prototype._read_comment = function(c) { // jshint unused:false
return token;
};

Tokenizer.prototype._read_processing = function(c) { // jshint unused:false
var token = null;
var resulting_string = null;
var directives = null;

if (c === '<') {
var peek1 = this._input.peek(1);
if (peek1 === '!' || peek1 === '?') {
resulting_string = this.__patterns.conditional_comment.read();
resulting_string = resulting_string || this.__patterns.processing.read();
}

if (resulting_string) {
token = this._create_token(TOKEN.COMMENT, resulting_string);
token.directives = directives;
}
}

return token;
};

Tokenizer.prototype._read_open = function(c, open_token) {
var resulting_string = null;
var token = null;
Expand Down Expand Up @@ -272,7 +291,7 @@ Tokenizer.prototype._read_raw_content = function(c, previous_token, open_token)
if (tag_name === 'script' || tag_name === 'style') {
// Script and style tags are allowed to have comments wrapping their content
// or just have regular content.
var token = this._read_comment(c);
var token = this._read_comment_or_cdata(c);
if (token) {
token.type = TOKEN.TEXT;
return token;
Expand Down
21 changes: 21 additions & 0 deletions js/test/generated/beautify-html-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
// Tests for script and style Commented and cdata wapping (#1641)
reset_options();
set_name('Tests for script and style Commented and cdata wapping (#1641)');
opts.templating = 'php';
bth(
'<style><!----></style>',
// -- output --
Expand Down Expand Up @@ -565,6 +566,26 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
' console.log("</script>" + "</style>");\n' +
' ]]>\n' +
'</script>');

// Issue #1687 - start with <?php ?>
bth(
'<script>\n' +
'<?php ?>\n' +
'var b={\n' +
'a:function _test( ){\n' +
'return 1;\n' +
'}\n' +
'}\n' +
'</script>',
// -- output --
'<script>\n' +
' <?php ?>\n' +
' var b = {\n' +
' a: function _test() {\n' +
' return 1;\n' +
' }\n' +
' }\n' +
'</script>');


//============================================================
Expand Down
Loading

0 comments on commit 481a9ac

Please sign in to comment.