Upgrade framework
This commit is contained in:
63
vendor/league/commonmark/src/Node/Block/AbstractBlock.php
vendored
Normal file
63
vendor/league/commonmark/src/Node/Block/AbstractBlock.php
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
|
||||
* - (c) John MacFarlane
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Node\Block;
|
||||
|
||||
use League\CommonMark\Node\Node;
|
||||
|
||||
/**
|
||||
* Block-level element
|
||||
*
|
||||
* @method parent() ?AbstractBlock
|
||||
*/
|
||||
abstract class AbstractBlock extends Node
|
||||
{
|
||||
protected ?int $startLine = null;
|
||||
|
||||
protected ?int $endLine = null;
|
||||
|
||||
protected function setParent(?Node $node = null): void
|
||||
{
|
||||
if ($node && ! $node instanceof self) {
|
||||
throw new \InvalidArgumentException('Parent of block must also be block (cannot be inline)');
|
||||
}
|
||||
|
||||
parent::setParent($node);
|
||||
}
|
||||
|
||||
public function setStartLine(?int $startLine): void
|
||||
{
|
||||
$this->startLine = $startLine;
|
||||
if ($this->endLine === null) {
|
||||
$this->endLine = $startLine;
|
||||
}
|
||||
}
|
||||
|
||||
public function getStartLine(): ?int
|
||||
{
|
||||
return $this->startLine;
|
||||
}
|
||||
|
||||
public function setEndLine(?int $endLine): void
|
||||
{
|
||||
$this->endLine = $endLine;
|
||||
}
|
||||
|
||||
public function getEndLine(): ?int
|
||||
{
|
||||
return $this->endLine;
|
||||
}
|
||||
}
|
||||
56
vendor/league/commonmark/src/Node/Block/Document.php
vendored
Normal file
56
vendor/league/commonmark/src/Node/Block/Document.php
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
|
||||
* - (c) John MacFarlane
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Node\Block;
|
||||
|
||||
use League\CommonMark\Parser\Cursor;
|
||||
use League\CommonMark\Reference\ReferenceMap;
|
||||
use League\CommonMark\Reference\ReferenceMapInterface;
|
||||
|
||||
class Document extends AbstractBlock
|
||||
{
|
||||
/** @psalm-readonly */
|
||||
protected ReferenceMapInterface $referenceMap;
|
||||
|
||||
public function __construct(?ReferenceMapInterface $referenceMap = null)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->setStartLine(1);
|
||||
|
||||
$this->referenceMap = $referenceMap ?? new ReferenceMap();
|
||||
}
|
||||
|
||||
public function getReferenceMap(): ReferenceMapInterface
|
||||
{
|
||||
return $this->referenceMap;
|
||||
}
|
||||
|
||||
public function canContain(AbstractBlock $block): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isCode(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function matchesNextLine(Cursor $cursor): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
21
vendor/league/commonmark/src/Node/Block/Paragraph.php
vendored
Normal file
21
vendor/league/commonmark/src/Node/Block/Paragraph.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
|
||||
* - (c) John MacFarlane
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Node\Block;
|
||||
|
||||
class Paragraph extends AbstractBlock
|
||||
{
|
||||
}
|
||||
21
vendor/league/commonmark/src/Node/Block/TightBlockInterface.php
vendored
Normal file
21
vendor/league/commonmark/src/Node/Block/TightBlockInterface.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Node\Block;
|
||||
|
||||
interface TightBlockInterface
|
||||
{
|
||||
public function isTight(): bool;
|
||||
|
||||
public function setTight(bool $tight): void;
|
||||
}
|
||||
23
vendor/league/commonmark/src/Node/Inline/AbstractInline.php
vendored
Normal file
23
vendor/league/commonmark/src/Node/Inline/AbstractInline.php
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
|
||||
* - (c) John MacFarlane
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Node\Inline;
|
||||
|
||||
use League\CommonMark\Node\Node;
|
||||
|
||||
abstract class AbstractInline extends Node
|
||||
{
|
||||
}
|
||||
45
vendor/league/commonmark/src/Node/Inline/AbstractStringContainer.php
vendored
Normal file
45
vendor/league/commonmark/src/Node/Inline/AbstractStringContainer.php
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
|
||||
* - (c) John MacFarlane
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Node\Inline;
|
||||
|
||||
use League\CommonMark\Node\StringContainerInterface;
|
||||
|
||||
abstract class AbstractStringContainer extends AbstractInline implements StringContainerInterface
|
||||
{
|
||||
protected string $literal = '';
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public function __construct(string $contents = '', array $data = [])
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->literal = $contents;
|
||||
$this->data->import($data);
|
||||
}
|
||||
|
||||
public function getLiteral(): string
|
||||
{
|
||||
return $this->literal;
|
||||
}
|
||||
|
||||
public function setLiteral(string $literal): void
|
||||
{
|
||||
$this->literal = $literal;
|
||||
}
|
||||
}
|
||||
105
vendor/league/commonmark/src/Node/Inline/AdjacentTextMerger.php
vendored
Normal file
105
vendor/league/commonmark/src/Node/Inline/AdjacentTextMerger.php
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* Additional emphasis processing code based on commonmark-java (https://github.com/atlassian/commonmark-java)
|
||||
* - (c) Atlassian Pty Ltd
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Node\Inline;
|
||||
|
||||
use League\CommonMark\Node\Node;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class AdjacentTextMerger
|
||||
{
|
||||
public static function mergeChildNodes(Node $node): void
|
||||
{
|
||||
// No children or just one child node, no need for merging
|
||||
if ($node->firstChild() === $node->lastChild() || $node->firstChild() === null || $node->lastChild() === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @psalm-suppress PossiblyNullArgument */
|
||||
self::mergeTextNodesInclusive($node->firstChild(), $node->lastChild());
|
||||
}
|
||||
|
||||
public static function mergeTextNodesBetweenExclusive(Node $fromNode, Node $toNode): void
|
||||
{
|
||||
// No nodes between them
|
||||
if ($fromNode === $toNode || $fromNode->next() === $toNode || $fromNode->next() === null || $toNode->previous() === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @psalm-suppress PossiblyNullArgument */
|
||||
self::mergeTextNodesInclusive($fromNode->next(), $toNode->previous());
|
||||
}
|
||||
|
||||
public static function mergeWithDirectlyAdjacentNodes(Text $node): void
|
||||
{
|
||||
$start = ($previous = $node->previous()) instanceof Text ? $previous : $node;
|
||||
$end = ($next = $node->next()) instanceof Text ? $next : $node;
|
||||
|
||||
self::mergeIfNeeded($start, $end);
|
||||
}
|
||||
|
||||
private static function mergeTextNodesInclusive(Node $fromNode, Node $toNode): void
|
||||
{
|
||||
$first = null;
|
||||
$last = null;
|
||||
|
||||
$node = $fromNode;
|
||||
while ($node !== null) {
|
||||
if ($node instanceof Text) {
|
||||
if ($first === null) {
|
||||
$first = $node;
|
||||
}
|
||||
|
||||
$last = $node;
|
||||
} else {
|
||||
self::mergeIfNeeded($first, $last);
|
||||
$first = null;
|
||||
$last = null;
|
||||
}
|
||||
|
||||
if ($node === $toNode) {
|
||||
break;
|
||||
}
|
||||
|
||||
$node = $node->next();
|
||||
}
|
||||
|
||||
self::mergeIfNeeded($first, $last);
|
||||
}
|
||||
|
||||
private static function mergeIfNeeded(?Text $first, ?Text $last): void
|
||||
{
|
||||
if ($first === null || $last === null || $first === $last) {
|
||||
// No merging needed
|
||||
return;
|
||||
}
|
||||
|
||||
$s = $first->getLiteral();
|
||||
|
||||
$node = $first->next();
|
||||
$stop = $last->next();
|
||||
while ($node !== $stop && $node instanceof Text) {
|
||||
$s .= $node->getLiteral();
|
||||
$unlink = $node;
|
||||
$node = $node->next();
|
||||
$unlink->detach();
|
||||
}
|
||||
|
||||
$first->setLiteral($s);
|
||||
}
|
||||
}
|
||||
21
vendor/league/commonmark/src/Node/Inline/DelimitedInterface.php
vendored
Normal file
21
vendor/league/commonmark/src/Node/Inline/DelimitedInterface.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Node\Inline;
|
||||
|
||||
interface DelimitedInterface
|
||||
{
|
||||
public function getOpeningDelimiter(): string;
|
||||
|
||||
public function getClosingDelimiter(): string;
|
||||
}
|
||||
40
vendor/league/commonmark/src/Node/Inline/Newline.php
vendored
Normal file
40
vendor/league/commonmark/src/Node/Inline/Newline.php
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
|
||||
* - (c) John MacFarlane
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Node\Inline;
|
||||
|
||||
final class Newline extends AbstractInline
|
||||
{
|
||||
// Any changes to these constants should be reflected in .phpstorm.meta.php
|
||||
public const HARDBREAK = 0;
|
||||
public const SOFTBREAK = 1;
|
||||
|
||||
/** @psalm-readonly */
|
||||
private int $type;
|
||||
|
||||
public function __construct(int $breakType = self::HARDBREAK)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->type = $breakType;
|
||||
}
|
||||
|
||||
/** @psalm-immutable */
|
||||
public function getType(): int
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
}
|
||||
25
vendor/league/commonmark/src/Node/Inline/Text.php
vendored
Normal file
25
vendor/league/commonmark/src/Node/Inline/Text.php
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
|
||||
* - (c) John MacFarlane
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Node\Inline;
|
||||
|
||||
final class Text extends AbstractStringContainer
|
||||
{
|
||||
public function append(string $literal): void
|
||||
{
|
||||
$this->literal .= $literal;
|
||||
}
|
||||
}
|
||||
261
vendor/league/commonmark/src/Node/Node.php
vendored
Normal file
261
vendor/league/commonmark/src/Node/Node.php
vendored
Normal file
@@ -0,0 +1,261 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
|
||||
* - (c) John MacFarlane
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Node;
|
||||
|
||||
use Dflydev\DotAccessData\Data;
|
||||
|
||||
abstract class Node
|
||||
{
|
||||
/** @psalm-readonly */
|
||||
public Data $data;
|
||||
|
||||
/** @psalm-readonly-allow-private-mutation */
|
||||
protected int $depth = 0;
|
||||
|
||||
/** @psalm-readonly-allow-private-mutation */
|
||||
protected ?Node $parent = null;
|
||||
|
||||
/** @psalm-readonly-allow-private-mutation */
|
||||
protected ?Node $previous = null;
|
||||
|
||||
/** @psalm-readonly-allow-private-mutation */
|
||||
protected ?Node $next = null;
|
||||
|
||||
/** @psalm-readonly-allow-private-mutation */
|
||||
protected ?Node $firstChild = null;
|
||||
|
||||
/** @psalm-readonly-allow-private-mutation */
|
||||
protected ?Node $lastChild = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->data = new Data([
|
||||
'attributes' => [],
|
||||
]);
|
||||
}
|
||||
|
||||
public function previous(): ?Node
|
||||
{
|
||||
return $this->previous;
|
||||
}
|
||||
|
||||
public function next(): ?Node
|
||||
{
|
||||
return $this->next;
|
||||
}
|
||||
|
||||
public function parent(): ?Node
|
||||
{
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
protected function setParent(?Node $node = null): void
|
||||
{
|
||||
$this->parent = $node;
|
||||
$this->depth = $node === null ? 0 : $node->depth + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts the $sibling node after $this
|
||||
*/
|
||||
public function insertAfter(Node $sibling): void
|
||||
{
|
||||
$sibling->detach();
|
||||
$sibling->next = $this->next;
|
||||
|
||||
if ($sibling->next) {
|
||||
$sibling->next->previous = $sibling;
|
||||
}
|
||||
|
||||
$sibling->previous = $this;
|
||||
$this->next = $sibling;
|
||||
$sibling->setParent($this->parent);
|
||||
|
||||
if (! $sibling->next && $sibling->parent) {
|
||||
$sibling->parent->lastChild = $sibling;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts the $sibling node before $this
|
||||
*/
|
||||
public function insertBefore(Node $sibling): void
|
||||
{
|
||||
$sibling->detach();
|
||||
$sibling->previous = $this->previous;
|
||||
|
||||
if ($sibling->previous) {
|
||||
$sibling->previous->next = $sibling;
|
||||
}
|
||||
|
||||
$sibling->next = $this;
|
||||
$this->previous = $sibling;
|
||||
$sibling->setParent($this->parent);
|
||||
|
||||
if (! $sibling->previous && $sibling->parent) {
|
||||
$sibling->parent->firstChild = $sibling;
|
||||
}
|
||||
}
|
||||
|
||||
public function replaceWith(Node $replacement): void
|
||||
{
|
||||
$replacement->detach();
|
||||
$this->insertAfter($replacement);
|
||||
$this->detach();
|
||||
}
|
||||
|
||||
public function detach(): void
|
||||
{
|
||||
if ($this->previous) {
|
||||
$this->previous->next = $this->next;
|
||||
} elseif ($this->parent) {
|
||||
$this->parent->firstChild = $this->next;
|
||||
}
|
||||
|
||||
if ($this->next) {
|
||||
$this->next->previous = $this->previous;
|
||||
} elseif ($this->parent) {
|
||||
$this->parent->lastChild = $this->previous;
|
||||
}
|
||||
|
||||
$this->parent = null;
|
||||
$this->next = null;
|
||||
$this->previous = null;
|
||||
$this->depth = 0;
|
||||
}
|
||||
|
||||
public function hasChildren(): bool
|
||||
{
|
||||
return $this->firstChild !== null;
|
||||
}
|
||||
|
||||
public function firstChild(): ?Node
|
||||
{
|
||||
return $this->firstChild;
|
||||
}
|
||||
|
||||
public function lastChild(): ?Node
|
||||
{
|
||||
return $this->lastChild;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Node[]
|
||||
*/
|
||||
public function children(): iterable
|
||||
{
|
||||
$children = [];
|
||||
for ($current = $this->firstChild; $current !== null; $current = $current->next) {
|
||||
$children[] = $current;
|
||||
}
|
||||
|
||||
return $children;
|
||||
}
|
||||
|
||||
public function appendChild(Node $child): void
|
||||
{
|
||||
if ($this->lastChild) {
|
||||
$this->lastChild->insertAfter($child);
|
||||
} else {
|
||||
$child->detach();
|
||||
$child->setParent($this);
|
||||
$this->lastChild = $this->firstChild = $child;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds $child as the very first child of $this
|
||||
*/
|
||||
public function prependChild(Node $child): void
|
||||
{
|
||||
if ($this->firstChild) {
|
||||
$this->firstChild->insertBefore($child);
|
||||
} else {
|
||||
$child->detach();
|
||||
$child->setParent($this);
|
||||
$this->lastChild = $this->firstChild = $child;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detaches all child nodes of given node
|
||||
*/
|
||||
public function detachChildren(): void
|
||||
{
|
||||
foreach ($this->children() as $children) {
|
||||
$children->setParent(null);
|
||||
}
|
||||
|
||||
$this->firstChild = $this->lastChild = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace all children of given node with collection of another
|
||||
*
|
||||
* @param iterable<Node> $children
|
||||
*/
|
||||
public function replaceChildren(iterable $children): void
|
||||
{
|
||||
$this->detachChildren();
|
||||
foreach ($children as $item) {
|
||||
$this->appendChild($item);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDepth(): int
|
||||
{
|
||||
return $this->depth;
|
||||
}
|
||||
|
||||
public function walker(): NodeWalker
|
||||
{
|
||||
return new NodeWalker($this);
|
||||
}
|
||||
|
||||
public function iterator(int $flags = 0): NodeIterator
|
||||
{
|
||||
return new NodeIterator($this, $flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the current node and its children
|
||||
*
|
||||
* WARNING: This is a recursive function and should not be called on deeply-nested node trees!
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
// Cloned nodes are detached from their parents, siblings, and children
|
||||
$this->parent = null;
|
||||
$this->previous = null;
|
||||
$this->next = null;
|
||||
// But save a copy of the children since we'll need that in a moment
|
||||
$children = $this->children();
|
||||
$this->detachChildren();
|
||||
|
||||
// The original children get cloned and re-added
|
||||
foreach ($children as $child) {
|
||||
$this->appendChild(clone $child);
|
||||
}
|
||||
}
|
||||
|
||||
public static function assertInstanceOf(Node $node): void
|
||||
{
|
||||
if (! $node instanceof static) {
|
||||
throw new \InvalidArgumentException(\sprintf('Incompatible node type: expected %s, got %s', static::class, \get_class($node)));
|
||||
}
|
||||
}
|
||||
}
|
||||
58
vendor/league/commonmark/src/Node/NodeIterator.php
vendored
Normal file
58
vendor/league/commonmark/src/Node/NodeIterator.php
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Node;
|
||||
|
||||
use League\CommonMark\Node\Block\AbstractBlock;
|
||||
|
||||
/**
|
||||
* @implements \IteratorAggregate<int, Node>
|
||||
*/
|
||||
final class NodeIterator implements \IteratorAggregate
|
||||
{
|
||||
public const FLAG_BLOCKS_ONLY = 1;
|
||||
|
||||
private Node $node;
|
||||
private bool $blocksOnly;
|
||||
|
||||
public function __construct(Node $node, int $flags = 0)
|
||||
{
|
||||
$this->node = $node;
|
||||
$this->blocksOnly = ($flags & self::FLAG_BLOCKS_ONLY) === self::FLAG_BLOCKS_ONLY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Generator<int, Node>
|
||||
*/
|
||||
public function getIterator(): \Generator
|
||||
{
|
||||
$stack = [$this->node];
|
||||
$index = 0;
|
||||
|
||||
while ($stack) {
|
||||
$node = \array_pop($stack);
|
||||
|
||||
yield $index++ => $node;
|
||||
|
||||
// Push all children onto the stack in reverse order
|
||||
$child = $node->lastChild();
|
||||
while ($child !== null) {
|
||||
if (! $this->blocksOnly || $child instanceof AbstractBlock) {
|
||||
$stack[] = $child;
|
||||
}
|
||||
|
||||
$child = $child->previous();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
80
vendor/league/commonmark/src/Node/NodeWalker.php
vendored
Normal file
80
vendor/league/commonmark/src/Node/NodeWalker.php
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
|
||||
* - (c) John MacFarlane
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Node;
|
||||
|
||||
use League\CommonMark\Node\Block\AbstractBlock;
|
||||
|
||||
final class NodeWalker
|
||||
{
|
||||
/** @psalm-readonly */
|
||||
private Node $root;
|
||||
|
||||
/** @psalm-readonly-allow-private-mutation */
|
||||
private ?Node $current = null;
|
||||
|
||||
/** @psalm-readonly-allow-private-mutation */
|
||||
private bool $entering;
|
||||
|
||||
public function __construct(Node $root)
|
||||
{
|
||||
$this->root = $root;
|
||||
$this->current = $this->root;
|
||||
$this->entering = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an event which contains node and entering flag
|
||||
* (entering is true when we enter a Node from a parent or sibling,
|
||||
* and false when we reenter it from child)
|
||||
*/
|
||||
public function next(): ?NodeWalkerEvent
|
||||
{
|
||||
$current = $this->current;
|
||||
$entering = $this->entering;
|
||||
if ($current === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($entering && ($current instanceof AbstractBlock || $current->hasChildren())) {
|
||||
if ($current->firstChild()) {
|
||||
$this->current = $current->firstChild();
|
||||
$this->entering = true;
|
||||
} else {
|
||||
$this->entering = false;
|
||||
}
|
||||
} elseif ($current === $this->root) {
|
||||
$this->current = null;
|
||||
} elseif ($current->next() === null) {
|
||||
$this->current = $current->parent();
|
||||
$this->entering = false;
|
||||
} else {
|
||||
$this->current = $current->next();
|
||||
$this->entering = true;
|
||||
}
|
||||
|
||||
return new NodeWalkerEvent($current, $entering);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the iterator to resume at the specified node
|
||||
*/
|
||||
public function resumeAt(Node $node, bool $entering = true): void
|
||||
{
|
||||
$this->current = $node;
|
||||
$this->entering = $entering;
|
||||
}
|
||||
}
|
||||
42
vendor/league/commonmark/src/Node/NodeWalkerEvent.php
vendored
Normal file
42
vendor/league/commonmark/src/Node/NodeWalkerEvent.php
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
|
||||
* - (c) John MacFarlane
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Node;
|
||||
|
||||
final class NodeWalkerEvent
|
||||
{
|
||||
/** @psalm-readonly */
|
||||
private Node $node;
|
||||
|
||||
/** @psalm-readonly */
|
||||
private bool $isEntering;
|
||||
|
||||
public function __construct(Node $node, bool $isEntering = true)
|
||||
{
|
||||
$this->node = $node;
|
||||
$this->isEntering = $isEntering;
|
||||
}
|
||||
|
||||
public function getNode(): Node
|
||||
{
|
||||
return $this->node;
|
||||
}
|
||||
|
||||
public function isEntering(): bool
|
||||
{
|
||||
return $this->isEntering;
|
||||
}
|
||||
}
|
||||
139
vendor/league/commonmark/src/Node/Query.php
vendored
Normal file
139
vendor/league/commonmark/src/Node/Query.php
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Node;
|
||||
|
||||
use League\CommonMark\Node\Query\AndExpr;
|
||||
use League\CommonMark\Node\Query\OrExpr;
|
||||
|
||||
final class Query
|
||||
{
|
||||
/** @var callable(Node): bool $condition */
|
||||
private $condition;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->condition = new AndExpr();
|
||||
}
|
||||
|
||||
public function where(callable ...$conditions): self
|
||||
{
|
||||
return $this->andWhere(...$conditions);
|
||||
}
|
||||
|
||||
public function andWhere(callable ...$conditions): self
|
||||
{
|
||||
if ($this->condition instanceof AndExpr) {
|
||||
foreach ($conditions as $condition) {
|
||||
$this->condition->add($condition);
|
||||
}
|
||||
} else {
|
||||
$this->condition = new AndExpr($this->condition, ...$conditions);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orWhere(callable ...$conditions): self
|
||||
{
|
||||
if ($this->condition instanceof OrExpr) {
|
||||
foreach ($conditions as $condition) {
|
||||
$this->condition->add($condition);
|
||||
}
|
||||
} else {
|
||||
$this->condition = new OrExpr($this->condition, ...$conditions);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function findOne(Node $node): ?Node
|
||||
{
|
||||
foreach ($node->iterator() as $n) {
|
||||
if (\call_user_func($this->condition, $n)) {
|
||||
return $n;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<Node>
|
||||
*/
|
||||
public function findAll(Node $node, ?int $limit = PHP_INT_MAX): iterable
|
||||
{
|
||||
$resultCount = 0;
|
||||
|
||||
foreach ($node->iterator() as $n) {
|
||||
if ($resultCount >= $limit) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (! \call_user_func($this->condition, $n)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
++$resultCount;
|
||||
|
||||
yield $n;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return callable(Node): bool
|
||||
*/
|
||||
public static function type(string $class): callable
|
||||
{
|
||||
return static fn (Node $node): bool => $node instanceof $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-param ?callable(Node): bool $condition
|
||||
*
|
||||
* @return callable(Node): bool
|
||||
*/
|
||||
public static function hasChild(?callable $condition = null): callable
|
||||
{
|
||||
return static function (Node $node) use ($condition): bool {
|
||||
foreach ($node->children() as $child) {
|
||||
if ($condition === null || $condition($child)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-param ?callable(Node): bool $condition
|
||||
*
|
||||
* @return callable(Node): bool
|
||||
*/
|
||||
public static function hasParent(?callable $condition = null): callable
|
||||
{
|
||||
return static function (Node $node) use ($condition): bool {
|
||||
$parent = $node->parent();
|
||||
if ($parent === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($condition === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $condition($parent);
|
||||
};
|
||||
}
|
||||
}
|
||||
55
vendor/league/commonmark/src/Node/Query/AndExpr.php
vendored
Normal file
55
vendor/league/commonmark/src/Node/Query/AndExpr.php
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Node\Query;
|
||||
|
||||
use League\CommonMark\Node\Node;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class AndExpr implements ExpressionInterface
|
||||
{
|
||||
/**
|
||||
* @var callable[]
|
||||
* @psalm-var list<callable(Node): bool>
|
||||
*/
|
||||
private array $conditions;
|
||||
|
||||
/**
|
||||
* @psalm-param callable(Node): bool $expressions
|
||||
*/
|
||||
public function __construct(callable ...$expressions)
|
||||
{
|
||||
$this->conditions = $expressions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable(Node): bool $expression
|
||||
*/
|
||||
public function add(callable $expression): void
|
||||
{
|
||||
$this->conditions[] = $expression;
|
||||
}
|
||||
|
||||
public function __invoke(Node $node): bool
|
||||
{
|
||||
foreach ($this->conditions as $condition) {
|
||||
if (! $condition($node)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
21
vendor/league/commonmark/src/Node/Query/ExpressionInterface.php
vendored
Normal file
21
vendor/league/commonmark/src/Node/Query/ExpressionInterface.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Node\Query;
|
||||
|
||||
use League\CommonMark\Node\Node;
|
||||
|
||||
interface ExpressionInterface
|
||||
{
|
||||
public function __invoke(Node $node): bool;
|
||||
}
|
||||
55
vendor/league/commonmark/src/Node/Query/OrExpr.php
vendored
Normal file
55
vendor/league/commonmark/src/Node/Query/OrExpr.php
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Node\Query;
|
||||
|
||||
use League\CommonMark\Node\Node;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class OrExpr implements ExpressionInterface
|
||||
{
|
||||
/**
|
||||
* @var callable[]
|
||||
* @psalm-var list<callable(Node): bool>
|
||||
*/
|
||||
private array $conditions;
|
||||
|
||||
/**
|
||||
* @psalm-param callable(Node): bool $expressions
|
||||
*/
|
||||
public function __construct(callable ...$expressions)
|
||||
{
|
||||
$this->conditions = $expressions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable(Node): bool $expression
|
||||
*/
|
||||
public function add(callable $expression): void
|
||||
{
|
||||
$this->conditions[] = $expression;
|
||||
}
|
||||
|
||||
public function __invoke(Node $node): bool
|
||||
{
|
||||
foreach ($this->conditions as $condition) {
|
||||
if ($condition($node)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
21
vendor/league/commonmark/src/Node/RawMarkupContainerInterface.php
vendored
Normal file
21
vendor/league/commonmark/src/Node/RawMarkupContainerInterface.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Node;
|
||||
|
||||
/**
|
||||
* Interface for a node which contains raw, unprocessed markup (like HTML)
|
||||
*/
|
||||
interface RawMarkupContainerInterface extends StringContainerInterface
|
||||
{
|
||||
}
|
||||
54
vendor/league/commonmark/src/Node/StringContainerHelper.php
vendored
Normal file
54
vendor/league/commonmark/src/Node/StringContainerHelper.php
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Node;
|
||||
|
||||
final class StringContainerHelper
|
||||
{
|
||||
/**
|
||||
* Extract text literals from all descendant nodes
|
||||
*
|
||||
* @param Node $node Parent node
|
||||
* @param array<string> $excludeTypes Optional list of node class types to exclude
|
||||
*
|
||||
* @return string Concatenated literals
|
||||
*/
|
||||
public static function getChildText(Node $node, array $excludeTypes = []): string
|
||||
{
|
||||
$text = '';
|
||||
|
||||
foreach ($node->iterator() as $child) {
|
||||
if ($child instanceof StringContainerInterface && ! self::isOneOf($child, $excludeTypes)) {
|
||||
$text .= $child->getLiteral();
|
||||
}
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $classesOrInterfacesToCheck
|
||||
*
|
||||
* @psalm-pure
|
||||
*/
|
||||
private static function isOneOf(object $object, array $classesOrInterfacesToCheck): bool
|
||||
{
|
||||
foreach ($classesOrInterfacesToCheck as $type) {
|
||||
if ($object instanceof $type) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
27
vendor/league/commonmark/src/Node/StringContainerInterface.php
vendored
Normal file
27
vendor/league/commonmark/src/Node/StringContainerInterface.php
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
|
||||
* - (c) John MacFarlane
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark\Node;
|
||||
|
||||
/**
|
||||
* Interface for a node which directly contains line(s) of text
|
||||
*/
|
||||
interface StringContainerInterface
|
||||
{
|
||||
public function setLiteral(string $literal): void;
|
||||
|
||||
public function getLiteral(): string;
|
||||
}
|
||||
Reference in New Issue
Block a user