|
|
@@ -4,33 +4,27 @@
|
|
|
|
|
|
module.exports = [
|
|
|
/**
|
|
|
- * Adjust line breaks and indentation for $lsx() within HTML tags
|
|
|
+ * Adjust line breaks and indentation for any directives within HTML tags
|
|
|
* @type {MigrationModule}
|
|
|
*/
|
|
|
(body) => {
|
|
|
- // Split into lines for better processing
|
|
|
const lines = body.split('\n');
|
|
|
+ const directivePattern = /\$[\w-]+\([^)]*\)/;
|
|
|
|
|
|
for (let i = 0; i < lines.length; i++) {
|
|
|
- // Find lines containing $lsx()
|
|
|
- if (lines[i].includes('$lsx(')) {
|
|
|
+ if (directivePattern.test(lines[i])) {
|
|
|
const currentLine = lines[i];
|
|
|
const prevLine = i > 0 ? lines[i - 1] : '';
|
|
|
const nextLine = i < lines.length - 1 ? lines[i + 1] : '';
|
|
|
|
|
|
- // Remove indentation from current line
|
|
|
lines[i] = currentLine.trimStart();
|
|
|
|
|
|
- // If previous line contains an HTML tag and is not an empty line
|
|
|
if (prevLine.includes('>') && prevLine.trim() !== '') {
|
|
|
- // Insert empty line
|
|
|
lines.splice(i, 0, '');
|
|
|
- i++; // Adjust index after insertion
|
|
|
+ i++;
|
|
|
}
|
|
|
|
|
|
- // If next line contains an HTML tag
|
|
|
if (nextLine.includes('</')) {
|
|
|
- // Handle next line (remove indentation)
|
|
|
lines[i + 1] = nextLine.trimStart();
|
|
|
}
|
|
|
}
|
|
|
@@ -40,13 +34,14 @@ module.exports = [
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
- * Remove unnecessary parentheses in $lsx() filter arguments
|
|
|
+ * Remove unnecessary parentheses in directive arguments
|
|
|
* @type {MigrationModule}
|
|
|
*/
|
|
|
(body) => {
|
|
|
- return body.replace(/\$lsx\([^)]*\)/g, (match) => {
|
|
|
- // Find and remove parentheses in filter=(...) pattern
|
|
|
- return match.replace(/filter=\(([^)]+)\)/g, 'filter=$1');
|
|
|
+ return body.replace(/\$[\w-]+\([^)]*\)/g, (match) => {
|
|
|
+ return match
|
|
|
+ .replace(/filter=\(([^)]+)\)/g, 'filter=$1')
|
|
|
+ .replace(/except=\(([^)]+)\)/g, 'except=$1');
|
|
|
});
|
|
|
},
|
|
|
];
|