From 63c9ffa11c397044293310b161c1ea116fe1195f Mon Sep 17 00:00:00 2001 From: avento Date: Fri, 15 Apr 2022 13:14:34 -0400 Subject: [PATCH] solution to partials not seperated by spaces --- js/src/html/beautifier.js | 6 +++++ test/data/html/tests.js | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/js/src/html/beautifier.js b/js/src/html/beautifier.js index 8e47a114..ae6c16fc 100644 --- a/js/src/html/beautifier.js +++ b/js/src/html/beautifier.js @@ -608,11 +608,17 @@ var TagOpenParserToken = function(parent, raw_token) { this.tag_check = tag_check_match ? tag_check_match[1] : ''; } else { tag_check_match = raw_token.text.match(/^{{~?(?:[\^]|#\*?)?([^\s}]+)/); + this.tag_check = tag_check_match ? tag_check_match[1] : ''; // handle "{{#> myPartial}}" or "{{~#> myPartial}}" if ((raw_token.text === '{{#>' || raw_token.text === '{{~#>') && this.tag_check === '>' && raw_token.next !== null) { this.tag_check = raw_token.next.text.split(' ')[0]; + } else { + // handle "{{#>myPartial}}" or "{{~#>myPartial}}" + if (raw_token.text.slice(0, 4) === ('{{#>') || raw_token.text.slice(0, 5) === ('{{~#>') && this.tag_check[0] === '>') { + this.tag_check = raw_token.text.split('>')[1]; + } } } this.tag_check = this.tag_check.toLowerCase(); diff --git a/test/data/html/tests.js b/test/data/html/tests.js index 03614c96..1421f35b 100644 --- a/test/data/html/tests.js +++ b/test/data/html/tests.js @@ -3591,6 +3591,60 @@ exports.test_data = { '{{/if}}' ] }] + }, { + name: "Handle Partials Not Seperated by Spaces", + description: "Handles partials that do not have a space before the tag", + template: "^^^ $$$", + options: [ + { name: "nospace_partials", value: "true" } + ], + tests: [{ + input: [ + '{{#>row}}', + ' {{#>column}}', + ' content', + ' {{/column}}', + ' {{/row}}' + ], + output: [ + '{{#>row}}', + ' {{#>column}}', + ' content', + ' {{/column}}', + '{{/row}}' + ] + }, { + input: [ + '{{~#>row}}', + '{{#>column}}', + '

content

', + '{{/column}}', + '{{/row}}' + ], + output: [ + '{{~#>row}}', + ' {{#>column}}', + '

content

', + ' {{/column}}', + '{{/row}}' + ] + }, { + unchanged: [ + '{{#>row}}', + ' {{#>column}}', + ' content', + ' {{/column}}', + '{{/row}}' + ] + }, { + unchanged: [ + '{{#> row}}', + ' {{#> column}}', + ' content', + ' {{/column}}', + '{{/row}}' + ] + }] }, { name: "New Test Suite" }]