From cecb9dab4feb5848eb6c6e8351cfc6a6862fb970 Mon Sep 17 00:00:00 2001 From: Connor Thomson Date: Sun, 20 Sep 2026 17:39:36 -0700 Subject: Add a preprocessor --- php/replace.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'php/replace.php') 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 . */ +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); } ?> -- cgit v1.2.3