From d5176ef294b4a90d0d2984441362632832e88e28 Mon Sep 17 00:00:00 2001 From: Gergely Gyorgy Both Date: Fri, 29 Mar 2024 22:08:35 +0100 Subject: [PATCH 1/3] Fixed #2260 - ' - // ] - input: [ + unchanged: [ '' - ], - output: [ + ] + }, { + comment: 'CSS @media, the inside of ', + '', + '', + '
', + '@if(someOtherExpression) {', + 'Text', + '}', + '
', + '' + ], + output: [ + '', + ' ', + ' ', + '', + '', + '
', + ' @if(someOtherExpression) {', + ' Text', + ' }', + '
', + '' ] }] }, { - name: "No indenting for angular control flow should be done if indent_handlebars is false", + name: "No indenting for angular control flow should be done if angular templating is not set", description: "https://github.com/beautify-web/js-beautify/issues/2219", template: "^^^ $$$", - options: [ - { name: "templating", value: "'angular, handlebars'" }, - { name: "indent_handlebars", value: "false" } - ], tests: [{ unchanged: [ '@if (a > b) {', From 18a518a89a89729585a3304fb9a7173fa6696258 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Sat, 27 Apr 2024 12:01:55 -0700 Subject: [PATCH 2/3] Update templatablepattern.js --- js/src/core/templatablepattern.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/js/src/core/templatablepattern.js b/js/src/core/templatablepattern.js index 047305e7d..6d6f1c9da 100644 --- a/js/src/core/templatablepattern.js +++ b/js/src/core/templatablepattern.js @@ -132,8 +132,11 @@ TemplatablePattern.prototype.__set_templated_pattern = function() { if (!this._disabled.php) { items.push(this.__patterns.php._starting_pattern.source); } - // Handlebars ('{{' and '}}') are also special tokens in Angular) - if (!this._disabled.handlebars || !this._disabled.angular) { + 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) { From 7d8f600a84f25cccbf84195e52d1c0af703cf93a Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Sat, 27 Apr 2024 12:06:51 -0700 Subject: [PATCH 3/3] Update tokenizer.js --- js/src/html/tokenizer.js | 41 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/js/src/html/tokenizer.js b/js/src/html/tokenizer.js index 1d918e8b8..11aadf146 100644 --- a/js/src/html/tokenizer.js +++ b/js/src/html/tokenizer.js @@ -327,27 +327,6 @@ Tokenizer.prototype._is_content_unformatted = function(tag_name) { this._options.unformatted.indexOf(tag_name) !== -1); }; - -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 - // or just have regular content. - var token = this._read_comment_or_cdata(c); - if (token) { - token.type = TOKEN.TEXT; - return token; - } - var resulting_string = this._input.readUntil(new RegExp('', 'ig')); - if (resulting_string) { - return this._create_token(TOKEN.TEXT, resulting_string); - } - } - } - return null; -}; - Tokenizer.prototype._read_raw_content = function(c, previous_token, open_token) { // jshint unused:false var resulting_string = ''; if (open_token && open_token.text[0] === '{') { @@ -369,6 +348,26 @@ Tokenizer.prototype._read_raw_content = function(c, previous_token, open_token) 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 + // or just have regular content. + var token = this._read_comment_or_cdata(c); + if (token) { + token.type = TOKEN.TEXT; + return token; + } + var resulting_string = this._input.readUntil(new RegExp('', 'ig')); + if (resulting_string) { + return this._create_token(TOKEN.TEXT, resulting_string); + } + } + } + return null; +}; + Tokenizer.prototype._read_content_word = function(c, open_token) { var resulting_string = ''; if (this._options.unformatted_content_delimiter) {