Upgrade to 3.8.0
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Kirby\Parsley\Schema;
|
||||
|
||||
use DOMElement;
|
||||
use DOMText;
|
||||
use Kirby\Parsley\Element;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
@@ -19,10 +21,6 @@ use Kirby\Toolkit\Str;
|
||||
*/
|
||||
class Blocks extends Plain
|
||||
{
|
||||
/**
|
||||
* @param \Kirby\Parsley\Element $node
|
||||
* @return array
|
||||
*/
|
||||
public function blockquote(Element $node): array
|
||||
{
|
||||
$citation = null;
|
||||
@@ -30,10 +28,14 @@ class Blocks extends Plain
|
||||
|
||||
// get all the text for the quote
|
||||
foreach ($node->children() as $child) {
|
||||
if (is_a($child, 'DOMText') === true) {
|
||||
if ($child instanceof DOMText) {
|
||||
$text[] = trim($child->textContent);
|
||||
}
|
||||
if (is_a($child, 'DOMElement') === true && $child->tagName !== 'footer') {
|
||||
|
||||
if (
|
||||
$child instanceof DOMElement &&
|
||||
$child->tagName !== 'footer'
|
||||
) {
|
||||
$text[] = (new Element($child))->innerHTML($this->marks());
|
||||
}
|
||||
}
|
||||
@@ -58,13 +60,10 @@ class Blocks extends Plain
|
||||
/**
|
||||
* Creates the fallback block type
|
||||
* if no other block can be found
|
||||
*
|
||||
* @param \Kirby\Parsley\Element|string $element
|
||||
* @return array|null
|
||||
*/
|
||||
public function fallback($element): ?array
|
||||
public function fallback(Element|string $element): array|null
|
||||
{
|
||||
if (is_a($element, Element::class) === true) {
|
||||
if ($element instanceof Element) {
|
||||
$html = $element->innerHtml();
|
||||
|
||||
// wrap the inner HTML in a p tag if it doesn't
|
||||
@@ -94,9 +93,6 @@ class Blocks extends Plain
|
||||
|
||||
/**
|
||||
* Converts a heading element to a heading block
|
||||
*
|
||||
* @param \Kirby\Parsley\Element $node
|
||||
* @return array
|
||||
*/
|
||||
public function heading(Element $node): array
|
||||
{
|
||||
@@ -117,10 +113,6 @@ class Blocks extends Plain
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Kirby\Parsley\Element $node
|
||||
* @return array
|
||||
*/
|
||||
public function iframe(Element $node): array
|
||||
{
|
||||
$caption = null;
|
||||
@@ -163,10 +155,6 @@ class Blocks extends Plain
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Kirby\Parsley\Element $node
|
||||
* @return array
|
||||
*/
|
||||
public function img(Element $node): array
|
||||
{
|
||||
$caption = null;
|
||||
@@ -197,9 +185,6 @@ class Blocks extends Plain
|
||||
|
||||
/**
|
||||
* Converts a list element to HTML
|
||||
*
|
||||
* @param \Kirby\Parsley\Element $node
|
||||
* @return string
|
||||
*/
|
||||
public function list(Element $node): string
|
||||
{
|
||||
@@ -209,9 +194,9 @@ class Blocks extends Plain
|
||||
$innerHtml = '';
|
||||
|
||||
foreach ($li->children() as $child) {
|
||||
if (is_a($child, 'DOMText') === true) {
|
||||
if ($child instanceof DOMText) {
|
||||
$innerHtml .= $child->textContent;
|
||||
} elseif (is_a($child, 'DOMElement') === true) {
|
||||
} elseif ($child instanceof DOMElement) {
|
||||
$child = new Element($child);
|
||||
|
||||
if (in_array($child->tagName(), ['ul', 'ol']) === true) {
|
||||
@@ -231,8 +216,6 @@ class Blocks extends Plain
|
||||
/**
|
||||
* Returns a list of allowed inline marks
|
||||
* and their parsing rules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function marks(): array
|
||||
{
|
||||
@@ -291,114 +274,79 @@ class Blocks extends Plain
|
||||
* their parsing rules
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return array
|
||||
*/
|
||||
public function nodes(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'blockquote',
|
||||
'parse' => function (Element $node) {
|
||||
return $this->blockquote($node);
|
||||
}
|
||||
'parse' => fn (Element $node) => $this->blockquote($node)
|
||||
],
|
||||
[
|
||||
'tag' => 'h1',
|
||||
'parse' => function (Element $node) {
|
||||
return $this->heading($node);
|
||||
}
|
||||
'parse' => fn (Element $node) => $this->heading($node)
|
||||
],
|
||||
[
|
||||
'tag' => 'h2',
|
||||
'parse' => function (Element $node) {
|
||||
return $this->heading($node);
|
||||
}
|
||||
'parse' => fn (Element $node) => $this->heading($node)
|
||||
],
|
||||
[
|
||||
'tag' => 'h3',
|
||||
'parse' => function (Element $node) {
|
||||
return $this->heading($node);
|
||||
}
|
||||
'parse' => fn (Element $node) => $this->heading($node)
|
||||
],
|
||||
[
|
||||
'tag' => 'h4',
|
||||
'parse' => function (Element $node) {
|
||||
return $this->heading($node);
|
||||
}
|
||||
'parse' => fn (Element $node) => $this->heading($node)
|
||||
],
|
||||
[
|
||||
'tag' => 'h5',
|
||||
'parse' => function (Element $node) {
|
||||
return $this->heading($node);
|
||||
}
|
||||
'parse' => fn (Element $node) => $this->heading($node)
|
||||
],
|
||||
[
|
||||
'tag' => 'h6',
|
||||
'parse' => function (Element $node) {
|
||||
return $this->heading($node);
|
||||
}
|
||||
'parse' => fn (Element $node) => $this->heading($node)
|
||||
],
|
||||
[
|
||||
'tag' => 'hr',
|
||||
'parse' => function (Element $node) {
|
||||
return [
|
||||
'type' => 'line'
|
||||
];
|
||||
}
|
||||
'parse' => fn (Element $node) => ['type' => 'line']
|
||||
],
|
||||
[
|
||||
'tag' => 'iframe',
|
||||
'parse' => function (Element $node) {
|
||||
return $this->iframe($node);
|
||||
}
|
||||
'parse' => fn (Element $node) => $this->iframe($node)
|
||||
],
|
||||
[
|
||||
'tag' => 'img',
|
||||
'parse' => function (Element $node) {
|
||||
return $this->img($node);
|
||||
}
|
||||
'parse' => fn (Element $node) => $this->img($node)
|
||||
],
|
||||
[
|
||||
'tag' => 'ol',
|
||||
'parse' => function (Element $node) {
|
||||
return [
|
||||
'content' => [
|
||||
'text' => $this->list($node)
|
||||
],
|
||||
'type' => 'list',
|
||||
];
|
||||
}
|
||||
'parse' => fn (Element $node) => [
|
||||
'content' => [
|
||||
'text' => $this->list($node)
|
||||
],
|
||||
'type' => 'list',
|
||||
]
|
||||
],
|
||||
[
|
||||
'tag' => 'pre',
|
||||
'parse' => function (Element $node) {
|
||||
return $this->pre($node);
|
||||
}
|
||||
'parse' => fn (Element $node) => $this->pre($node)
|
||||
],
|
||||
[
|
||||
'tag' => 'table',
|
||||
'parse' => function (Element $node) {
|
||||
return $this->table($node);
|
||||
}
|
||||
'parse' => fn (Element $node) => $this->table($node)
|
||||
],
|
||||
[
|
||||
'tag' => 'ul',
|
||||
'parse' => function (Element $node) {
|
||||
return [
|
||||
'content' => [
|
||||
'text' => $this->list($node)
|
||||
],
|
||||
'type' => 'list',
|
||||
];
|
||||
}
|
||||
'parse' => fn (Element $node) => [
|
||||
'content' => [
|
||||
'text' => $this->list($node)
|
||||
],
|
||||
'type' => 'list',
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Kirby\Parsley\Element $node
|
||||
* @return array
|
||||
*/
|
||||
public function pre(Element $node): array
|
||||
{
|
||||
$language = 'text';
|
||||
@@ -421,10 +369,6 @@ class Blocks extends Plain
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Kirby\Parsley\Element $node
|
||||
* @return array
|
||||
*/
|
||||
public function table(Element $node): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -23,13 +23,10 @@ class Plain extends Schema
|
||||
/**
|
||||
* Creates the fallback block type
|
||||
* if no other block can be found
|
||||
*
|
||||
* @param \Kirby\Parsley\Element|string $element
|
||||
* @return array|null
|
||||
*/
|
||||
public function fallback($element): ?array
|
||||
public function fallback(Element|string $element): array|null
|
||||
{
|
||||
if (is_a($element, Element::class) === true) {
|
||||
if ($element instanceof Element) {
|
||||
$text = $element->innerText();
|
||||
} elseif (is_string($element) === true) {
|
||||
$text = trim($element);
|
||||
@@ -52,8 +49,6 @@ class Plain extends Schema
|
||||
/**
|
||||
* Returns a list of all elements that
|
||||
* should be skipped during parsing
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function skip(): array
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user