Skip to content

Commit

Permalink
Trim empty class directives
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Dec 5, 2024
1 parent 4fb8e57 commit f9f9755
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function canAddPermalink(string $content, int $level): bool
/** @internal */
public function postProcess(string $html): string
{
$html = str_replace('class=""', '', $html);
$html = preg_replace('/<h([1-6]) >/', '<h$1>', $html);

return implode('', array_map('trim', explode("\n", $html)));
Expand Down
7 changes: 7 additions & 0 deletions packages/framework/tests/Unit/HeadingRendererUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ public function testPostProcessTrimsWhitespaceAndIndentationFromLines()
$this->assertSame('<h1>Title</h1><h2>Subtitle</h2>', (new HeadingRenderer())->postProcess($html));
}

public function testPostProcessTrimsEmptyClassAttributes()
{
$html = '<h1 class="">Title</h1>';

$this->assertSame('<h1>Title</h1>', (new HeadingRenderer())->postProcess($html));
}

public function testPostProcessHandlesEmptyString()
{
$html = '';
Expand Down

0 comments on commit f9f9755

Please sign in to comment.