Skip to content

Commit

Permalink
Add support for PureContent
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek committed Mar 27, 2021
1 parent a0491ea commit 607fd47
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/ContentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@ function (array $match) use (&$items): string {
$html,
);
$title = null;
if (preg_match('/<h1>([^<]+)<\/h1>/', $html, $htmlTitleParser)) {
$title = strip_tags(trim($htmlTitleParser[1] ?? ''));
$pureContent = null;
if (preg_match('/^((?:.|\n)*)<h1>([^<]+)<\/h1>((?:.|\n)*)$/', $content, $htmlTitleParser)) {
$title = strip_tags(trim($htmlTitleParser[2] ?? ''));
$pureContent = trim($htmlTitleParser[1] ?? '') . trim($htmlTitleParser[3] ?? '');
}
$perex = null;
if (preg_match('/<p>([^<]+)<\/p>/', $html, $htmlPerexParser)) {
if (preg_match('/<p>([^<]+)<\/p>/', $content, $htmlPerexParser)) {
$perex = strip_tags(trim($htmlPerexParser[1] ?? ''));
}

return new Response(
$html,
$content,
$pureContent ?? $content,
$title,
$perex,
$items,
Expand Down
7 changes: 7 additions & 0 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ final class Response
public function __construct(
private string $original,
private string $content,
private string $pureContent,
private ?string $title,
private ?string $perex,
private array $items,
Expand Down Expand Up @@ -41,6 +42,12 @@ public function getContent(): string
}


public function getPureContent(): string
{
return $this->pureContent;
}


public function getTitle(): ?string
{
return $this->title;
Expand Down

0 comments on commit 607fd47

Please sign in to comment.