Skip to content

Commit

Permalink
Merge pull request #195 from c0nst4ntin/152-richtextastext-only-inclu…
Browse files Browse the repository at this point in the history
…de-newline-when-there-are-multiple-blocks

fix (#152): remove last new line from rich text blocks
  • Loading branch information
c0nst4ntin authored Nov 22, 2022
2 parents 29cd0d7 + ecbffbf commit 94709c5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Prismic/Dom/RichText.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function asText($richText)
}
}

return $result;
return trim($result);
}

/**
Expand Down
26 changes: 23 additions & 3 deletions tests/Prismic/Dom/RichTextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,29 @@ protected function setUp(): void

public function testAsText()
{
$expected = "The title\n";
$actual = RichText::asText($this->richText->title);
$this->assertEquals($expected, $actual);
$expected = (
"Heading 1\n".
"Heading 2\n".
"Heading 3\n".
"Heading 4\n".
"Heading 5\n".
"Heading 6\n".
"Paragraph em and strong\n".
"Paragraph Web link and media link\n".
"Preformatted block\n".
"Help\n".
"Revolver\n".
"Abbey Road\n".
"John\n".
"Paul\n".
"George\n".
"Ringo"
);

$this->assertEquals($expected, RichText::asText($this->richText->description));
$this->assertEquals($expected, RichText::asText($this->richText->description, $this->linkResolver));

$this->assertStringEndsNotWith("\n", RichText::asText($this->richText->description));
}

public function testAsHtml()
Expand Down

0 comments on commit 94709c5

Please sign in to comment.