Skip to content

Commit

Permalink
fix: 馃悰 multiple directive in html tag gets unexpected format
Browse files Browse the repository at this point in the history
  • Loading branch information
shufo committed Feb 13, 2022
1 parent 905eaad commit 7f68515
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export default class Formatter {
return _.replace(content, /(?<!@)@php(.*?)@endphp/gs, (match: any, p1: any) => this.storeRawBlock(p1));
}

async preserveInlineDirective(content: any) {
preserveInlineDirective(content: string): string {
// preserve inline directives inside html tag
const regex = new RegExp(
`(<[\\w]+?[^>]*?)(${indentStartTokens.join(
Expand All @@ -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,
Expand All @@ -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) {
Expand Down

0 comments on commit 7f68515

Please sign in to comment.