From 327974622397f2b868cd49ccf2960ccf62ee76e1 Mon Sep 17 00:00:00 2001 From: Miraty Date: Wed, 1 Jun 2022 19:36:07 +0200 Subject: [PATCH] Tidy HTML --- mkht.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/mkht.php b/mkht.php index 3684c24..147cb4f 100755 --- a/mkht.php +++ b/mkht.php @@ -219,8 +219,25 @@ foreach ($pages as $page) { require SITE . "/end.inc.html"; echo ""; - file_put_contents($pathParts['dirname'] . "/" . $pathParts['filename'] . ".html", ob_get_contents()); - ob_end_clean(); + $pageContent = ob_get_clean(); + + if (extension_loaded("tidy")) { + $tidy = new tidy; + $tidy->parseString( + $pageContent, + array( + 'indent' => true, + 'keep-tabs' => true, + 'wrap' => 0 + ) + ); + $tidy->cleanRepair(); + $pageContent = tidy_get_output($tidy); + } else { + echo "tidy extension unavailable\n"; + } + + file_put_contents($pathParts['dirname'] . "/" . $pathParts['filename'] . ".html", $pageContent); // Gzip compression exec(GZIP . " --keep --fast --force " . $pathParts['dirname'] . "/" . $pathParts['filename'] . ".html");