summaryrefslogtreecommitdiff
path: root/php/replace.php
diff options
context:
space:
mode:
Diffstat (limited to 'php/replace.php')
-rwxr-xr-xphp/replace.php14
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);
}
?>