Upgrade to 4.0.0

This commit is contained in:
Bastian Allgeier
2023-11-28 09:33:56 +01:00
parent f96b96af76
commit 3b0b6546ca
480 changed files with 21371 additions and 13327 deletions

View File

@@ -23,8 +23,7 @@ class Blocks extends Plain
{
public function blockquote(Element $node): array
{
$citation = null;
$text = [];
$text = [];
// get all the text for the quote
foreach ($node->children() as $child) {
@@ -36,7 +35,8 @@ class Blocks extends Plain
$child instanceof DOMElement &&
$child->tagName !== 'footer'
) {
$text[] = (new Element($child))->innerHTML($this->marks());
$element = new Element($child);
$text[] = $element->innerHTML($this->marks());
}
}
@@ -44,9 +44,7 @@ class Blocks extends Plain
$text = implode('', array_filter($text));
// get the citation from the footer
if ($footer = $node->find('footer')) {
$citation = $footer->innerHTML($this->marks());
}
$citation = $node->find('footer')?->innerHTML($this->marks());
return [
'content' => [
@@ -115,15 +113,12 @@ class Blocks extends Plain
public function iframe(Element $node): array
{
$caption = null;
$src = $node->attr('src');
$src = $node->attr('src');
$figcaption = $node->find('ancestor::figure[1]//figcaption');
$caption = $figcaption?->innerHTML($this->marks());
if ($figcaption = $node->find('ancestor::figure[1]//figcaption')) {
$caption = $figcaption->innerHTML($this->marks());
// avoid parsing the caption twice
$figcaption->remove();
}
// avoid parsing the caption twice
$figcaption?->remove();
// reverse engineer video URLs
if (preg_match('!player.vimeo.com\/video\/([0-9]+)!i', $src, $array) === 1) {
@@ -157,19 +152,12 @@ class Blocks extends Plain
public function img(Element $node): array
{
$caption = null;
$link = null;
$link = $node->find('ancestor::a')?->attr('href');
$figcaption = $node->find('ancestor::figure[1]//figcaption');
$caption = $figcaption?->innerHTML($this->marks());
if ($figcaption = $node->find('ancestor::figure[1]//figcaption')) {
$caption = $figcaption->innerHTML($this->marks());
// avoid parsing the caption twice
$figcaption->remove();
}
if ($a = $node->find('ancestor::a')) {
$link = $a->attr('href');
}
// avoid parsing the caption twice
$figcaption?->remove();
return [
'content' => [
@@ -198,19 +186,21 @@ class Blocks extends Plain
$innerHtml .= $child->textContent;
} elseif ($child instanceof DOMElement) {
$child = new Element($child);
if (in_array($child->tagName(), ['ul', 'ol']) === true) {
$innerHtml .= $this->list($child);
} else {
$innerHtml .= $child->innerHTML($this->marks());
}
$list = ['ul', 'ol'];
$innerHtml .= match (in_array($child->tagName(), $list)) {
true => $this->list($child),
default => $child->innerHTML($this->marks())
};
}
}
$html[] = '<li>' . trim($innerHtml) . '</li>';
}
return '<' . $node->tagName() . '>' . implode($html) . '</' . $node->tagName() . '>';
$outerHtml = '<' . $node->tagName() . '>';
$outerHtml .= implode($html);
$outerHtml .= '</' . $node->tagName() . '>';
return $outerHtml;
}
/**