diff options
| author | Connor Thomson <blumatrikz@gmail.com> | 2026-09-20 17:39:36 -0700 |
|---|---|---|
| committer | Connor Thomson <blumatrikz@gmail.com> | 2026-09-20 17:39:36 -0700 |
| commit | cecb9dab4feb5848eb6c6e8351cfc6a6862fb970 (patch) | |
| tree | da584b646e036f691a2a0bb208b8b6d63aa4f7f1 /php/replace.php | |
| parent | fcff9dc07a06912821e6a481d233b92cc55bfdcd (diff) | |
Add a preprocessor
Diffstat (limited to 'php/replace.php')
| -rwxr-xr-x | php/replace.php | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/php/replace.php b/php/replace.php index 9cdc5bf..dcc5fb6 100755 --- a/php/replace.php +++ b/php/replace.php @@ -17,14 +17,24 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ +require_once ROOT . '/php/preprocess.php'; + function replace(string $templatePath, array $replacements = []): string { - $html = file_get_contents($templatePath); + $html = import($templatePath); foreach ($replacements as $placeholder => $replacementValue) { + $replacementValue = tidy((string)$replacementValue); + + $pattern = '/^([ \t]*)' . preg_quote($placeholder, '/') . '/m'; + + $html = preg_replace_callback($pattern, function (array $match) use ($replacementValue) { + return indent($replacementValue, $match[1]); + }, $html); + $html = str_replace($placeholder, $replacementValue, $html); } - return $html; + return tidy($html); } ?> |
