From 7f6851537b7788f7346abbb3085b2fd1ad3a71b2 Mon Sep 17 00:00:00 2001 From: shufo Date: Sun, 13 Feb 2022 15:20:01 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20multiple=20directive=20in?= =?UTF-8?q?=20html=20tag=20gets=20unexpected=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/formatter.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/formatter.ts b/src/formatter.ts index 35330aa9..ed32cd78 100644 --- a/src/formatter.ts +++ b/src/formatter.ts @@ -205,7 +205,7 @@ export default class Formatter { return _.replace(content, /(? this.storeRawBlock(p1)); } - async preserveInlineDirective(content: any) { + preserveInlineDirective(content: string): string { // preserve inline directives inside html tag const regex = new RegExp( `(<[\\w]+?[^>]*?)(${indentStartTokens.join( @@ -214,11 +214,11 @@ export default class Formatter { )})(\\s*?)(${nestedParenthesisRegex})(.*?)(${indentEndTokens.join('|')})(.*?>)`, 'gims', ); - return _.replace( + const replaced = _.replace( content, regex, ( - match: string, + _match: string, p1: string, p2: string, p3: string, @@ -231,6 +231,12 @@ export default class Formatter { return `${p1}${this.storeInlineDirective(`${p2.trim()}${p3}${p4.trim()} ${p6.trim()} ${p7.trim()}`)}${p8}`; }, ); + + if (regex.test(replaced)) { + return this.preserveInlineDirective(replaced); + } + + return replaced; } async preserveInlinePhpDirective(content: any) {