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;
|
||||
}
|
||||
}
|
||||
51
vendor/league/commonmark/src/Block/Parser/ATXHeadingParser.php
vendored
Normal file
51
vendor/league/commonmark/src/Block/Parser/ATXHeadingParser.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\Parser;
|
||||
|
||||
use League\CommonMark\Block\Element\Heading;
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
use League\CommonMark\Util\RegexHelper;
|
||||
|
||||
final class ATXHeadingParser implements BlockParserInterface
|
||||
{
|
||||
public function parse(ContextInterface $context, Cursor $cursor): bool
|
||||
{
|
||||
if ($cursor->isIndented()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$match = RegexHelper::matchFirst('/^#{1,6}(?:[ \t]+|$)/', $cursor->getLine(), $cursor->getNextNonSpacePosition());
|
||||
if (!$match) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cursor->advanceToNextNonSpaceOrTab();
|
||||
|
||||
$cursor->advanceBy(\strlen($match[0]));
|
||||
|
||||
$level = \strlen(\trim($match[0]));
|
||||
$str = $cursor->getRemainder();
|
||||
/** @var string $str */
|
||||
$str = \preg_replace('/^[ \t]*#+[ \t]*$/', '', $str);
|
||||
/** @var string $str */
|
||||
$str = \preg_replace('/[ \t]+#+[ \t]*$/', '', $str);
|
||||
|
||||
$context->addBlock(new Heading($level, $str));
|
||||
$context->setBlocksParsed(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
29
vendor/league/commonmark/src/Block/Parser/BlockParserInterface.php
vendored
Normal file
29
vendor/league/commonmark/src/Block/Parser/BlockParserInterface.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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\Parser;
|
||||
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
|
||||
interface BlockParserInterface
|
||||
{
|
||||
/**
|
||||
* @param ContextInterface $context
|
||||
* @param Cursor $cursor
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function parse(ContextInterface $context, Cursor $cursor): bool;
|
||||
}
|
||||
41
vendor/league/commonmark/src/Block/Parser/BlockQuoteParser.php
vendored
Normal file
41
vendor/league/commonmark/src/Block/Parser/BlockQuoteParser.php
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
<?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\Parser;
|
||||
|
||||
use League\CommonMark\Block\Element\BlockQuote;
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
|
||||
final class BlockQuoteParser implements BlockParserInterface
|
||||
{
|
||||
public function parse(ContextInterface $context, Cursor $cursor): bool
|
||||
{
|
||||
if ($cursor->isIndented()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($cursor->getNextNonSpaceCharacter() !== '>') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cursor->advanceToNextNonSpaceOrTab();
|
||||
$cursor->advanceBy(1);
|
||||
$cursor->advanceBySpaceOrTab();
|
||||
|
||||
$context->addBlock(new BlockQuote());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
47
vendor/league/commonmark/src/Block/Parser/FencedCodeParser.php
vendored
Normal file
47
vendor/league/commonmark/src/Block/Parser/FencedCodeParser.php
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
<?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\Parser;
|
||||
|
||||
use League\CommonMark\Block\Element\FencedCode;
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
|
||||
final class FencedCodeParser implements BlockParserInterface
|
||||
{
|
||||
public function parse(ContextInterface $context, Cursor $cursor): bool
|
||||
{
|
||||
if ($cursor->isIndented()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$c = $cursor->getCharacter();
|
||||
if ($c !== ' ' && $c !== "\t" && $c !== '`' && $c !== '~') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$indent = $cursor->getIndent();
|
||||
$fence = $cursor->match('/^[ \t]*(?:`{3,}(?!.*`)|~{3,})/');
|
||||
if ($fence === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// fenced code block
|
||||
$fence = \ltrim($fence, " \t");
|
||||
$fenceLength = \strlen($fence);
|
||||
$context->addBlock(new FencedCode($fenceLength, $fence[0], $indent));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
59
vendor/league/commonmark/src/Block/Parser/HtmlBlockParser.php
vendored
Normal file
59
vendor/league/commonmark/src/Block/Parser/HtmlBlockParser.php
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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\Parser;
|
||||
|
||||
use League\CommonMark\Block\Element\HtmlBlock;
|
||||
use League\CommonMark\Block\Element\Paragraph;
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
use League\CommonMark\Util\RegexHelper;
|
||||
|
||||
final class HtmlBlockParser implements BlockParserInterface
|
||||
{
|
||||
public function parse(ContextInterface $context, Cursor $cursor): bool
|
||||
{
|
||||
if ($cursor->isIndented()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($cursor->getNextNonSpaceCharacter() !== '<') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$savedState = $cursor->saveState();
|
||||
|
||||
$cursor->advanceToNextNonSpaceOrTab();
|
||||
$line = $cursor->getRemainder();
|
||||
|
||||
for ($blockType = 1; $blockType <= 7; $blockType++) {
|
||||
$match = RegexHelper::matchAt(
|
||||
RegexHelper::getHtmlBlockOpenRegex($blockType),
|
||||
$line
|
||||
);
|
||||
|
||||
if ($match !== null && ($blockType < 7 || !($context->getContainer() instanceof Paragraph))) {
|
||||
$cursor->restoreState($savedState);
|
||||
$context->addBlock(new HtmlBlock($blockType));
|
||||
$context->setBlocksParsed(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$cursor->restoreState($savedState);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
43
vendor/league/commonmark/src/Block/Parser/IndentedCodeParser.php
vendored
Normal file
43
vendor/league/commonmark/src/Block/Parser/IndentedCodeParser.php
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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\Parser;
|
||||
|
||||
use League\CommonMark\Block\Element\IndentedCode;
|
||||
use League\CommonMark\Block\Element\Paragraph;
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
|
||||
final class IndentedCodeParser implements BlockParserInterface
|
||||
{
|
||||
public function parse(ContextInterface $context, Cursor $cursor): bool
|
||||
{
|
||||
if (!$cursor->isIndented()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($context->getTip() instanceof Paragraph) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($cursor->isBlank()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cursor->advanceBy(Cursor::INDENT_LEVEL, true);
|
||||
$context->addBlock(new IndentedCode());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
32
vendor/league/commonmark/src/Block/Parser/LazyParagraphParser.php
vendored
Normal file
32
vendor/league/commonmark/src/Block/Parser/LazyParagraphParser.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?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\Parser;
|
||||
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
|
||||
final class LazyParagraphParser implements BlockParserInterface
|
||||
{
|
||||
public function parse(ContextInterface $context, Cursor $cursor): bool
|
||||
{
|
||||
if (!$cursor->isIndented()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$context->setBlocksParsed(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
154
vendor/league/commonmark/src/Block/Parser/ListParser.php
vendored
Normal file
154
vendor/league/commonmark/src/Block/Parser/ListParser.php
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
<?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\Parser;
|
||||
|
||||
use League\CommonMark\Block\Element\ListBlock;
|
||||
use League\CommonMark\Block\Element\ListData;
|
||||
use League\CommonMark\Block\Element\ListItem;
|
||||
use League\CommonMark\Block\Element\Paragraph;
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
use League\CommonMark\Util\ConfigurationAwareInterface;
|
||||
use League\CommonMark\Util\ConfigurationInterface;
|
||||
use League\CommonMark\Util\RegexHelper;
|
||||
|
||||
final class ListParser implements BlockParserInterface, ConfigurationAwareInterface
|
||||
{
|
||||
/** @var ConfigurationInterface|null */
|
||||
private $config;
|
||||
|
||||
/** @var string|null */
|
||||
private $listMarkerRegex;
|
||||
|
||||
public function setConfiguration(ConfigurationInterface $configuration)
|
||||
{
|
||||
$this->config = $configuration;
|
||||
}
|
||||
|
||||
public function parse(ContextInterface $context, Cursor $cursor): bool
|
||||
{
|
||||
if ($cursor->isIndented() && !($context->getContainer() instanceof ListBlock)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$indent = $cursor->getIndent();
|
||||
if ($indent >= 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$tmpCursor = clone $cursor;
|
||||
$tmpCursor->advanceToNextNonSpaceOrTab();
|
||||
$rest = $tmpCursor->getRemainder();
|
||||
|
||||
if (\preg_match($this->listMarkerRegex ?? $this->generateListMarkerRegex(), $rest) === 1) {
|
||||
$data = new ListData();
|
||||
$data->markerOffset = $indent;
|
||||
$data->type = ListBlock::TYPE_BULLET;
|
||||
$data->delimiter = null;
|
||||
$data->bulletChar = $rest[0];
|
||||
$markerLength = 1;
|
||||
} elseif (($matches = RegexHelper::matchFirst('/^(\d{1,9})([.)])/', $rest)) && (!($context->getContainer() instanceof Paragraph) || $matches[1] === '1')) {
|
||||
$data = new ListData();
|
||||
$data->markerOffset = $indent;
|
||||
$data->type = ListBlock::TYPE_ORDERED;
|
||||
$data->start = (int) $matches[1];
|
||||
$data->delimiter = $matches[2];
|
||||
$data->bulletChar = null;
|
||||
$markerLength = \strlen($matches[0]);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure we have spaces after
|
||||
$nextChar = $tmpCursor->peek($markerLength);
|
||||
if (!($nextChar === null || $nextChar === "\t" || $nextChar === ' ')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If it interrupts paragraph, make sure first line isn't blank
|
||||
$container = $context->getContainer();
|
||||
if ($container instanceof Paragraph && !RegexHelper::matchAt(RegexHelper::REGEX_NON_SPACE, $rest, $markerLength)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We've got a match! Advance offset and calculate padding
|
||||
$cursor->advanceToNextNonSpaceOrTab(); // to start of marker
|
||||
$cursor->advanceBy($markerLength, true); // to end of marker
|
||||
$data->padding = $this->calculateListMarkerPadding($cursor, $markerLength);
|
||||
|
||||
// add the list if needed
|
||||
if (!($container instanceof ListBlock) || !$data->equals($container->getListData())) {
|
||||
$context->addBlock(new ListBlock($data));
|
||||
}
|
||||
|
||||
// add the list item
|
||||
$context->addBlock(new ListItem($data));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Cursor $cursor
|
||||
* @param int $markerLength
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function calculateListMarkerPadding(Cursor $cursor, int $markerLength): int
|
||||
{
|
||||
$start = $cursor->saveState();
|
||||
$spacesStartCol = $cursor->getColumn();
|
||||
|
||||
while ($cursor->getColumn() - $spacesStartCol < 5) {
|
||||
if (!$cursor->advanceBySpaceOrTab()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$blankItem = $cursor->peek() === null;
|
||||
$spacesAfterMarker = $cursor->getColumn() - $spacesStartCol;
|
||||
|
||||
if ($spacesAfterMarker >= 5 || $spacesAfterMarker < 1 || $blankItem) {
|
||||
$cursor->restoreState($start);
|
||||
$cursor->advanceBySpaceOrTab();
|
||||
|
||||
return $markerLength + 1;
|
||||
}
|
||||
|
||||
return $markerLength + $spacesAfterMarker;
|
||||
}
|
||||
|
||||
private function generateListMarkerRegex(): string
|
||||
{
|
||||
// No configuration given - use the defaults
|
||||
if ($this->config === null) {
|
||||
return $this->listMarkerRegex = '/^[*+-]/';
|
||||
}
|
||||
|
||||
$deprecatedMarkers = $this->config->get('unordered_list_markers', ConfigurationInterface::MISSING);
|
||||
if ($deprecatedMarkers !== ConfigurationInterface::MISSING) {
|
||||
@\trigger_error('The "unordered_list_markers" configuration option is deprecated in league/commonmark 1.6 and will be replaced with "commonmark > unordered_list_markers" in 2.0', \E_USER_DEPRECATED);
|
||||
} else {
|
||||
$deprecatedMarkers = ['*', '+', '-'];
|
||||
}
|
||||
|
||||
$markers = $this->config->get('commonmark/unordered_list_markers', $deprecatedMarkers);
|
||||
|
||||
if (!\is_array($markers) || $markers === []) {
|
||||
throw new \RuntimeException('Invalid configuration option "unordered_list_markers": value must be an array of strings');
|
||||
}
|
||||
|
||||
return $this->listMarkerRegex = '/^[' . \preg_quote(\implode('', $markers), '/') . ']/';
|
||||
}
|
||||
}
|
||||
81
vendor/league/commonmark/src/Block/Parser/SetExtHeadingParser.php
vendored
Normal file
81
vendor/league/commonmark/src/Block/Parser/SetExtHeadingParser.php
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
<?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\Parser;
|
||||
|
||||
use League\CommonMark\Block\Element\Heading;
|
||||
use League\CommonMark\Block\Element\Paragraph;
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
use League\CommonMark\Reference\ReferenceParser;
|
||||
use League\CommonMark\Util\RegexHelper;
|
||||
|
||||
final class SetExtHeadingParser implements BlockParserInterface
|
||||
{
|
||||
public function parse(ContextInterface $context, Cursor $cursor): bool
|
||||
{
|
||||
if ($cursor->isIndented()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!($context->getContainer() instanceof Paragraph)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$match = RegexHelper::matchFirst('/^(?:=+|-+)[ \t]*$/', $cursor->getLine(), $cursor->getNextNonSpacePosition());
|
||||
if ($match === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$level = $match[0][0] === '=' ? 1 : 2;
|
||||
$strings = $context->getContainer()->getStrings();
|
||||
|
||||
$strings = $this->resolveReferenceLinkDefinitions($strings, $context->getReferenceParser());
|
||||
if (empty($strings)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$context->replaceContainerBlock(new Heading($level, $strings));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve reference link definition
|
||||
*
|
||||
* @see https://github.com/commonmark/commonmark.js/commit/993bbe335931af847460effa99b2411eb643577d
|
||||
*
|
||||
* @param string[] $strings
|
||||
* @param ReferenceParser $referenceParser
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
private function resolveReferenceLinkDefinitions(array $strings, ReferenceParser $referenceParser): array
|
||||
{
|
||||
foreach ($strings as &$string) {
|
||||
$cursor = new Cursor($string);
|
||||
while ($cursor->getCharacter() === '[' && $referenceParser->parse($cursor)) {
|
||||
$string = $cursor->getRemainder();
|
||||
}
|
||||
|
||||
if ($string !== '') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return \array_filter($strings, function ($s) {
|
||||
return $s !== '';
|
||||
});
|
||||
}
|
||||
}
|
||||
43
vendor/league/commonmark/src/Block/Parser/ThematicBreakParser.php
vendored
Normal file
43
vendor/league/commonmark/src/Block/Parser/ThematicBreakParser.php
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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\Parser;
|
||||
|
||||
use League\CommonMark\Block\Element\ThematicBreak;
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
use League\CommonMark\Util\RegexHelper;
|
||||
|
||||
final class ThematicBreakParser implements BlockParserInterface
|
||||
{
|
||||
public function parse(ContextInterface $context, Cursor $cursor): bool
|
||||
{
|
||||
if ($cursor->isIndented()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$match = RegexHelper::matchAt(RegexHelper::REGEX_THEMATIC_BREAK, $cursor->getLine(), $cursor->getNextNonSpacePosition());
|
||||
if ($match === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Advance to the end of the string, consuming the entire line (of the thematic break)
|
||||
$cursor->advanceToEnd();
|
||||
|
||||
$context->addBlock(new ThematicBreak());
|
||||
$context->setBlocksParsed(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
50
vendor/league/commonmark/src/Block/Renderer/BlockQuoteRenderer.php
vendored
Normal file
50
vendor/league/commonmark/src/Block/Renderer/BlockQuoteRenderer.php
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
<?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\Renderer;
|
||||
|
||||
use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\Block\Element\BlockQuote;
|
||||
use League\CommonMark\ElementRendererInterface;
|
||||
use League\CommonMark\HtmlElement;
|
||||
|
||||
final class BlockQuoteRenderer implements BlockRendererInterface
|
||||
{
|
||||
/**
|
||||
* @param BlockQuote $block
|
||||
* @param ElementRendererInterface $htmlRenderer
|
||||
* @param bool $inTightList
|
||||
*
|
||||
* @return HtmlElement
|
||||
*/
|
||||
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
|
||||
{
|
||||
if (!($block instanceof BlockQuote)) {
|
||||
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
|
||||
}
|
||||
|
||||
$attrs = $block->getData('attributes', []);
|
||||
|
||||
$filling = $htmlRenderer->renderBlocks($block->children());
|
||||
if ($filling === '') {
|
||||
return new HtmlElement('blockquote', $attrs, $htmlRenderer->getOption('inner_separator', "\n"));
|
||||
}
|
||||
|
||||
return new HtmlElement(
|
||||
'blockquote',
|
||||
$attrs,
|
||||
$htmlRenderer->getOption('inner_separator', "\n") . $filling . $htmlRenderer->getOption('inner_separator', "\n")
|
||||
);
|
||||
}
|
||||
}
|
||||
31
vendor/league/commonmark/src/Block/Renderer/BlockRendererInterface.php
vendored
Normal file
31
vendor/league/commonmark/src/Block/Renderer/BlockRendererInterface.php
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
<?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\Renderer;
|
||||
|
||||
use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\ElementRendererInterface;
|
||||
use League\CommonMark\HtmlElement;
|
||||
|
||||
interface BlockRendererInterface
|
||||
{
|
||||
/**
|
||||
* @param AbstractBlock $block
|
||||
* @param ElementRendererInterface $htmlRenderer
|
||||
* @param bool $inTightList
|
||||
*
|
||||
* @return HtmlElement|string|null
|
||||
*/
|
||||
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false);
|
||||
}
|
||||
40
vendor/league/commonmark/src/Block/Renderer/DocumentRenderer.php
vendored
Normal file
40
vendor/league/commonmark/src/Block/Renderer/DocumentRenderer.php
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<?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\Renderer;
|
||||
|
||||
use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\Block\Element\Document;
|
||||
use League\CommonMark\ElementRendererInterface;
|
||||
|
||||
final class DocumentRenderer implements BlockRendererInterface
|
||||
{
|
||||
/**
|
||||
* @param Document $block
|
||||
* @param ElementRendererInterface $htmlRenderer
|
||||
* @param bool $inTightList
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
|
||||
{
|
||||
if (!($block instanceof Document)) {
|
||||
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
|
||||
}
|
||||
|
||||
$wholeDoc = $htmlRenderer->renderBlocks($block->children());
|
||||
|
||||
return $wholeDoc === '' ? '' : $wholeDoc . "\n";
|
||||
}
|
||||
}
|
||||
52
vendor/league/commonmark/src/Block/Renderer/FencedCodeRenderer.php
vendored
Normal file
52
vendor/league/commonmark/src/Block/Renderer/FencedCodeRenderer.php
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
<?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\Renderer;
|
||||
|
||||
use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\Block\Element\FencedCode;
|
||||
use League\CommonMark\ElementRendererInterface;
|
||||
use League\CommonMark\HtmlElement;
|
||||
use League\CommonMark\Util\Xml;
|
||||
|
||||
final class FencedCodeRenderer implements BlockRendererInterface
|
||||
{
|
||||
/**
|
||||
* @param FencedCode $block
|
||||
* @param ElementRendererInterface $htmlRenderer
|
||||
* @param bool $inTightList
|
||||
*
|
||||
* @return HtmlElement
|
||||
*/
|
||||
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
|
||||
{
|
||||
if (!($block instanceof FencedCode)) {
|
||||
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
|
||||
}
|
||||
|
||||
$attrs = $block->getData('attributes', []);
|
||||
|
||||
$infoWords = $block->getInfoWords();
|
||||
if (\count($infoWords) !== 0 && \strlen($infoWords[0]) !== 0) {
|
||||
$attrs['class'] = isset($attrs['class']) ? $attrs['class'] . ' ' : '';
|
||||
$attrs['class'] .= 'language-' . $infoWords[0];
|
||||
}
|
||||
|
||||
return new HtmlElement(
|
||||
'pre',
|
||||
[],
|
||||
new HtmlElement('code', $attrs, Xml::escape($block->getStringContent()))
|
||||
);
|
||||
}
|
||||
}
|
||||
43
vendor/league/commonmark/src/Block/Renderer/HeadingRenderer.php
vendored
Normal file
43
vendor/league/commonmark/src/Block/Renderer/HeadingRenderer.php
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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\Renderer;
|
||||
|
||||
use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\Block\Element\Heading;
|
||||
use League\CommonMark\ElementRendererInterface;
|
||||
use League\CommonMark\HtmlElement;
|
||||
|
||||
final class HeadingRenderer implements BlockRendererInterface
|
||||
{
|
||||
/**
|
||||
* @param Heading $block
|
||||
* @param ElementRendererInterface $htmlRenderer
|
||||
* @param bool $inTightList
|
||||
*
|
||||
* @return HtmlElement
|
||||
*/
|
||||
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
|
||||
{
|
||||
if (!($block instanceof Heading)) {
|
||||
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
|
||||
}
|
||||
|
||||
$tag = 'h' . $block->getLevel();
|
||||
|
||||
$attrs = $block->getData('attributes', []);
|
||||
|
||||
return new HtmlElement($tag, $attrs, $htmlRenderer->renderInlines($block->children()));
|
||||
}
|
||||
}
|
||||
59
vendor/league/commonmark/src/Block/Renderer/HtmlBlockRenderer.php
vendored
Normal file
59
vendor/league/commonmark/src/Block/Renderer/HtmlBlockRenderer.php
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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\Renderer;
|
||||
|
||||
use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\Block\Element\HtmlBlock;
|
||||
use League\CommonMark\ElementRendererInterface;
|
||||
use League\CommonMark\EnvironmentInterface;
|
||||
use League\CommonMark\Util\ConfigurationAwareInterface;
|
||||
use League\CommonMark\Util\ConfigurationInterface;
|
||||
|
||||
final class HtmlBlockRenderer implements BlockRendererInterface, ConfigurationAwareInterface
|
||||
{
|
||||
/**
|
||||
* @var ConfigurationInterface
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @param HtmlBlock $block
|
||||
* @param ElementRendererInterface $htmlRenderer
|
||||
* @param bool $inTightList
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
|
||||
{
|
||||
if (!($block instanceof HtmlBlock)) {
|
||||
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
|
||||
}
|
||||
|
||||
if ($this->config->get('html_input') === EnvironmentInterface::HTML_INPUT_STRIP) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($this->config->get('html_input') === EnvironmentInterface::HTML_INPUT_ESCAPE) {
|
||||
return \htmlspecialchars($block->getStringContent(), \ENT_NOQUOTES);
|
||||
}
|
||||
|
||||
return $block->getStringContent();
|
||||
}
|
||||
|
||||
public function setConfiguration(ConfigurationInterface $configuration)
|
||||
{
|
||||
$this->config = $configuration;
|
||||
}
|
||||
}
|
||||
46
vendor/league/commonmark/src/Block/Renderer/IndentedCodeRenderer.php
vendored
Normal file
46
vendor/league/commonmark/src/Block/Renderer/IndentedCodeRenderer.php
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
<?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\Renderer;
|
||||
|
||||
use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\Block\Element\IndentedCode;
|
||||
use League\CommonMark\ElementRendererInterface;
|
||||
use League\CommonMark\HtmlElement;
|
||||
use League\CommonMark\Util\Xml;
|
||||
|
||||
final class IndentedCodeRenderer implements BlockRendererInterface
|
||||
{
|
||||
/**
|
||||
* @param IndentedCode $block
|
||||
* @param ElementRendererInterface $htmlRenderer
|
||||
* @param bool $inTightList
|
||||
*
|
||||
* @return HtmlElement
|
||||
*/
|
||||
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
|
||||
{
|
||||
if (!($block instanceof IndentedCode)) {
|
||||
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
|
||||
}
|
||||
|
||||
$attrs = $block->getData('attributes', []);
|
||||
|
||||
return new HtmlElement(
|
||||
'pre',
|
||||
[],
|
||||
new HtmlElement('code', $attrs, Xml::escape($block->getStringContent()))
|
||||
);
|
||||
}
|
||||
}
|
||||
56
vendor/league/commonmark/src/Block/Renderer/ListBlockRenderer.php
vendored
Normal file
56
vendor/league/commonmark/src/Block/Renderer/ListBlockRenderer.php
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
<?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\Renderer;
|
||||
|
||||
use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\Block\Element\ListBlock;
|
||||
use League\CommonMark\ElementRendererInterface;
|
||||
use League\CommonMark\HtmlElement;
|
||||
|
||||
final class ListBlockRenderer implements BlockRendererInterface
|
||||
{
|
||||
/**
|
||||
* @param ListBlock $block
|
||||
* @param ElementRendererInterface $htmlRenderer
|
||||
* @param bool $inTightList
|
||||
*
|
||||
* @return HtmlElement
|
||||
*/
|
||||
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
|
||||
{
|
||||
if (!($block instanceof ListBlock)) {
|
||||
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
|
||||
}
|
||||
|
||||
$listData = $block->getListData();
|
||||
|
||||
$tag = $listData->type === ListBlock::TYPE_BULLET ? 'ul' : 'ol';
|
||||
|
||||
$attrs = $block->getData('attributes', []);
|
||||
|
||||
if ($listData->start !== null && $listData->start !== 1) {
|
||||
$attrs['start'] = (string) $listData->start;
|
||||
}
|
||||
|
||||
return new HtmlElement(
|
||||
$tag,
|
||||
$attrs,
|
||||
$htmlRenderer->getOption('inner_separator', "\n") . $htmlRenderer->renderBlocks(
|
||||
$block->children(),
|
||||
$block->isTight()
|
||||
) . $htmlRenderer->getOption('inner_separator', "\n")
|
||||
);
|
||||
}
|
||||
}
|
||||
60
vendor/league/commonmark/src/Block/Renderer/ListItemRenderer.php
vendored
Normal file
60
vendor/league/commonmark/src/Block/Renderer/ListItemRenderer.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\Renderer;
|
||||
|
||||
use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\Block\Element\ListItem;
|
||||
use League\CommonMark\Block\Element\Paragraph;
|
||||
use League\CommonMark\ElementRendererInterface;
|
||||
use League\CommonMark\Extension\TaskList\TaskListItemMarker;
|
||||
use League\CommonMark\HtmlElement;
|
||||
|
||||
final class ListItemRenderer implements BlockRendererInterface
|
||||
{
|
||||
/**
|
||||
* @param ListItem $block
|
||||
* @param ElementRendererInterface $htmlRenderer
|
||||
* @param bool $inTightList
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
|
||||
{
|
||||
if (!($block instanceof ListItem)) {
|
||||
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
|
||||
}
|
||||
|
||||
$contents = $htmlRenderer->renderBlocks($block->children(), $inTightList);
|
||||
if (\substr($contents, 0, 1) === '<' && !$this->startsTaskListItem($block)) {
|
||||
$contents = "\n" . $contents;
|
||||
}
|
||||
if (\substr($contents, -1, 1) === '>') {
|
||||
$contents .= "\n";
|
||||
}
|
||||
|
||||
$attrs = $block->getData('attributes', []);
|
||||
|
||||
$li = new HtmlElement('li', $attrs, $contents);
|
||||
|
||||
return $li;
|
||||
}
|
||||
|
||||
private function startsTaskListItem(ListItem $block): bool
|
||||
{
|
||||
$firstChild = $block->firstChild();
|
||||
|
||||
return $firstChild instanceof Paragraph && $firstChild->firstChild() instanceof TaskListItemMarker;
|
||||
}
|
||||
}
|
||||
45
vendor/league/commonmark/src/Block/Renderer/ParagraphRenderer.php
vendored
Normal file
45
vendor/league/commonmark/src/Block/Renderer/ParagraphRenderer.php
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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\Renderer;
|
||||
|
||||
use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\Block\Element\Paragraph;
|
||||
use League\CommonMark\ElementRendererInterface;
|
||||
use League\CommonMark\HtmlElement;
|
||||
|
||||
final class ParagraphRenderer implements BlockRendererInterface
|
||||
{
|
||||
/**
|
||||
* @param Paragraph $block
|
||||
* @param ElementRendererInterface $htmlRenderer
|
||||
* @param bool $inTightList
|
||||
*
|
||||
* @return HtmlElement|string
|
||||
*/
|
||||
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
|
||||
{
|
||||
if (!($block instanceof Paragraph)) {
|
||||
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
|
||||
}
|
||||
|
||||
if ($inTightList) {
|
||||
return $htmlRenderer->renderInlines($block->children());
|
||||
}
|
||||
|
||||
$attrs = $block->getData('attributes', []);
|
||||
|
||||
return new HtmlElement('p', $attrs, $htmlRenderer->renderInlines($block->children()));
|
||||
}
|
||||
}
|
||||
41
vendor/league/commonmark/src/Block/Renderer/ThematicBreakRenderer.php
vendored
Normal file
41
vendor/league/commonmark/src/Block/Renderer/ThematicBreakRenderer.php
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
<?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\Renderer;
|
||||
|
||||
use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\Block\Element\ThematicBreak;
|
||||
use League\CommonMark\ElementRendererInterface;
|
||||
use League\CommonMark\HtmlElement;
|
||||
|
||||
final class ThematicBreakRenderer implements BlockRendererInterface
|
||||
{
|
||||
/**
|
||||
* @param ThematicBreak $block
|
||||
* @param ElementRendererInterface $htmlRenderer
|
||||
* @param bool $inTightList
|
||||
*
|
||||
* @return HtmlElement
|
||||
*/
|
||||
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
|
||||
{
|
||||
if (!($block instanceof ThematicBreak)) {
|
||||
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
|
||||
}
|
||||
|
||||
$attrs = $block->getData('attributes', []);
|
||||
|
||||
return new HtmlElement('hr', $attrs, '', true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user