Skip to content

Commit

Permalink
Merge pull request #21 from ubermanu/feat/keep-knockout-comments
Browse files Browse the repository at this point in the history
feat: keep knockout comments
  • Loading branch information
abordage committed Feb 28, 2024
2 parents 2e2d9a3 + a96c131 commit 8b9bd09
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/HtmlMin.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected function doctypeNotFound(string $html): bool

protected function removeHtmlComments(string $html): string
{
return (string)preg_replace('~<!--[^]><!\[](?!Livewire)(.*?)[^]]-->~s', '', $html);
return (string)preg_replace('~<!--[^]><!\[](?!Livewire|ko |/ko)(.*?)[^]]-->~s', '', $html);
}

protected function trimScriptElements(string $html): string
Expand Down
14 changes: 14 additions & 0 deletions tests/HtmlMinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ public function testLivewire(): void
$this->assertEquals($expected, $this->htmlMin->minify($html));
}

public function testKnockout(): void
{
$html = "<div>
<!-- ko if: true -->
<span>First item</span>
<!-- /ko -->
<!-- ko template: getTemplate() --><!-- /ko -->
</div>";
$expected = "<div><!-- ko if: true --><span>First item</span><!-- /ko --><!-- ko template: getTemplate() --><!-- /ko --></div>";
$this->assertEquals($expected, $this->htmlMin->minify($html));
}

public function testStyleTag(): void
{
$html = "<style>
Expand Down

0 comments on commit 8b9bd09

Please sign in to comment.