Primo Committ
This commit is contained in:
222
vendor/league/commonmark/src/Block/Element/AbstractBlock.php
vendored
Normal file
222
vendor/league/commonmark/src/Block/Element/AbstractBlock.php
vendored
Normal file
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Block\Element;
|
||||
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
use League\CommonMark\Node\Node;
|
||||
|
||||
/**
|
||||
* Block-level element
|
||||
*
|
||||
* @method parent() ?AbstractBlock
|
||||
*/
|
||||
abstract class AbstractBlock extends Node
|
||||
{
|
||||
/**
|
||||
* Used for storage of arbitrary data.
|
||||
*
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
public $data = [];
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $open = true;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $lastLineBlank = false;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $startLine = 0;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $endLine = 0;
|
||||
|
||||
protected function setParent(Node $node = null)
|
||||
{
|
||||
if ($node && !$node instanceof self) {
|
||||
throw new \InvalidArgumentException('Parent of block must also be block (can not be inline)');
|
||||
}
|
||||
|
||||
parent::setParent($node);
|
||||
}
|
||||
|
||||
public function isContainer(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasChildren(): bool
|
||||
{
|
||||
return $this->firstChild !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this block can contain the given block as a child node
|
||||
*
|
||||
* @param AbstractBlock $block
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract public function canContain(AbstractBlock $block): bool;
|
||||
|
||||
/**
|
||||
* Whether this is a code block
|
||||
*
|
||||
* Code blocks are extra-greedy - they'll try to consume all subsequent
|
||||
* lines of content without calling matchesNextLine() each time.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract public function isCode(): bool;
|
||||
|
||||
/**
|
||||
* @param Cursor $cursor
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract public function matchesNextLine(Cursor $cursor): bool;
|
||||
|
||||
/**
|
||||
* @param int $startLine
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setStartLine(int $startLine)
|
||||
{
|
||||
$this->startLine = $startLine;
|
||||
if (empty($this->endLine)) {
|
||||
$this->endLine = $startLine;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getStartLine(): int
|
||||
{
|
||||
return $this->startLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $endLine
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setEndLine(int $endLine)
|
||||
{
|
||||
$this->endLine = $endLine;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getEndLine(): int
|
||||
{
|
||||
return $this->endLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the block ends with a blank line
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function endsWithBlankLine(): bool
|
||||
{
|
||||
return $this->lastLineBlank;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $blank
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setLastLineBlank(bool $blank)
|
||||
{
|
||||
$this->lastLineBlank = $blank;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the last line should be marked as blank
|
||||
*
|
||||
* @param Cursor $cursor
|
||||
* @param int $currentLineNumber
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function shouldLastLineBeBlank(Cursor $cursor, int $currentLineNumber): bool
|
||||
{
|
||||
return $cursor->isBlank();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the block is open for modifications
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isOpen(): bool
|
||||
{
|
||||
return $this->open;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize the block; mark it closed for modification
|
||||
*
|
||||
* @param ContextInterface $context
|
||||
* @param int $endLineNumber
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function finalize(ContextInterface $context, int $endLineNumber)
|
||||
{
|
||||
if (!$this->open) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->open = false;
|
||||
$this->endLine = $endLineNumber;
|
||||
|
||||
// This should almost always be true
|
||||
if ($context->getTip() !== null) {
|
||||
$context->setTip($context->getTip()->parent());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getData(string $key, $default = null)
|
||||
{
|
||||
return \array_key_exists($key, $this->data) ? $this->data[$key] : $default;
|
||||
}
|
||||
}
|
||||
55
vendor/league/commonmark/src/Block/Element/AbstractStringContainerBlock.php
vendored
Normal file
55
vendor/league/commonmark/src/Block/Element/AbstractStringContainerBlock.php
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Block\Element;
|
||||
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
use League\CommonMark\Util\ArrayCollection;
|
||||
|
||||
/**
|
||||
* @method children() AbstractInline[]
|
||||
*/
|
||||
abstract class AbstractStringContainerBlock extends AbstractBlock implements StringContainerInterface
|
||||
{
|
||||
/**
|
||||
* @var ArrayCollection<int, string>
|
||||
*/
|
||||
protected $strings;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $finalStringContents = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->strings = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function addLine(string $line)
|
||||
{
|
||||
$this->strings[] = $line;
|
||||
}
|
||||
|
||||
abstract public function handleRemainingContents(ContextInterface $context, Cursor $cursor);
|
||||
|
||||
public function getStringContent(): string
|
||||
{
|
||||
return $this->finalStringContents;
|
||||
}
|
||||
}
|
||||
51
vendor/league/commonmark/src/Block/Element/BlockQuote.php
vendored
Normal file
51
vendor/league/commonmark/src/Block/Element/BlockQuote.php
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Block\Element;
|
||||
|
||||
use League\CommonMark\Cursor;
|
||||
|
||||
/**
|
||||
* @method children() AbstractBlock[]
|
||||
*/
|
||||
class BlockQuote extends AbstractBlock
|
||||
{
|
||||
public function canContain(AbstractBlock $block): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isCode(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function matchesNextLine(Cursor $cursor): bool
|
||||
{
|
||||
if (!$cursor->isIndented() && $cursor->getNextNonSpaceCharacter() === '>') {
|
||||
$cursor->advanceToNextNonSpaceOrTab();
|
||||
$cursor->advanceBy(1);
|
||||
$cursor->advanceBySpaceOrTab();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function shouldLastLineBeBlank(Cursor $cursor, int $currentLineNumber): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
58
vendor/league/commonmark/src/Block/Element/Document.php
vendored
Normal file
58
vendor/league/commonmark/src/Block/Element/Document.php
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Block\Element;
|
||||
|
||||
use League\CommonMark\Cursor;
|
||||
use League\CommonMark\Reference\ReferenceMap;
|
||||
use League\CommonMark\Reference\ReferenceMapInterface;
|
||||
|
||||
/**
|
||||
* @method children() AbstractBlock[]
|
||||
*/
|
||||
class Document extends AbstractBlock
|
||||
{
|
||||
/** @var ReferenceMapInterface */
|
||||
protected $referenceMap;
|
||||
|
||||
public function __construct(?ReferenceMapInterface $referenceMap = null)
|
||||
{
|
||||
$this->setStartLine(1);
|
||||
|
||||
$this->referenceMap = $referenceMap ?? new ReferenceMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ReferenceMapInterface
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
201
vendor/league/commonmark/src/Block/Element/FencedCode.php
vendored
Normal file
201
vendor/league/commonmark/src/Block/Element/FencedCode.php
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Block\Element;
|
||||
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
use League\CommonMark\Util\RegexHelper;
|
||||
|
||||
class FencedCode extends AbstractStringContainerBlock
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $info;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $length;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $char;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $offset;
|
||||
|
||||
/**
|
||||
* @param int $length
|
||||
* @param string $char
|
||||
* @param int $offset
|
||||
*/
|
||||
public function __construct(int $length, string $char, int $offset)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->length = $length;
|
||||
$this->char = $char;
|
||||
$this->offset = $offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getInfo(): string
|
||||
{
|
||||
return $this->info;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getInfoWords(): array
|
||||
{
|
||||
return \preg_split('/\s+/', $this->info) ?: [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getChar(): string
|
||||
{
|
||||
return $this->char;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $char
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setChar(string $char): self
|
||||
{
|
||||
$this->char = $char;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getLength(): int
|
||||
{
|
||||
return $this->length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $length
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLength(int $length): self
|
||||
{
|
||||
$this->length = $length;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getOffset(): int
|
||||
{
|
||||
return $this->offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOffset(int $offset): self
|
||||
{
|
||||
$this->offset = $offset;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function canContain(AbstractBlock $block): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isCode(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function matchesNextLine(Cursor $cursor): bool
|
||||
{
|
||||
if ($this->length === -1) {
|
||||
if ($cursor->isBlank()) {
|
||||
$this->lastLineBlank = true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Skip optional spaces of fence offset
|
||||
$cursor->match('/^ {0,' . $this->offset . '}/');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function finalize(ContextInterface $context, int $endLineNumber)
|
||||
{
|
||||
parent::finalize($context, $endLineNumber);
|
||||
|
||||
// first line becomes info string
|
||||
$firstLine = $this->strings->first();
|
||||
if ($firstLine === false) {
|
||||
$firstLine = '';
|
||||
}
|
||||
|
||||
$this->info = RegexHelper::unescape(\trim($firstLine));
|
||||
|
||||
if ($this->strings->count() === 1) {
|
||||
$this->finalStringContents = '';
|
||||
} else {
|
||||
$this->finalStringContents = \implode("\n", $this->strings->slice(1)) . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
public function handleRemainingContents(ContextInterface $context, Cursor $cursor)
|
||||
{
|
||||
/** @var self $container */
|
||||
$container = $context->getContainer();
|
||||
|
||||
// check for closing code fence
|
||||
if ($cursor->getIndent() <= 3 && $cursor->getNextNonSpaceCharacter() === $container->getChar()) {
|
||||
$match = RegexHelper::matchFirst('/^(?:`{3,}|~{3,})(?= *$)/', $cursor->getLine(), $cursor->getNextNonSpacePosition());
|
||||
if ($match !== null && \strlen($match[0]) >= $container->getLength()) {
|
||||
// don't add closing fence to container; instead, close it:
|
||||
$this->setLength(-1); // -1 means we've passed closer
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$container->addLine($cursor->getRemainder());
|
||||
}
|
||||
|
||||
public function shouldLastLineBeBlank(Cursor $cursor, int $currentLineNumber): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
80
vendor/league/commonmark/src/Block/Element/Heading.php
vendored
Normal file
80
vendor/league/commonmark/src/Block/Element/Heading.php
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Block\Element;
|
||||
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
|
||||
class Heading extends AbstractStringContainerBlock implements InlineContainerInterface
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $level;
|
||||
|
||||
/**
|
||||
* @param int $level
|
||||
* @param string|string[] $contents
|
||||
*/
|
||||
public function __construct(int $level, $contents)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->level = $level;
|
||||
|
||||
if (!\is_array($contents)) {
|
||||
$contents = [$contents];
|
||||
}
|
||||
|
||||
foreach ($contents as $line) {
|
||||
$this->addLine($line);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getLevel(): int
|
||||
{
|
||||
return $this->level;
|
||||
}
|
||||
|
||||
public function finalize(ContextInterface $context, int $endLineNumber)
|
||||
{
|
||||
parent::finalize($context, $endLineNumber);
|
||||
|
||||
$this->finalStringContents = \implode("\n", $this->strings->toArray());
|
||||
}
|
||||
|
||||
public function canContain(AbstractBlock $block): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isCode(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function matchesNextLine(Cursor $cursor): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function handleRemainingContents(ContextInterface $context, Cursor $cursor)
|
||||
{
|
||||
// nothing to do; contents were already added via the constructor.
|
||||
}
|
||||
}
|
||||
104
vendor/league/commonmark/src/Block/Element/HtmlBlock.php
vendored
Normal file
104
vendor/league/commonmark/src/Block/Element/HtmlBlock.php
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Block\Element;
|
||||
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
use League\CommonMark\Util\RegexHelper;
|
||||
|
||||
class HtmlBlock extends AbstractStringContainerBlock
|
||||
{
|
||||
// Any changes to these constants should be reflected in .phpstorm.meta.php
|
||||
const TYPE_1_CODE_CONTAINER = 1;
|
||||
const TYPE_2_COMMENT = 2;
|
||||
const TYPE_3 = 3;
|
||||
const TYPE_4 = 4;
|
||||
const TYPE_5_CDATA = 5;
|
||||
const TYPE_6_BLOCK_ELEMENT = 6;
|
||||
const TYPE_7_MISC_ELEMENT = 7;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* @param int $type
|
||||
*/
|
||||
public function __construct(int $type)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getType(): int
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $type
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setType(int $type)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public function canContain(AbstractBlock $block): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isCode(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function matchesNextLine(Cursor $cursor): bool
|
||||
{
|
||||
if ($cursor->isBlank() && ($this->type === self::TYPE_6_BLOCK_ELEMENT || $this->type === self::TYPE_7_MISC_ELEMENT)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function finalize(ContextInterface $context, int $endLineNumber)
|
||||
{
|
||||
parent::finalize($context, $endLineNumber);
|
||||
|
||||
$this->finalStringContents = \implode("\n", $this->strings->toArray());
|
||||
}
|
||||
|
||||
public function handleRemainingContents(ContextInterface $context, Cursor $cursor)
|
||||
{
|
||||
/** @var self $tip */
|
||||
$tip = $context->getTip();
|
||||
$tip->addLine($cursor->getRemainder());
|
||||
|
||||
// Check for end condition
|
||||
if ($this->type >= self::TYPE_1_CODE_CONTAINER && $this->type <= self::TYPE_5_CDATA) {
|
||||
if ($cursor->match(RegexHelper::getHtmlBlockCloseRegex($this->type)) !== null) {
|
||||
$this->finalize($context, $context->getLineNumber());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
72
vendor/league/commonmark/src/Block/Element/IndentedCode.php
vendored
Normal file
72
vendor/league/commonmark/src/Block/Element/IndentedCode.php
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Block\Element;
|
||||
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
|
||||
class IndentedCode extends AbstractStringContainerBlock
|
||||
{
|
||||
public function canContain(AbstractBlock $block): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isCode(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function matchesNextLine(Cursor $cursor): bool
|
||||
{
|
||||
if ($cursor->isIndented()) {
|
||||
$cursor->advanceBy(Cursor::INDENT_LEVEL, true);
|
||||
} elseif ($cursor->isBlank()) {
|
||||
$cursor->advanceToNextNonSpaceOrTab();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function finalize(ContextInterface $context, int $endLineNumber)
|
||||
{
|
||||
parent::finalize($context, $endLineNumber);
|
||||
|
||||
$reversed = \array_reverse($this->strings->toArray(), true);
|
||||
foreach ($reversed as $index => $line) {
|
||||
if ($line === '' || $line === "\n" || \preg_match('/^(\n *)$/', $line)) {
|
||||
unset($reversed[$index]);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$fixed = \array_reverse($reversed);
|
||||
$tmp = \implode("\n", $fixed);
|
||||
if (\substr($tmp, -1) !== "\n") {
|
||||
$tmp .= "\n";
|
||||
}
|
||||
|
||||
$this->finalStringContents = $tmp;
|
||||
}
|
||||
|
||||
public function handleRemainingContents(ContextInterface $context, Cursor $cursor)
|
||||
{
|
||||
/** @var self $tip */
|
||||
$tip = $context->getTip();
|
||||
$tip->addLine($cursor->getRemainder());
|
||||
}
|
||||
}
|
||||
20
vendor/league/commonmark/src/Block/Element/InlineContainerInterface.php
vendored
Normal file
20
vendor/league/commonmark/src/Block/Element/InlineContainerInterface.php
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Block\Element;
|
||||
|
||||
interface InlineContainerInterface extends StringContainerInterface
|
||||
{
|
||||
public function getStringContent(): string;
|
||||
}
|
||||
123
vendor/league/commonmark/src/Block/Element/ListBlock.php
vendored
Normal file
123
vendor/league/commonmark/src/Block/Element/ListBlock.php
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Block\Element;
|
||||
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
|
||||
/**
|
||||
* @method children() AbstractBlock[]
|
||||
*/
|
||||
class ListBlock extends AbstractBlock
|
||||
{
|
||||
const TYPE_BULLET = 'bullet';
|
||||
const TYPE_ORDERED = 'ordered';
|
||||
|
||||
/**
|
||||
* @deprecated This constant is deprecated in league/commonmark 1.4 and will be removed in 2.0; use TYPE_BULLET instead
|
||||
*/
|
||||
const TYPE_UNORDERED = self::TYPE_BULLET;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $tight = false;
|
||||
|
||||
/**
|
||||
* @var ListData
|
||||
*/
|
||||
protected $listData;
|
||||
|
||||
public function __construct(ListData $listData)
|
||||
{
|
||||
$this->listData = $listData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ListData
|
||||
*/
|
||||
public function getListData(): ListData
|
||||
{
|
||||
return $this->listData;
|
||||
}
|
||||
|
||||
public function endsWithBlankLine(): bool
|
||||
{
|
||||
if ($this->lastLineBlank) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasChildren()) {
|
||||
return $this->lastChild() instanceof AbstractBlock && $this->lastChild()->endsWithBlankLine();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function canContain(AbstractBlock $block): bool
|
||||
{
|
||||
return $block instanceof ListItem;
|
||||
}
|
||||
|
||||
public function isCode(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function matchesNextLine(Cursor $cursor): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function finalize(ContextInterface $context, int $endLineNumber)
|
||||
{
|
||||
parent::finalize($context, $endLineNumber);
|
||||
|
||||
$this->tight = true; // tight by default
|
||||
|
||||
foreach ($this->children() as $item) {
|
||||
if (!($item instanceof AbstractBlock)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// check for non-final list item ending with blank line:
|
||||
if ($item->endsWithBlankLine() && $item !== $this->lastChild()) {
|
||||
$this->tight = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// Recurse into children of list item, to see if there are
|
||||
// spaces between any of them:
|
||||
foreach ($item->children() as $subItem) {
|
||||
if ($subItem instanceof AbstractBlock && $subItem->endsWithBlankLine() && ($item !== $this->lastChild() || $subItem !== $item->lastChild())) {
|
||||
$this->tight = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function isTight(): bool
|
||||
{
|
||||
return $this->tight;
|
||||
}
|
||||
|
||||
public function setTight(bool $tight): self
|
||||
{
|
||||
$this->tight = $tight;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
60
vendor/league/commonmark/src/Block/Element/ListData.php
vendored
Normal file
60
vendor/league/commonmark/src/Block/Element/ListData.php
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Block\Element;
|
||||
|
||||
class ListData
|
||||
{
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
public $start;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $padding = 0;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $type;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
public $delimiter;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
public $bulletChar;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $markerOffset;
|
||||
|
||||
/**
|
||||
* @param ListData $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function equals(ListData $data)
|
||||
{
|
||||
return $this->type === $data->type &&
|
||||
$this->delimiter === $data->delimiter &&
|
||||
$this->bulletChar === $data->bulletChar;
|
||||
}
|
||||
}
|
||||
73
vendor/league/commonmark/src/Block/Element/ListItem.php
vendored
Normal file
73
vendor/league/commonmark/src/Block/Element/ListItem.php
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Block\Element;
|
||||
|
||||
use League\CommonMark\Cursor;
|
||||
|
||||
/**
|
||||
* @method children() AbstractBlock[]
|
||||
*/
|
||||
class ListItem extends AbstractBlock
|
||||
{
|
||||
/**
|
||||
* @var ListData
|
||||
*/
|
||||
protected $listData;
|
||||
|
||||
public function __construct(ListData $listData)
|
||||
{
|
||||
$this->listData = $listData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ListData
|
||||
*/
|
||||
public function getListData(): ListData
|
||||
{
|
||||
return $this->listData;
|
||||
}
|
||||
|
||||
public function canContain(AbstractBlock $block): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isCode(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function matchesNextLine(Cursor $cursor): bool
|
||||
{
|
||||
if ($cursor->isBlank()) {
|
||||
if ($this->firstChild === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cursor->advanceToNextNonSpaceOrTab();
|
||||
} elseif ($cursor->getIndent() >= $this->listData->markerOffset + $this->listData->padding) {
|
||||
$cursor->advanceBy($this->listData->markerOffset + $this->listData->padding, true);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function shouldLastLineBeBlank(Cursor $cursor, int $currentLineNumber): bool
|
||||
{
|
||||
return $cursor->isBlank() && $this->startLine < $currentLineNumber;
|
||||
}
|
||||
}
|
||||
98
vendor/league/commonmark/src/Block/Element/Paragraph.php
vendored
Normal file
98
vendor/league/commonmark/src/Block/Element/Paragraph.php
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Block\Element;
|
||||
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
|
||||
class Paragraph extends AbstractStringContainerBlock implements InlineContainerInterface
|
||||
{
|
||||
public function canContain(AbstractBlock $block): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isCode(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function matchesNextLine(Cursor $cursor): bool
|
||||
{
|
||||
if ($cursor->isBlank()) {
|
||||
$this->lastLineBlank = true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function finalize(ContextInterface $context, int $endLineNumber)
|
||||
{
|
||||
parent::finalize($context, $endLineNumber);
|
||||
|
||||
$this->finalStringContents = \preg_replace('/^ */m', '', \implode("\n", $this->getStrings()));
|
||||
|
||||
// Short-circuit
|
||||
if ($this->finalStringContents === '' || $this->finalStringContents[0] !== '[') {
|
||||
return;
|
||||
}
|
||||
|
||||
$cursor = new Cursor($this->finalStringContents);
|
||||
|
||||
$referenceFound = $this->parseReferences($context, $cursor);
|
||||
|
||||
$this->finalStringContents = $cursor->getRemainder();
|
||||
|
||||
if ($referenceFound && $cursor->isAtEnd()) {
|
||||
$this->detach();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContextInterface $context
|
||||
* @param Cursor $cursor
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function parseReferences(ContextInterface $context, Cursor $cursor)
|
||||
{
|
||||
$referenceFound = false;
|
||||
while ($cursor->getCharacter() === '[' && $context->getReferenceParser()->parse($cursor)) {
|
||||
$this->finalStringContents = $cursor->getRemainder();
|
||||
$referenceFound = true;
|
||||
}
|
||||
|
||||
return $referenceFound;
|
||||
}
|
||||
|
||||
public function handleRemainingContents(ContextInterface $context, Cursor $cursor)
|
||||
{
|
||||
$cursor->advanceToNextNonSpaceOrTab();
|
||||
|
||||
/** @var self $tip */
|
||||
$tip = $context->getTip();
|
||||
$tip->addLine($cursor->getRemainder());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getStrings(): array
|
||||
{
|
||||
return $this->strings->toArray();
|
||||
}
|
||||
}
|
||||
44
vendor/league/commonmark/src/Block/Element/StringContainerInterface.php
vendored
Normal file
44
vendor/league/commonmark/src/Block/Element/StringContainerInterface.php
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Block\Element;
|
||||
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
|
||||
/**
|
||||
* Interface for a block which can contain line(s) of strings
|
||||
*/
|
||||
interface StringContainerInterface
|
||||
{
|
||||
/**
|
||||
* @param string $line
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addLine(string $line);
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getStringContent(): string;
|
||||
|
||||
/**
|
||||
* @param ContextInterface $context
|
||||
* @param Cursor $cursor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handleRemainingContents(ContextInterface $context, Cursor $cursor);
|
||||
}
|
||||
35
vendor/league/commonmark/src/Block/Element/ThematicBreak.php
vendored
Normal file
35
vendor/league/commonmark/src/Block/Element/ThematicBreak.php
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Block\Element;
|
||||
|
||||
use League\CommonMark\Cursor;
|
||||
|
||||
class ThematicBreak extends AbstractBlock
|
||||
{
|
||||
public function canContain(AbstractBlock $block): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isCode(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function matchesNextLine(Cursor $cursor): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user