|
28 | 28 | if (str_ends_with($file, ".phtml")) { |
29 | 29 | $content = preg_replace_callback_array( |
30 | 30 | [ |
31 | | - '/(^|[^\?])>(\s*)(([^<]|(?=<\?php\s+e\(.*\);\s*\?>)<)+)(\s*)</m' => function ($matches) { |
32 | | - if (!trim($matches[3]) || str_starts_with($matches[3], '<?php e(')) { |
| 31 | + '/(^|[^\?])>(([^<]|(?=<\?php\s+e\(.*\);\s*\?>)<)+)</s' => function ($matches) { |
| 32 | + if (!trim($matches[2]) || str_starts_with(trim($matches[2]), '<?php e(')) { |
33 | 33 | return $matches[0]; |
34 | 34 | } |
35 | | - $string = $matches[3]; |
| 35 | + $string = $matches[2]; |
| 36 | + $leadingWhite = ''; |
| 37 | + $trailingWhite = ''; |
| 38 | + if (preg_match('/^(\s*)(.*?)(\s*)$/s', $string, $whiteMatches)) { |
| 39 | + $leadingWhite = $whiteMatches[1]; |
| 40 | + $string = $whiteMatches[2]; |
| 41 | + $trailingWhite = $whiteMatches[3]; |
| 42 | + } |
36 | 43 | $args = []; |
37 | 44 | $string = preg_replace_callback_array( |
38 | 45 | [ |
|
44 | 51 | $string |
45 | 52 | ); |
46 | 53 | if ($args) { |
47 | | - return $matches[1] . '>' . $matches[2] . '<?php e(t("' . str_replace('\"', "'", addslashes($string)) . '", ' . implode(',', $args) . ')); ?>' . $matches[5] . '<'; |
| 54 | + return $matches[1] . '>' . $leadingWhite . '<?php e(t("' . str_replace('\"', "'", addslashes(preg_replace('/\s+/', ' ', $string))) . '", ' . implode(',', $args) . ')); ?>' . $trailingWhite . '<'; |
48 | 55 | } |
49 | | - return $matches[1] . '>' . $matches[2] . '<?php e(t("' . str_replace('\"', "'", addslashes($string)) . '")); ?>' . $matches[5] . '<'; |
| 56 | + return $matches[1] . '>' . $leadingWhite . '<?php e(t("' . str_replace('\"', "'", addslashes(preg_replace('/\s+/', ' ', $string))) . '")); ?>' . $trailingWhite . '<'; |
50 | 57 | }, |
51 | | - '/((alt|title|placeholder)="(.*?)")/m' => function ($matches) { |
| 58 | + '/((alt|title|placeholder)="(.*?)")/s' => function ($matches) { |
52 | 59 | if (!trim($matches[3]) || str_starts_with($matches[3], '<?php e(')) { |
53 | 60 | return $matches[0]; |
54 | 61 | } |
|
61 | 68 | if (str_ends_with($file, ".php")) { |
62 | 69 | $content = preg_replace_callback_array( |
63 | 70 | [ |
64 | | - '/error[^=]+=[^"](".*?")/m' => function ($matches) { |
| 71 | + '/error[^=]+=[^"](".*?")/s' => function ($matches) { |
65 | 72 | return str_replace($matches[1], 't(' . $matches[1] . ')', $matches[0]); |
66 | 73 | }, |
67 | 74 | ], |
|
0 commit comments