|
@@ -10,6 +10,7 @@ module.exports = [
|
|
|
(body) => {
|
|
(body) => {
|
|
|
const lines = body.split('\n');
|
|
const lines = body.split('\n');
|
|
|
const directivePattern = /\$[\w-]+\([^)]*\)/;
|
|
const directivePattern = /\$[\w-]+\([^)]*\)/;
|
|
|
|
|
+ let lastDirectiveLineIndex = -1;
|
|
|
|
|
|
|
|
for (let i = 0; i < lines.length; i++) {
|
|
for (let i = 0; i < lines.length; i++) {
|
|
|
if (directivePattern.test(lines[i])) {
|
|
if (directivePattern.test(lines[i])) {
|
|
@@ -20,12 +21,21 @@ module.exports = [
|
|
|
// Always remove indentation from directive line
|
|
// Always remove indentation from directive line
|
|
|
lines[i] = currentLine.trimStart();
|
|
lines[i] = currentLine.trimStart();
|
|
|
|
|
|
|
|
- // Insert empty line if previous line ends with HTML tag
|
|
|
|
|
- if (prevLine.match(/>[^\n]*$/) && prevLine.trim() !== '') {
|
|
|
|
|
|
|
+ // Insert empty line only if:
|
|
|
|
|
+ // 1. Previous line contains an HTML tag (ends with >)
|
|
|
|
|
+ // 2. Previous line is not empty
|
|
|
|
|
+ // 3. Previous line is not a directive line
|
|
|
|
|
+ const isPrevLineHtmlTag = prevLine.match(/>[^\n]*$/) && !prevLine.match(directivePattern);
|
|
|
|
|
+ const isNotAfterDirective = i - 1 !== lastDirectiveLineIndex;
|
|
|
|
|
+
|
|
|
|
|
+ if (isPrevLineHtmlTag && prevLine.trim() !== '' && isNotAfterDirective) {
|
|
|
lines.splice(i, 0, '');
|
|
lines.splice(i, 0, '');
|
|
|
i++;
|
|
i++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // Update the last directive line index
|
|
|
|
|
+ lastDirectiveLineIndex = i;
|
|
|
|
|
+
|
|
|
// Handle next line if it's a closing tag
|
|
// Handle next line if it's a closing tag
|
|
|
if (nextLine.match(/^\s*<\//)) {
|
|
if (nextLine.match(/^\s*<\//)) {
|
|
|
lines[i + 1] = nextLine.trimStart();
|
|
lines[i + 1] = nextLine.trimStart();
|