diff options
| author | Greg Roach <fisharebest@gmail.com> | 2018-01-09 13:37:46 +0000 |
|---|---|---|
| committer | Greg Roach <fisharebest@gmail.com> | 2018-01-10 22:19:52 +0000 |
| commit | e195df77d56d9863b3b38e4c1f75dc54bf0138dd (patch) | |
| tree | f69b92122c76e8ae449b5dd2f083edf45d7c8fdc /vendor/league/commonmark/src | |
| parent | 6214363af62618c3780500b5b6aa1ea171aba81a (diff) | |
| download | webtrees-e195df77d56d9863b3b38e4c1f75dc54bf0138dd.tar.gz webtrees-e195df77d56d9863b3b38e4c1f75dc54bf0138dd.tar.bz2 webtrees-e195df77d56d9863b3b38e4c1f75dc54bf0138dd.zip | |
webuni/commonmark-table-extension issue #12 now resolved so can upgrade to the latest league/commonmark
Diffstat (limited to 'vendor/league/commonmark/src')
60 files changed, 596 insertions, 494 deletions
diff --git a/vendor/league/commonmark/src/Block/Element/AbstractBlock.php b/vendor/league/commonmark/src/Block/Element/AbstractBlock.php index 5738f8097e..cf764f5c33 100644 --- a/vendor/league/commonmark/src/Block/Element/AbstractBlock.php +++ b/vendor/league/commonmark/src/Block/Element/AbstractBlock.php @@ -135,7 +135,7 @@ abstract class AbstractBlock extends Node { // create paragraph container for line $context->addBlock(new Paragraph()); - $cursor->advanceToFirstNonSpace(); + $cursor->advanceToNextNonSpaceOrTab(); $context->getTip()->addLine($cursor->getRemainder()); } @@ -247,7 +247,7 @@ abstract class AbstractBlock extends Node public function finalize(ContextInterface $context, $endLineNumber) { if (!$this->open) { - return; // TODO: Throw AlreadyClosedException? + return; } $this->open = false; diff --git a/vendor/league/commonmark/src/Block/Element/BlockQuote.php b/vendor/league/commonmark/src/Block/Element/BlockQuote.php index c212653ac3..1d39dfe6e8 100644 --- a/vendor/league/commonmark/src/Block/Element/BlockQuote.php +++ b/vendor/league/commonmark/src/Block/Element/BlockQuote.php @@ -52,8 +52,8 @@ class BlockQuote extends AbstractBlock public function matchesNextLine(Cursor $cursor) { - if (!$cursor->isIndented() && $cursor->getFirstNonSpaceCharacter() === '>') { - $cursor->advanceToFirstNonSpace(); + if (!$cursor->isIndented() && $cursor->getNextNonSpaceCharacter() === '>') { + $cursor->advanceToNextNonSpaceOrTab(); $cursor->advance(); $cursor->advanceBySpaceOrTab(); diff --git a/vendor/league/commonmark/src/Block/Element/FencedCode.php b/vendor/league/commonmark/src/Block/Element/FencedCode.php index deb2f32446..a52bee81ab 100644 --- a/vendor/league/commonmark/src/Block/Element/FencedCode.php +++ b/vendor/league/commonmark/src/Block/Element/FencedCode.php @@ -173,7 +173,7 @@ class FencedCode extends AbstractBlock } // Skip optional spaces of fence offset - $cursor->advanceWhileMatches(' ', $this->offset); + $cursor->match('/^ {0,' . $this->offset . '}/'); return true; } @@ -202,8 +202,8 @@ class FencedCode extends AbstractBlock $container = $context->getContainer(); // check for closing code fence - if ($cursor->getIndent() <= 3 && $cursor->getFirstNonSpaceCharacter() === $container->getChar()) { - $match = RegexHelper::matchAll('/^(?:`{3,}|~{3,})(?= *$)/', $cursor->getLine(), $cursor->getFirstNonSpacePosition()); + if ($cursor->getIndent() <= 3 && $cursor->getNextNonSpaceCharacter() === $container->getChar()) { + $match = RegexHelper::matchAll('/^(?:`{3,}|~{3,})(?= *$)/', $cursor->getLine(), $cursor->getNextNonSpacePosition()); if (strlen($match[0]) >= $container->getLength()) { // don't add closing fence to container; instead, close it: $this->setLength(-1); // -1 means we've passed closer diff --git a/vendor/league/commonmark/src/Block/Element/Heading.php b/vendor/league/commonmark/src/Block/Element/Heading.php index 94302edc46..c70c4e31f7 100644 --- a/vendor/league/commonmark/src/Block/Element/Heading.php +++ b/vendor/league/commonmark/src/Block/Element/Heading.php @@ -17,7 +17,7 @@ namespace League\CommonMark\Block\Element; use League\CommonMark\ContextInterface; use League\CommonMark\Cursor; -class Heading extends AbstractBlock implements InlineContainer +class Heading extends AbstractBlock implements InlineContainerInterface { /** * @var int diff --git a/vendor/league/commonmark/src/Block/Element/IndentedCode.php b/vendor/league/commonmark/src/Block/Element/IndentedCode.php index bf913a799a..23d996addf 100644 --- a/vendor/league/commonmark/src/Block/Element/IndentedCode.php +++ b/vendor/league/commonmark/src/Block/Element/IndentedCode.php @@ -56,7 +56,7 @@ class IndentedCode extends AbstractBlock if ($cursor->isIndented()) { $cursor->advanceBy(Cursor::INDENT_LEVEL, true); } elseif ($cursor->isBlank()) { - $cursor->advanceToFirstNonSpace(); + $cursor->advanceToNextNonSpaceOrTab(); } else { return false; } diff --git a/vendor/league/commonmark/src/Block/Element/InlineContainer.php b/vendor/league/commonmark/src/Block/Element/InlineContainer.php index fe0d984f7a..2b863d4924 100644 --- a/vendor/league/commonmark/src/Block/Element/InlineContainer.php +++ b/vendor/league/commonmark/src/Block/Element/InlineContainer.php @@ -2,7 +2,9 @@ namespace League\CommonMark\Block\Element; -interface InlineContainer +/** + * @deprecated Use InlineContainerInterface instead + */ +interface InlineContainer extends InlineContainerInterface { - public function getStringContent(); } diff --git a/vendor/league/commonmark/src/Block/Element/InlineContainerInterface.php b/vendor/league/commonmark/src/Block/Element/InlineContainerInterface.php new file mode 100644 index 0000000000..cd58782115 --- /dev/null +++ b/vendor/league/commonmark/src/Block/Element/InlineContainerInterface.php @@ -0,0 +1,8 @@ +<?php + +namespace League\CommonMark\Block\Element; + +interface InlineContainerInterface +{ + public function getStringContent(); +} diff --git a/vendor/league/commonmark/src/Block/Element/ListItem.php b/vendor/league/commonmark/src/Block/Element/ListItem.php index 902e832857..2da2c7d81e 100644 --- a/vendor/league/commonmark/src/Block/Element/ListItem.php +++ b/vendor/league/commonmark/src/Block/Element/ListItem.php @@ -69,7 +69,7 @@ class ListItem extends AbstractBlock return false; } - $cursor->advanceToFirstNonSpace(); + $cursor->advanceToNextNonSpaceOrTab(); } elseif ($cursor->getIndent() >= $this->listData->markerOffset + $this->listData->padding) { $cursor->advanceBy($this->listData->markerOffset + $this->listData->padding, true); } else { diff --git a/vendor/league/commonmark/src/Block/Element/Paragraph.php b/vendor/league/commonmark/src/Block/Element/Paragraph.php index f5c9fb745c..c5b84c9a66 100644 --- a/vendor/league/commonmark/src/Block/Element/Paragraph.php +++ b/vendor/league/commonmark/src/Block/Element/Paragraph.php @@ -17,7 +17,7 @@ namespace League\CommonMark\Block\Element; use League\CommonMark\ContextInterface; use League\CommonMark\Cursor; -class Paragraph extends AbstractBlock implements InlineContainer +class Paragraph extends AbstractBlock implements InlineContainerInterface { /** * Returns true if this block can contain the given block as a child node @@ -107,7 +107,7 @@ class Paragraph extends AbstractBlock implements InlineContainer */ public function handleRemainingContents(ContextInterface $context, Cursor $cursor) { - $cursor->advanceToFirstNonSpace(); + $cursor->advanceToNextNonSpaceOrTab(); $context->getTip()->addLine($cursor->getRemainder()); } } diff --git a/vendor/league/commonmark/src/Block/Parser/ATXHeadingParser.php b/vendor/league/commonmark/src/Block/Parser/ATXHeadingParser.php index f456e32176..4e26804d0e 100644 --- a/vendor/league/commonmark/src/Block/Parser/ATXHeadingParser.php +++ b/vendor/league/commonmark/src/Block/Parser/ATXHeadingParser.php @@ -33,19 +33,19 @@ class ATXHeadingParser extends AbstractBlockParser return false; } - $match = RegexHelper::matchAll('/^#{1,6}(?:[ \t]+|$)/', $cursor->getLine(), $cursor->getFirstNonSpacePosition()); + $match = RegexHelper::matchAll('/^#{1,6}(?:[ \t]+|$)/', $cursor->getLine(), $cursor->getNextNonSpacePosition()); if (!$match) { return false; } - $cursor->advanceToFirstNonSpace(); + $cursor->advanceToNextNonSpaceOrTab(); $cursor->advanceBy(strlen($match[0])); $level = strlen(trim($match[0])); $str = $cursor->getRemainder(); - $str = preg_replace('/^ *#+ *$/', '', $str); - $str = preg_replace('/ +#+ *$/', '', $str); + $str = preg_replace('/^[ \t]*#+[ \t]*$/', '', $str); + $str = preg_replace('/[ \t]+#+[ \t]*$/', '', $str); $context->addBlock(new Heading($level, $str)); $context->setBlocksParsed(true); diff --git a/vendor/league/commonmark/src/Block/Parser/BlockQuoteParser.php b/vendor/league/commonmark/src/Block/Parser/BlockQuoteParser.php index c7615af315..62342246ab 100644 --- a/vendor/league/commonmark/src/Block/Parser/BlockQuoteParser.php +++ b/vendor/league/commonmark/src/Block/Parser/BlockQuoteParser.php @@ -32,11 +32,11 @@ class BlockQuoteParser extends AbstractBlockParser return false; } - if ($cursor->getFirstNonSpaceCharacter() !== '>') { + if ($cursor->getNextNonSpaceCharacter() !== '>') { return false; } - $cursor->advanceToFirstNonSpace(); + $cursor->advanceToNextNonSpaceOrTab(); $cursor->advance(); $cursor->advanceBySpaceOrTab(); diff --git a/vendor/league/commonmark/src/Block/Parser/FencedCodeParser.php b/vendor/league/commonmark/src/Block/Parser/FencedCodeParser.php index d87681b171..d27abb2b8a 100644 --- a/vendor/league/commonmark/src/Block/Parser/FencedCodeParser.php +++ b/vendor/league/commonmark/src/Block/Parser/FencedCodeParser.php @@ -32,16 +32,14 @@ class FencedCodeParser extends AbstractBlockParser return false; } - $previousState = $cursor->saveState(); - $indent = $cursor->advanceToFirstNonSpace(); - $fence = $cursor->match('/^`{3,}(?!.*`)|^~{3,}(?!.*~)/'); + $indent = $cursor->getIndent(); + $fence = $cursor->match('/^[ \t]*(?:`{3,}(?!.*`)|^~{3,}(?!.*~))/'); if (is_null($fence)) { - $cursor->restoreState($previousState); - return false; } // fenced code block + $fence = ltrim($fence, " \t"); $fenceLength = strlen($fence); $context->addBlock(new FencedCode($fenceLength, $fence[0], $indent)); diff --git a/vendor/league/commonmark/src/Block/Parser/HtmlBlockParser.php b/vendor/league/commonmark/src/Block/Parser/HtmlBlockParser.php index 3eab228a84..4ac9b50c91 100644 --- a/vendor/league/commonmark/src/Block/Parser/HtmlBlockParser.php +++ b/vendor/league/commonmark/src/Block/Parser/HtmlBlockParser.php @@ -34,13 +34,13 @@ class HtmlBlockParser extends AbstractBlockParser return false; } - if ($cursor->getFirstNonSpaceCharacter() !== '<') { + if ($cursor->getNextNonSpaceCharacter() !== '<') { return false; } $savedState = $cursor->saveState(); - $cursor->advanceToFirstNonSpace(); + $cursor->advanceToNextNonSpaceOrTab(); $line = $cursor->getRemainder(); for ($blockType = 1; $blockType <= 7; $blockType++) { diff --git a/vendor/league/commonmark/src/Block/Parser/ListParser.php b/vendor/league/commonmark/src/Block/Parser/ListParser.php index 5255e678af..131699837a 100644 --- a/vendor/league/commonmark/src/Block/Parser/ListParser.php +++ b/vendor/league/commonmark/src/Block/Parser/ListParser.php @@ -37,27 +37,27 @@ class ListParser extends AbstractBlockParser } $tmpCursor = clone $cursor; - $tmpCursor->advanceToFirstNonSpace(); + $tmpCursor->advanceToNextNonSpaceOrTab(); $rest = $tmpCursor->getRemainder(); $data = new ListData(); $data->markerOffset = $cursor->getIndent(); - if ($matches = RegexHelper::matchAll('/^[*+-]/', $rest)) { + if (preg_match('/^[*+-]/', $rest) === 1) { $data->type = ListBlock::TYPE_UNORDERED; $data->delimiter = null; - $data->bulletChar = $matches[0][0]; + $data->bulletChar = $rest[0]; + $markerLength = 1; } elseif (($matches = RegexHelper::matchAll('/^(\d{1,9})([.)])/', $rest)) && (!($context->getContainer() instanceof Paragraph) || $matches[1] === '1')) { $data->type = ListBlock::TYPE_ORDERED; - $data->start = intval($matches[1]); + $data->start = (int) $matches[1]; $data->delimiter = $matches[2]; $data->bulletChar = null; + $markerLength = strlen($matches[0]); } else { return false; } - $markerLength = strlen($matches[0]); - // Make sure we have spaces after $nextChar = $tmpCursor->peek($markerLength); if (!($nextChar === null || $nextChar === "\t" || $nextChar === ' ')) { @@ -65,18 +65,18 @@ class ListParser extends AbstractBlockParser } // If it interrupts paragraph, make sure first line isn't blank - if ($context->getContainer() instanceof Paragraph && !RegexHelper::matchAt(RegexHelper::REGEX_NON_SPACE, $rest, $markerLength)) { + $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->advanceToFirstNonSpace(); // to start of marker + $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 - $container = $context->getContainer(); - if (!$container || !($context->getContainer() instanceof ListBlock) || !$data->equals($container->getListData())) { + if (!$container || !($container instanceof ListBlock) || !$data->equals($container->getListData())) { $context->addBlock(new ListBlock($data)); } diff --git a/vendor/league/commonmark/src/Block/Parser/SetExtHeadingParser.php b/vendor/league/commonmark/src/Block/Parser/SetExtHeadingParser.php index 23de37063c..56ad1fd765 100644 --- a/vendor/league/commonmark/src/Block/Parser/SetExtHeadingParser.php +++ b/vendor/league/commonmark/src/Block/Parser/SetExtHeadingParser.php @@ -38,7 +38,7 @@ class SetExtHeadingParser extends AbstractBlockParser return false; } - $match = RegexHelper::matchAll('/^(?:=+|-+)[ \t]*$/', $cursor->getLine(), $cursor->getFirstNonSpacePosition()); + $match = RegexHelper::matchAll('/^(?:=+|-+)[ \t]*$/', $cursor->getLine(), $cursor->getNextNonSpacePosition()); if ($match === null) { return false; } diff --git a/vendor/league/commonmark/src/Block/Parser/ThematicBreakParser.php b/vendor/league/commonmark/src/Block/Parser/ThematicBreakParser.php index 6b81e5304c..09ad7dcdf0 100644 --- a/vendor/league/commonmark/src/Block/Parser/ThematicBreakParser.php +++ b/vendor/league/commonmark/src/Block/Parser/ThematicBreakParser.php @@ -33,7 +33,7 @@ class ThematicBreakParser extends AbstractBlockParser return false; } - $match = RegexHelper::matchAt(RegexHelper::getInstance()->getThematicBreakRegex(), $cursor->getLine(), $cursor->getFirstNonSpacePosition()); + $match = RegexHelper::matchAt(RegexHelper::REGEX_THEMATIC_BREAK, $cursor->getLine(), $cursor->getNextNonSpacePosition()); if ($match === null) { return false; } diff --git a/vendor/league/commonmark/src/Block/Renderer/BlockQuoteRenderer.php b/vendor/league/commonmark/src/Block/Renderer/BlockQuoteRenderer.php index e2dbf5f26e..e35285c889 100644 --- a/vendor/league/commonmark/src/Block/Renderer/BlockQuoteRenderer.php +++ b/vendor/league/commonmark/src/Block/Renderer/BlockQuoteRenderer.php @@ -18,6 +18,7 @@ use League\CommonMark\Block\Element\AbstractBlock; use League\CommonMark\Block\Element\BlockQuote; use League\CommonMark\ElementRendererInterface; use League\CommonMark\HtmlElement; +use League\CommonMark\Util\Xml; class BlockQuoteRenderer implements BlockRendererInterface { @@ -36,7 +37,7 @@ class BlockQuoteRenderer implements BlockRendererInterface $attrs = []; foreach ($block->getData('attributes', []) as $key => $value) { - $attrs[$key] = $htmlRenderer->escape($value, true); + $attrs[$key] = Xml::escape($value, true); } $filling = $htmlRenderer->renderBlocks($block->children()); diff --git a/vendor/league/commonmark/src/Block/Renderer/FencedCodeRenderer.php b/vendor/league/commonmark/src/Block/Renderer/FencedCodeRenderer.php index 6dee2774be..c018bebce8 100644 --- a/vendor/league/commonmark/src/Block/Renderer/FencedCodeRenderer.php +++ b/vendor/league/commonmark/src/Block/Renderer/FencedCodeRenderer.php @@ -18,6 +18,7 @@ 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; class FencedCodeRenderer implements BlockRendererInterface { @@ -36,19 +37,19 @@ class FencedCodeRenderer implements BlockRendererInterface $attrs = []; foreach ($block->getData('attributes', []) as $key => $value) { - $attrs[$key] = $htmlRenderer->escape($value, true); + $attrs[$key] = Xml::escape($value, true); } $infoWords = $block->getInfoWords(); if (count($infoWords) !== 0 && strlen($infoWords[0]) !== 0) { $attrs['class'] = isset($attrs['class']) ? $attrs['class'] . ' ' : ''; - $attrs['class'] .= 'language-' . $htmlRenderer->escape($infoWords[0], true); + $attrs['class'] .= 'language-' . Xml::escape($infoWords[0], true); } return new HtmlElement( 'pre', [], - new HtmlElement('code', $attrs, $htmlRenderer->escape($block->getStringContent())) + new HtmlElement('code', $attrs, Xml::escape($block->getStringContent())) ); } } diff --git a/vendor/league/commonmark/src/Block/Renderer/HeadingRenderer.php b/vendor/league/commonmark/src/Block/Renderer/HeadingRenderer.php index 4f666898ec..0a09c290a5 100644 --- a/vendor/league/commonmark/src/Block/Renderer/HeadingRenderer.php +++ b/vendor/league/commonmark/src/Block/Renderer/HeadingRenderer.php @@ -18,6 +18,7 @@ use League\CommonMark\Block\Element\AbstractBlock; use League\CommonMark\Block\Element\Heading; use League\CommonMark\ElementRendererInterface; use League\CommonMark\HtmlElement; +use League\CommonMark\Util\Xml; class HeadingRenderer implements BlockRendererInterface { @@ -38,7 +39,7 @@ class HeadingRenderer implements BlockRendererInterface $attrs = []; foreach ($block->getData('attributes', []) as $key => $value) { - $attrs[$key] = $htmlRenderer->escape($value, true); + $attrs[$key] = Xml::escape($value, true); } return new HtmlElement($tag, $attrs, $htmlRenderer->renderInlines($block->children())); diff --git a/vendor/league/commonmark/src/Block/Renderer/IndentedCodeRenderer.php b/vendor/league/commonmark/src/Block/Renderer/IndentedCodeRenderer.php index b065fd122c..b514625b12 100644 --- a/vendor/league/commonmark/src/Block/Renderer/IndentedCodeRenderer.php +++ b/vendor/league/commonmark/src/Block/Renderer/IndentedCodeRenderer.php @@ -18,6 +18,7 @@ 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; class IndentedCodeRenderer implements BlockRendererInterface { @@ -36,13 +37,13 @@ class IndentedCodeRenderer implements BlockRendererInterface $attrs = []; foreach ($block->getData('attributes', []) as $key => $value) { - $attrs[$key] = $htmlRenderer->escape($value, true); + $attrs[$key] = Xml::escape($value, true); } return new HtmlElement( 'pre', [], - new HtmlElement('code', $attrs, $htmlRenderer->escape($block->getStringContent())) + new HtmlElement('code', $attrs, Xml::escape($block->getStringContent())) ); } } diff --git a/vendor/league/commonmark/src/Block/Renderer/ListBlockRenderer.php b/vendor/league/commonmark/src/Block/Renderer/ListBlockRenderer.php index 9d4e3681fb..f8dac9d07d 100644 --- a/vendor/league/commonmark/src/Block/Renderer/ListBlockRenderer.php +++ b/vendor/league/commonmark/src/Block/Renderer/ListBlockRenderer.php @@ -18,6 +18,7 @@ use League\CommonMark\Block\Element\AbstractBlock; use League\CommonMark\Block\Element\ListBlock; use League\CommonMark\ElementRendererInterface; use League\CommonMark\HtmlElement; +use League\CommonMark\Util\Xml; class ListBlockRenderer implements BlockRendererInterface { @@ -40,7 +41,7 @@ class ListBlockRenderer implements BlockRendererInterface $attrs = []; foreach ($block->getData('attributes', []) as $key => $value) { - $attrs[$key] = $htmlRenderer->escape($value, true); + $attrs[$key] = Xml::escape($value, true); } if ($listData->start !== null && $listData->start !== 1) { diff --git a/vendor/league/commonmark/src/Block/Renderer/ListItemRenderer.php b/vendor/league/commonmark/src/Block/Renderer/ListItemRenderer.php index e8c340e7e4..6f7c21b175 100644 --- a/vendor/league/commonmark/src/Block/Renderer/ListItemRenderer.php +++ b/vendor/league/commonmark/src/Block/Renderer/ListItemRenderer.php @@ -18,6 +18,7 @@ use League\CommonMark\Block\Element\AbstractBlock; use League\CommonMark\Block\Element\ListItem; use League\CommonMark\ElementRendererInterface; use League\CommonMark\HtmlElement; +use League\CommonMark\Util\Xml; class ListItemRenderer implements BlockRendererInterface { @@ -44,7 +45,7 @@ class ListItemRenderer implements BlockRendererInterface $attrs = []; foreach ($block->getData('attributes', []) as $key => $value) { - $attrs[$key] = $htmlRenderer->escape($value, true); + $attrs[$key] = Xml::escape($value, true); } $li = new HtmlElement('li', $attrs, $contents); diff --git a/vendor/league/commonmark/src/Block/Renderer/ParagraphRenderer.php b/vendor/league/commonmark/src/Block/Renderer/ParagraphRenderer.php index a221f29121..b6d2fa1dcb 100644 --- a/vendor/league/commonmark/src/Block/Renderer/ParagraphRenderer.php +++ b/vendor/league/commonmark/src/Block/Renderer/ParagraphRenderer.php @@ -18,6 +18,7 @@ use League\CommonMark\Block\Element\AbstractBlock; use League\CommonMark\Block\Element\Paragraph; use League\CommonMark\ElementRendererInterface; use League\CommonMark\HtmlElement; +use League\CommonMark\Util\Xml; class ParagraphRenderer implements BlockRendererInterface { @@ -36,13 +37,13 @@ class ParagraphRenderer implements BlockRendererInterface if ($inTightList) { return $htmlRenderer->renderInlines($block->children()); - } else { - $attrs = []; - foreach ($block->getData('attributes', []) as $key => $value) { - $attrs[$key] = $htmlRenderer->escape($value, true); - } + } - return new HtmlElement('p', $attrs, $htmlRenderer->renderInlines($block->children())); + $attrs = []; + foreach ($block->getData('attributes', []) as $key => $value) { + $attrs[$key] = Xml::escape($value, true); } + + return new HtmlElement('p', $attrs, $htmlRenderer->renderInlines($block->children())); } } diff --git a/vendor/league/commonmark/src/Block/Renderer/ThematicBreakRenderer.php b/vendor/league/commonmark/src/Block/Renderer/ThematicBreakRenderer.php index c92e5de074..d83da36fa3 100644 --- a/vendor/league/commonmark/src/Block/Renderer/ThematicBreakRenderer.php +++ b/vendor/league/commonmark/src/Block/Renderer/ThematicBreakRenderer.php @@ -18,6 +18,7 @@ use League\CommonMark\Block\Element\AbstractBlock; use League\CommonMark\Block\Element\ThematicBreak; use League\CommonMark\ElementRendererInterface; use League\CommonMark\HtmlElement; +use League\CommonMark\Util\Xml; class ThematicBreakRenderer implements BlockRendererInterface { @@ -36,7 +37,7 @@ class ThematicBreakRenderer implements BlockRendererInterface $attrs = []; foreach ($block->getData('attributes', []) as $key => $value) { - $attrs[$key] = $htmlRenderer->escape($value, true); + $attrs[$key] = Xml::escape($value, true); } return new HtmlElement('hr', $attrs, '', true); diff --git a/vendor/league/commonmark/src/Cursor.php b/vendor/league/commonmark/src/Cursor.php index e4252e6c6f..7de36dfab3 100644 --- a/vendor/league/commonmark/src/Cursor.php +++ b/vendor/league/commonmark/src/Cursor.php @@ -51,7 +51,7 @@ class Cursor /** * @var int|null */ - private $firstNonSpaceCache; + private $nextNonSpaceCache; /** * @var bool @@ -59,23 +59,41 @@ class Cursor private $partiallyConsumedTab = false; /** + * @var string + */ + private $encoding; + + /** + * @var bool + */ + private $lineContainsTabs; + + /** + * @var bool + */ + private $isMultibyte; + + /** * @param string $line */ public function __construct($line) { $this->line = $line; - $this->length = mb_strlen($line, 'utf-8'); + $this->encoding = mb_detect_encoding($line, 'ASCII,UTF-8', true) ?: 'ISO-8859-1'; + $this->length = mb_strlen($line, $this->encoding); + $this->isMultibyte = $this->length !== strlen($line); + $this->lineContainsTabs = preg_match('/\t/', $line) > 0; } /** - * Returns the position of the next non-space character + * Returns the position of the next character which is not a space (or tab) * * @return int */ - public function getFirstNonSpacePosition() + public function getNextNonSpacePosition() { - if ($this->firstNonSpaceCache !== null) { - return $this->firstNonSpaceCache; + if ($this->nextNonSpaceCache !== null) { + return $this->nextNonSpaceCache; } $i = $this->currentPosition; @@ -96,17 +114,17 @@ class Cursor $nextNonSpace = ($c === null) ? $this->length : $i; $this->indent = $cols - $this->column; - return $this->firstNonSpaceCache = $nextNonSpace; + return $this->nextNonSpaceCache = $nextNonSpace; } /** - * Returns the next character which isn't a space + * Returns the next character which isn't a space (or tab) * * @return string */ - public function getFirstNonSpaceCharacter() + public function getNextNonSpaceCharacter() { - return $this->getCharacter($this->getFirstNonSpacePosition()); + return $this->getCharacter($this->getNextNonSpacePosition()); } /** @@ -116,7 +134,7 @@ class Cursor */ public function getIndent() { - $this->getFirstNonSpacePosition(); + $this->getNextNonSpacePosition(); return $this->indent; } @@ -128,7 +146,9 @@ class Cursor */ public function isIndented() { - return $this->getIndent() >= self::INDENT_LEVEL; + $this->getNextNonSpacePosition(); + + return $this->indent >= self::INDENT_LEVEL; } /** @@ -147,7 +167,7 @@ class Cursor return; } - return mb_substr($this->line, $index, 1, 'utf-8'); + return mb_substr($this->line, $index, 1, $this->encoding); } /** @@ -169,7 +189,7 @@ class Cursor */ public function isBlank() { - return $this->getFirstNonSpacePosition() === $this->length; + return $this->getNextNonSpacePosition() === $this->length; } /** @@ -183,14 +203,32 @@ class Cursor /** * Move the cursor forwards * - * @param int $characters Number of characters to advance by + * @param int $characters Number of characters to advance by + * @param bool $advanceByColumns Whether to advance by columns instead of spaces */ public function advanceBy($characters, $advanceByColumns = false) { + if ($characters === 0) { + $this->previousPosition = $this->currentPosition; + + return; + } + $this->previousPosition = $this->currentPosition; - $this->firstNonSpaceCache = null; + $this->nextNonSpaceCache = null; + + $nextFewChars = mb_substr($this->line, $this->currentPosition, $characters, $this->encoding); + + // Optimization to avoid tab handling logic if we have no tabs + if (!$this->lineContainsTabs || preg_match('/\t/', $nextFewChars) === 0) { + $length = min($characters, $this->length - $this->currentPosition); + $this->partiallyConsumedTab = false; + $this->currentPosition += $length; + $this->column += $length; + + return; + } - $nextFewChars = mb_substr($this->line, $this->currentPosition, $characters, 'utf-8'); if ($characters === 1 && !empty($nextFewChars)) { $asArray = [$nextFewChars]; } else { @@ -200,11 +238,18 @@ class Cursor foreach ($asArray as $relPos => $c) { if ($c === "\t") { $charsToTab = 4 - ($this->column % 4); - $this->partiallyConsumedTab = $advanceByColumns && $charsToTab > $characters; - $charsToAdvance = $charsToTab > $characters ? $characters : $charsToTab; - $this->column += $charsToAdvance; - $this->currentPosition += $this->partiallyConsumedTab ? 0 : 1; - $characters -= $charsToAdvance; + if ($advanceByColumns) { + $this->partiallyConsumedTab = $charsToTab > $characters; + $charsToAdvance = $charsToTab > $characters ? $characters : $charsToTab; + $this->column += $charsToAdvance; + $this->currentPosition += $this->partiallyConsumedTab ? 0 : 1; + $characters -= $charsToAdvance; + } else { + $this->partiallyConsumedTab = false; + $this->column += $charsToTab; + $this->currentPosition++; + $characters--; + } } else { $this->partiallyConsumedTab = false; $this->currentPosition++; @@ -237,43 +282,27 @@ class Cursor } /** - * Advances the cursor while the given character is matched - * - * @param string $character Character to match - * @param int|null $maximumCharactersToAdvance Maximum number of characters to advance before giving up + * Parse zero or more space/tab characters * - * @return int Number of positions moved (0 if unsuccessful) + * @return int Number of positions moved */ - public function advanceWhileMatches($character, $maximumCharactersToAdvance = null) + public function advanceToNextNonSpaceOrTab() { - // Calculate how far to advance - $start = $this->currentPosition; - $newIndex = $start; - if ($maximumCharactersToAdvance === null) { - $maximumCharactersToAdvance = $this->length; - } - - $max = min($start + $maximumCharactersToAdvance, $this->length); - - while ($newIndex < $max && $this->getCharacter($newIndex) === $character) { - ++$newIndex; - } - - if ($newIndex <= $start) { - return 0; - } - - $this->advanceBy($newIndex - $start); + $newPosition = $this->getNextNonSpacePosition(); + $this->advanceBy($newPosition - $this->currentPosition); + $this->partiallyConsumedTab = false; return $this->currentPosition - $this->previousPosition; } /** - * Parse zero or more space characters, including at most one newline + * Parse zero or more space characters, including at most one newline. + * + * Tab characters are not parsed with this function. * * @return int Number of positions moved */ - public function advanceToFirstNonSpace() + public function advanceToNextNonSpaceOrNewline() { $matches = []; preg_match('/^ *(?:\n *)?/', $this->getRemainder(), $matches, PREG_OFFSET_CAPTURE); @@ -299,7 +328,7 @@ class Cursor public function advanceToEnd() { $this->previousPosition = $this->currentPosition; - $this->firstNonSpaceCache = null; + $this->nextNonSpaceCache = null; $this->currentPosition = $this->length; @@ -311,7 +340,7 @@ class Cursor */ public function getRemainder() { - if ($this->isAtEnd()) { + if ($this->currentPosition >= $this->length) { return ''; } @@ -323,7 +352,7 @@ class Cursor $prefix = str_repeat(' ', $charsToTab); } - return $prefix . mb_substr($this->line, $position, null, 'utf-8'); + return $prefix . mb_substr($this->line, $position, null, $this->encoding); } /** @@ -355,51 +384,65 @@ class Cursor { $subject = $this->getRemainder(); - $matches = []; if (!preg_match($regex, $subject, $matches, PREG_OFFSET_CAPTURE)) { return; } - // PREG_OFFSET_CAPTURE always returns the byte offset, not the char offset, which is annoying - $offset = mb_strlen(mb_strcut($subject, 0, $matches[0][1], 'utf-8'), 'utf-8'); + // $matches[0][0] contains the matched text + // $matches[0][1] contains the index of that match + + if ($this->isMultibyte) { + // PREG_OFFSET_CAPTURE always returns the byte offset, not the char offset, which is annoying + $offset = mb_strlen(mb_strcut($subject, 0, $matches[0][1], $this->encoding), $this->encoding); + } else { + $offset = $matches[0][1]; + } // [0][0] contains the matched text // [0][1] contains the index of that match - $this->advanceBy($offset + mb_strlen($matches[0][0], 'utf-8')); + $this->advanceBy($offset + mb_strlen($matches[0][0], $this->encoding)); return $matches[0][0]; } /** - * @return CursorState + * Encapsulates the current state of this cursor in case you need to rollback later. + * + * WARNING: Do not parse or use the return value for ANYTHING except for + * passing it back into restoreState(), as the number of values and their + * contents may change in any future release without warning. + * + * @return array */ public function saveState() { - return new CursorState( - $this->line, - $this->length, + return [ $this->currentPosition, $this->previousPosition, - $this->firstNonSpaceCache, + $this->nextNonSpaceCache, $this->indent, $this->column, - $this->partiallyConsumedTab - ); + $this->partiallyConsumedTab, + ]; } /** - * @param CursorState $state + * Restore the cursor to a previous state. + * + * Pass in the value previously obtained by calling saveState(). + * + * @param array $state */ - public function restoreState(CursorState $state) + public function restoreState($state) { - $this->line = $state->getLine(); - $this->length = $state->getLength(); - $this->currentPosition = $state->getCurrentPosition(); - $this->previousPosition = $state->getPreviousPosition(); - $this->firstNonSpaceCache = $state->getFirstNonSpaceCache(); - $this->column = $state->getColumn(); - $this->indent = $state->getIndent(); - $this->partiallyConsumedTab = $state->getPartiallyConsumedTab(); + list( + $this->currentPosition, + $this->previousPosition, + $this->nextNonSpaceCache, + $this->indent, + $this->column, + $this->partiallyConsumedTab, + ) = $state; } /** @@ -415,7 +458,7 @@ class Cursor */ public function getPreviousText() { - return mb_substr($this->line, $this->previousPosition, $this->currentPosition - $this->previousPosition, 'utf-8'); + return mb_substr($this->line, $this->previousPosition, $this->currentPosition - $this->previousPosition, $this->encoding); } /** diff --git a/vendor/league/commonmark/src/CursorState.php b/vendor/league/commonmark/src/CursorState.php deleted file mode 100644 index a70091e4b4..0000000000 --- a/vendor/league/commonmark/src/CursorState.php +++ /dev/null @@ -1,141 +0,0 @@ -<?php - -/* - * This file is part of the league/commonmark package. - * - * (c) Colin O'Dell <colinodell@gmail.com> - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace League\CommonMark; - -class CursorState -{ - /** - * @var string - */ - private $line; - - /** - * @var int - */ - private $length; - - /** - * @var int - */ - private $currentPosition; - - /** - * @var int - */ - private $previousPosition; - - /** - * @var int|null - */ - private $firstNonSpaceCache; - - /** - * @var int - */ - private $indent; - - /** - * @var int - */ - private $column; - - /** - * @var bool - */ - private $partiallyConsumedTab; - - /** - * @param string $line - * @param int $length - * @param int $currentPosition - * @param int $previousPosition - * @param int|null $firstNonSpaceCache - * @param int $indent - * @param int $column - * @param bool $partiallyConsumedTab - */ - public function __construct($line, $length, $currentPosition, $previousPosition, $firstNonSpaceCache, $indent, $column, $partiallyConsumedTab) - { - $this->line = $line; - $this->length = $length; - $this->currentPosition = $currentPosition; - $this->previousPosition = $previousPosition; - $this->firstNonSpaceCache = $firstNonSpaceCache; - $this->indent = $indent; - $this->column = $column; - $this->partiallyConsumedTab = $partiallyConsumedTab; - } - - /** - * @return int - */ - public function getCurrentPosition() - { - return $this->currentPosition; - } - - /** - * @return int - */ - public function getLength() - { - return $this->length; - } - - /** - * @return string - */ - public function getLine() - { - return $this->line; - } - - /** - * @return int - */ - public function getPreviousPosition() - { - return $this->previousPosition; - } - - /** - * @return int|null - */ - public function getFirstNonSpaceCache() - { - return $this->firstNonSpaceCache; - } - - /** - * @return int - */ - public function getIndent() - { - return $this->indent; - } - - /** - * @return int - */ - public function getColumn() - { - return $this->column; - } - - /** - * @return bool - */ - public function getPartiallyConsumedTab() - { - return $this->partiallyConsumedTab; - } -} diff --git a/vendor/league/commonmark/src/Delimiter/Delimiter.php b/vendor/league/commonmark/src/Delimiter/Delimiter.php index 66ce8296ea..b58a9d2657 100644 --- a/vendor/league/commonmark/src/Delimiter/Delimiter.php +++ b/vendor/league/commonmark/src/Delimiter/Delimiter.php @@ -24,6 +24,9 @@ class Delimiter /** @var int */ protected $numDelims; + /** @var int */ + protected $origDelims; + /** @var Node */ protected $inlineNode; @@ -57,6 +60,7 @@ class Delimiter { $this->char = $char; $this->numDelims = $numDelims; + $this->origDelims = $numDelims; $this->inlineNode = $node; $this->canOpen = $canOpen; $this->canClose = $canClose; @@ -205,6 +209,14 @@ class Delimiter } /** + * @return int + */ + public function getOrigDelims() + { + return $this->origDelims; + } + + /** * @return Node */ public function getInlineNode() diff --git a/vendor/league/commonmark/src/Delimiter/DelimiterStack.php b/vendor/league/commonmark/src/Delimiter/DelimiterStack.php index 9a49d146dd..c7e06ede10 100644 --- a/vendor/league/commonmark/src/Delimiter/DelimiterStack.php +++ b/vendor/league/commonmark/src/Delimiter/DelimiterStack.php @@ -175,7 +175,7 @@ class DelimiterStack $opener = $closer->getPrevious(); while ($opener !== null && $opener !== $stackBottom && $opener !== $openersBottom[$closerChar]) { - $oddMatch = ($closer->canOpen() || $opener->canClose()) && ($opener->getNumDelims() + $closer->getNumDelims()) % 3 === 0; + $oddMatch = ($closer->canOpen() || $opener->canClose()) && ($opener->getOrigDelims() + $closer->getOrigDelims()) % 3 === 0; if ($opener->getChar() === $closerChar && $opener->canOpen() && !$oddMatch) { return $opener; } @@ -183,27 +183,4 @@ class DelimiterStack $opener = $opener->getPrevious(); } } - - /** - * @param Delimiter $closer - * @param array $openersBottom - * @param Delimiter|null $stackBottom - * - * @return Delimiter|null - * - * @deprecated Use findMatchingOpener() instead. This method will be removed in the next major release. - */ - protected function findFirstMatchingOpener(Delimiter $closer, $openersBottom, Delimiter $stackBottom = null) - { - $closerChar = $closer->getChar(); - $opener = $closer->getPrevious(); - - while ($opener !== null && $opener !== $stackBottom && $opener !== $openersBottom[$closerChar]) { - if ($opener->getChar() === $closerChar && $opener->canOpen()) { - return $opener; - } - - $opener = $opener->getPrevious(); - } - } } diff --git a/vendor/league/commonmark/src/DocParser.php b/vendor/league/commonmark/src/DocParser.php index 7aa9cab0a2..d0e0c3d7ed 100644 --- a/vendor/league/commonmark/src/DocParser.php +++ b/vendor/league/commonmark/src/DocParser.php @@ -16,7 +16,7 @@ namespace League\CommonMark; use League\CommonMark\Block\Element\AbstractBlock; use League\CommonMark\Block\Element\Document; -use League\CommonMark\Block\Element\InlineContainer; +use League\CommonMark\Block\Element\InlineContainerInterface; use League\CommonMark\Block\Element\Paragraph; use League\CommonMark\Node\NodeWalker; @@ -33,12 +33,18 @@ class DocParser private $inlineParserEngine; /** + * @var int|float + */ + private $maxNestingLevel; + + /** * @param Environment $environment */ public function __construct(Environment $environment) { $this->environment = $environment; $this->inlineParserEngine = new InlineParserEngine($environment); + $this->maxNestingLevel = $environment->getConfig('max_nesting_level', INF); } /** @@ -83,8 +89,8 @@ class DocParser $this->incorporateLine($context); } - while ($context->getTip()) { - $context->getTip()->finalize($context, count($lines)); + while ($tip = $context->getTip()) { + $tip->finalize($context, count($lines)); } $this->processInlines($context, $context->getDocument()->walker()); @@ -128,7 +134,7 @@ class DocParser } elseif (!$cursor->isBlank()) { // Create paragraph container for line $context->addBlock(new Paragraph()); - $cursor->advanceToFirstNonSpace(); + $cursor->advanceToNextNonSpaceOrTab(); $context->getTip()->addLine($cursor->getRemainder()); } } @@ -142,13 +148,13 @@ class DocParser private function processInlines(ContextInterface $context, NodeWalker $walker) { - while (($event = $walker->next()) !== null) { + while ($event = $walker->next()) { if (!$event->isEntering()) { continue; } $node = $event->getNode(); - if ($node instanceof InlineContainer) { + if ($node instanceof InlineContainerInterface) { $this->inlineParserEngine->parse($node, $context->getDocument()->getReferenceMap()); } } @@ -162,20 +168,22 @@ class DocParser */ private function resetContainer(ContextInterface $context, Cursor $cursor) { - $context->setContainer($context->getDocument()); + $container = $context->getDocument(); - while ($context->getContainer()->hasChildren()) { - $lastChild = $context->getContainer()->lastChild(); + while ($container->hasChildren()) { + $lastChild = $container->lastChild(); if (!$lastChild->isOpen()) { break; } - $context->setContainer($lastChild); - if (!$context->getContainer()->matchesNextLine($cursor)) { - $context->setContainer($context->getContainer()->parent()); // back up to the last matching block + $container = $lastChild; + if (!$container->matchesNextLine($cursor)) { + $container = $container->parent(); // back up to the last matching block break; } } + + $context->setContainer($container); } /** @@ -195,8 +203,9 @@ class DocParser } } - if (!$parsed || $context->getContainer()->acceptsLines()) { + if (!$parsed || $context->getContainer()->acceptsLines() || $context->getTip()->getDepth() >= $this->maxNestingLevel) { $context->setBlocksParsed(true); + break; } } } @@ -219,15 +228,16 @@ class DocParser * @param ContextInterface $context * @param Cursor $cursor */ - private function setAndPropagateLastLineBlank(ContextInterface $context, $cursor) + private function setAndPropagateLastLineBlank(ContextInterface $context, Cursor $cursor) { - if ($cursor->isBlank() && $lastChild = $context->getContainer()->lastChild()) { + $container = $context->getContainer(); + + if ($cursor->isBlank() && $lastChild = $container->lastChild()) { if ($lastChild instanceof AbstractBlock) { $lastChild->setLastLineBlank(true); } } - $container = $context->getContainer(); $lastLineBlank = $container->shouldLastLineBeBlank($cursor, $context->getLineNumber()); // Propagate lastLineBlank up through parents: diff --git a/vendor/league/commonmark/src/ElementRendererInterface.php b/vendor/league/commonmark/src/ElementRendererInterface.php index 9101a44d78..54e577acbd 100644 --- a/vendor/league/commonmark/src/ElementRendererInterface.php +++ b/vendor/league/commonmark/src/ElementRendererInterface.php @@ -31,14 +31,6 @@ interface ElementRendererInterface public function getOption($option, $default = null); /** - * @param string $string - * @param bool $preserveEntities - * - * @return string - */ - public function escape($string, $preserveEntities = false); - - /** * @param AbstractInline[] $inlines * * @return string diff --git a/vendor/league/commonmark/src/Environment.php b/vendor/league/commonmark/src/Environment.php index 442e1ca299..c5ca1a1355 100644 --- a/vendor/league/commonmark/src/Environment.php +++ b/vendor/league/commonmark/src/Environment.php @@ -243,14 +243,14 @@ class Environment /** * @param string $character * - * @return InlineParserInterface[]|null + * @return InlineParserInterface[] */ public function getInlineParsersForCharacter($character) { $this->initializeExtensions(); if (!isset($this->inlineParsersByCharacter[$character])) { - return; + return []; } return $this->inlineParsersByCharacter[$character]; @@ -485,6 +485,7 @@ class Environment 'safe' => false, // deprecated option 'html_input' => self::HTML_INPUT_ALLOW, 'allow_unsafe_links' => true, + 'max_nesting_level' => INF, ]); return $environment; @@ -533,7 +534,7 @@ class Environment private function getMiscExtension() { $lastExtension = end($this->extensions); - if ($lastExtension !== false && $lastExtension instanceof MiscExtension) { + if ($lastExtension instanceof MiscExtension) { return $lastExtension; } diff --git a/vendor/league/commonmark/src/Extension/CommonMarkCoreExtension.php b/vendor/league/commonmark/src/Extension/CommonMarkCoreExtension.php index c9f47b589f..6a95023999 100644 --- a/vendor/league/commonmark/src/Extension/CommonMarkCoreExtension.php +++ b/vendor/league/commonmark/src/Extension/CommonMarkCoreExtension.php @@ -76,16 +76,16 @@ class CommonMarkCoreExtension extends Extension public function getBlockRenderers() { return [ - 'League\CommonMark\Block\Element\BlockQuote' => new BlockRenderer\BlockQuoteRenderer(), - 'League\CommonMark\Block\Element\Document' => new BlockRenderer\DocumentRenderer(), - 'League\CommonMark\Block\Element\FencedCode' => new BlockRenderer\FencedCodeRenderer(), - 'League\CommonMark\Block\Element\Heading' => new BlockRenderer\HeadingRenderer(), - 'League\CommonMark\Block\Element\HtmlBlock' => new BlockRenderer\HtmlBlockRenderer(), - 'League\CommonMark\Block\Element\IndentedCode' => new BlockRenderer\IndentedCodeRenderer(), - 'League\CommonMark\Block\Element\ListBlock' => new BlockRenderer\ListBlockRenderer(), - 'League\CommonMark\Block\Element\ListItem' => new BlockRenderer\ListItemRenderer(), - 'League\CommonMark\Block\Element\Paragraph' => new BlockRenderer\ParagraphRenderer(), - 'League\CommonMark\Block\Element\ThematicBreak' => new BlockRenderer\ThematicBreakRenderer(), + 'League\CommonMark\Block\Element\BlockQuote' => new BlockRenderer\BlockQuoteRenderer(), + 'League\CommonMark\Block\Element\Document' => new BlockRenderer\DocumentRenderer(), + 'League\CommonMark\Block\Element\FencedCode' => new BlockRenderer\FencedCodeRenderer(), + 'League\CommonMark\Block\Element\Heading' => new BlockRenderer\HeadingRenderer(), + 'League\CommonMark\Block\Element\HtmlBlock' => new BlockRenderer\HtmlBlockRenderer(), + 'League\CommonMark\Block\Element\IndentedCode' => new BlockRenderer\IndentedCodeRenderer(), + 'League\CommonMark\Block\Element\ListBlock' => new BlockRenderer\ListBlockRenderer(), + 'League\CommonMark\Block\Element\ListItem' => new BlockRenderer\ListItemRenderer(), + 'League\CommonMark\Block\Element\Paragraph' => new BlockRenderer\ParagraphRenderer(), + 'League\CommonMark\Block\Element\ThematicBreak' => new BlockRenderer\ThematicBreakRenderer(), ]; } diff --git a/vendor/league/commonmark/src/Extension/MiscExtension.php b/vendor/league/commonmark/src/Extension/MiscExtension.php index 0c3f730533..3feb791423 100644 --- a/vendor/league/commonmark/src/Extension/MiscExtension.php +++ b/vendor/league/commonmark/src/Extension/MiscExtension.php @@ -93,6 +93,8 @@ class MiscExtension implements ExtensionInterface public function addInlineParser(InlineParserInterface $inlineParser) { $this->inlineParsers[] = $inlineParser; + + return $this; } /** @@ -162,6 +164,8 @@ class MiscExtension implements ExtensionInterface } $this->blockRenderers[$blockClass] = $blockRenderer; + + return $this; } /** diff --git a/vendor/league/commonmark/src/HtmlElement.php b/vendor/league/commonmark/src/HtmlElement.php index 9dab1e9135..fee0e44059 100644 --- a/vendor/league/commonmark/src/HtmlElement.php +++ b/vendor/league/commonmark/src/HtmlElement.php @@ -107,7 +107,7 @@ class HtmlElement */ public function setContents($contents) { - $this->contents = !is_null($contents) ? $contents : ''; + $this->contents = $contents !== null ? $contents : ''; return $this; } @@ -124,7 +124,7 @@ class HtmlElement } if ($this->contents !== '') { - $result .= '>' . $this->getContents(true) . '</' . $this->tagName . '>'; + $result .= '>' . $this->getContents() . '</' . $this->tagName . '>'; } elseif ($this->selfClosing) { $result .= ' />'; } else { diff --git a/vendor/league/commonmark/src/HtmlRenderer.php b/vendor/league/commonmark/src/HtmlRenderer.php index b3a50f29a4..28bcdfe7e2 100644 --- a/vendor/league/commonmark/src/HtmlRenderer.php +++ b/vendor/league/commonmark/src/HtmlRenderer.php @@ -47,23 +47,6 @@ class HtmlRenderer implements ElementRendererInterface } /** - * @param string $string - * @param bool $preserveEntities - * - * @return string - */ - public function escape($string, $preserveEntities = false) - { - if ($preserveEntities) { - $string = preg_replace('/[&](?;|[a-z][a-z0-9]{1,31};)/i', '&', $string); - } else { - $string = str_replace('&', '&', $string); - } - - return str_replace(['<', '>', '"'], ['<', '>', '"'], $string); - } - - /** * @param AbstractInline $inline * * @throws \RuntimeException diff --git a/vendor/league/commonmark/src/Inline/Parser/BacktickParser.php b/vendor/league/commonmark/src/Inline/Parser/BacktickParser.php index 86ee79fc4a..6a16703ca5 100644 --- a/vendor/league/commonmark/src/Inline/Parser/BacktickParser.php +++ b/vendor/league/commonmark/src/Inline/Parser/BacktickParser.php @@ -43,11 +43,12 @@ class BacktickParser extends AbstractInlineParser return false; } + $currentPosition = $cursor->getPosition(); $previousState = $cursor->saveState(); while ($matchingTicks = $cursor->match('/`+/m')) { if ($matchingTicks === $ticks) { - $code = mb_substr($cursor->getLine(), $previousState->getCurrentPosition(), $cursor->getPosition() - $previousState->getCurrentPosition() - strlen($ticks), 'utf-8'); + $code = mb_substr($cursor->getLine(), $currentPosition, $cursor->getPosition() - $currentPosition - strlen($ticks), 'utf-8'); $c = preg_replace(RegexHelper::REGEX_WHITESPACE, ' ', $code); $inlineContext->getContainer()->appendChild(new Code(trim($c))); diff --git a/vendor/league/commonmark/src/Inline/Parser/CloseBracketParser.php b/vendor/league/commonmark/src/Inline/Parser/CloseBracketParser.php index 111b5258bd..2fa3ba1aef 100644 --- a/vendor/league/commonmark/src/Inline/Parser/CloseBracketParser.php +++ b/vendor/league/commonmark/src/Inline/Parser/CloseBracketParser.php @@ -150,14 +150,14 @@ class CloseBracketParser extends AbstractInlineParser implements EnvironmentAwar $previousState = $cursor->saveState(); $cursor->advance(); - $cursor->advanceToFirstNonSpace(); + $cursor->advanceToNextNonSpaceOrNewline(); if (($dest = LinkParserHelper::parseLinkDestination($cursor)) === null) { $cursor->restoreState($previousState); return false; } - $cursor->advanceToFirstNonSpace(); + $cursor->advanceToNextNonSpaceOrNewline(); $title = null; // make sure there's a space before the title: @@ -165,7 +165,7 @@ class CloseBracketParser extends AbstractInlineParser implements EnvironmentAwar $title = LinkParserHelper::parseLinkTitle($cursor) ?: ''; } - $cursor->advanceToFirstNonSpace(); + $cursor->advanceToNextNonSpaceOrNewline(); if ($cursor->match('/^\\)/') === null) { $cursor->restoreState($previousState); @@ -215,8 +215,8 @@ class CloseBracketParser extends AbstractInlineParser implements EnvironmentAwar { if ($isImage) { return new Image($url, null, $title); - } else { - return new Link($url, null, $title); } + + return new Link($url, null, $title); } } diff --git a/vendor/league/commonmark/src/Inline/Parser/EmphasisParser.php b/vendor/league/commonmark/src/Inline/Parser/EmphasisParser.php index f6d01dec11..72993e9457 100644 --- a/vendor/league/commonmark/src/Inline/Parser/EmphasisParser.php +++ b/vendor/league/commonmark/src/Inline/Parser/EmphasisParser.php @@ -29,10 +29,10 @@ class EmphasisParser extends AbstractInlineParser implements EnvironmentAwareInt public function __construct(array $newConfig = []) { $this->config = new Configuration([ - 'use_asterisk' => true, - 'use_underscore' => true, - 'enable_em' => true, - 'enable_strong' => true, + 'use_asterisk' => true, + 'use_underscore' => true, + 'enable_em' => true, + 'enable_strong' => true, ]); $this->config->mergeConfig($newConfig); } @@ -131,8 +131,8 @@ class EmphasisParser extends AbstractInlineParser implements EnvironmentAwareInt $beforeIsWhitespace = preg_match(RegexHelper::REGEX_UNICODE_WHITESPACE_CHAR, $charBefore); $beforeIsPunctuation = preg_match(RegexHelper::REGEX_PUNCTUATION, $charBefore); - $leftFlanking = !$afterIsWhitespace && !($afterIsPunctuation && !$beforeIsWhitespace && !$beforeIsPunctuation); - $rightFlanking = !$beforeIsWhitespace && !($beforeIsPunctuation && !$afterIsWhitespace && !$afterIsPunctuation); + $leftFlanking = !$afterIsWhitespace && (!$afterIsPunctuation || $beforeIsWhitespace || $beforeIsPunctuation); + $rightFlanking = !$beforeIsWhitespace && (!$beforeIsPunctuation || $afterIsWhitespace || $afterIsPunctuation); if ($character === '_') { $canOpen = $leftFlanking && (!$rightFlanking || $beforeIsPunctuation); diff --git a/vendor/league/commonmark/src/Inline/Parser/EntityParser.php b/vendor/league/commonmark/src/Inline/Parser/EntityParser.php index 577e7a5a78..242f9ab516 100644 --- a/vendor/league/commonmark/src/Inline/Parser/EntityParser.php +++ b/vendor/league/commonmark/src/Inline/Parser/EntityParser.php @@ -36,7 +36,7 @@ class EntityParser extends AbstractInlineParser */ public function parse(InlineParserContext $inlineContext) { - if ($m = $inlineContext->getCursor()->match('/^' . RegexHelper::REGEX_ENTITY . '/i')) { + if ($m = $inlineContext->getCursor()->match('/^' . RegexHelper::PARTIAL_ENTITY . '/i')) { $inlineContext->getContainer()->appendChild(new Text(Html5Entities::decodeEntity($m))); return true; diff --git a/vendor/league/commonmark/src/Inline/Parser/EscapableParser.php b/vendor/league/commonmark/src/Inline/Parser/EscapableParser.php index 5c8b42dba7..bfd8802f07 100644 --- a/vendor/league/commonmark/src/Inline/Parser/EscapableParser.php +++ b/vendor/league/commonmark/src/Inline/Parser/EscapableParser.php @@ -49,7 +49,7 @@ class EscapableParser extends AbstractInlineParser return true; } elseif ($nextChar !== null && - preg_match('/' . RegexHelper::REGEX_ESCAPABLE . '/', $nextChar) + preg_match('/' . RegexHelper::PARTIAL_ESCAPABLE . '/', $nextChar) ) { $cursor->advanceBy(2); $inlineContext->getContainer()->appendChild(new Text($nextChar)); diff --git a/vendor/league/commonmark/src/Inline/Parser/HtmlInlineParser.php b/vendor/league/commonmark/src/Inline/Parser/HtmlInlineParser.php index 02368ed6c4..c6db4f44d7 100644 --- a/vendor/league/commonmark/src/Inline/Parser/HtmlInlineParser.php +++ b/vendor/league/commonmark/src/Inline/Parser/HtmlInlineParser.php @@ -36,7 +36,7 @@ class HtmlInlineParser extends AbstractInlineParser public function parse(InlineParserContext $inlineContext) { $cursor = $inlineContext->getCursor(); - if ($m = $cursor->match(RegexHelper::getInstance()->getHtmlTagRegex())) { + if ($m = $cursor->match('/^' . RegexHelper::PARTIAL_HTMLTAG . '/i')) { $inlineContext->getContainer()->appendChild(new HtmlInline($m)); return true; diff --git a/vendor/league/commonmark/src/Inline/Processor/EmphasisProcessor.php b/vendor/league/commonmark/src/Inline/Processor/EmphasisProcessor.php index 797f6ec2d7..b6c6f9cb98 100644 --- a/vendor/league/commonmark/src/Inline/Processor/EmphasisProcessor.php +++ b/vendor/league/commonmark/src/Inline/Processor/EmphasisProcessor.php @@ -26,13 +26,7 @@ class EmphasisProcessor implements InlineProcessorInterface { $callback = function (Delimiter $opener, Delimiter $closer, DelimiterStack $stack) { // Calculate actual number of delimiters used from this closer - if ($closer->getNumDelims() < 3 || $opener->getNumDelims() < 3) { - $useDelims = $closer->getNumDelims() <= $opener->getNumDelims() - ? $closer->getNumDelims() - : $opener->getNumDelims(); - } else { - $useDelims = $closer->getNumDelims() % 2 === 0 ? 2 : 1; - } + $useDelims = ($closer->getNumDelims() >= 2 && $opener->getNumDelims() >= 2) ? 2 : 1; /** @var Text $openerInline */ $openerInline = $opener->getInlineNode(); /** @var Text $closerInline */ diff --git a/vendor/league/commonmark/src/Inline/Renderer/CodeRenderer.php b/vendor/league/commonmark/src/Inline/Renderer/CodeRenderer.php index 5cf70f74ad..9c7794b5b3 100644 --- a/vendor/league/commonmark/src/Inline/Renderer/CodeRenderer.php +++ b/vendor/league/commonmark/src/Inline/Renderer/CodeRenderer.php @@ -18,6 +18,7 @@ use League\CommonMark\ElementRendererInterface; use League\CommonMark\HtmlElement; use League\CommonMark\Inline\Element\AbstractInline; use League\CommonMark\Inline\Element\Code; +use League\CommonMark\Util\Xml; class CodeRenderer implements InlineRendererInterface { @@ -35,9 +36,9 @@ class CodeRenderer implements InlineRendererInterface $attrs = []; foreach ($inline->getData('attributes', []) as $key => $value) { - $attrs[$key] = $htmlRenderer->escape($value, true); + $attrs[$key] = Xml::escape($value, true); } - return new HtmlElement('code', $attrs, $htmlRenderer->escape($inline->getContent())); + return new HtmlElement('code', $attrs, Xml::escape($inline->getContent())); } } diff --git a/vendor/league/commonmark/src/Inline/Renderer/EmphasisRenderer.php b/vendor/league/commonmark/src/Inline/Renderer/EmphasisRenderer.php index 8ccefbcd8e..9692c2b5e1 100644 --- a/vendor/league/commonmark/src/Inline/Renderer/EmphasisRenderer.php +++ b/vendor/league/commonmark/src/Inline/Renderer/EmphasisRenderer.php @@ -18,6 +18,7 @@ use League\CommonMark\ElementRendererInterface; use League\CommonMark\HtmlElement; use League\CommonMark\Inline\Element\AbstractInline; use League\CommonMark\Inline\Element\Emphasis; +use League\CommonMark\Util\Xml; class EmphasisRenderer implements InlineRendererInterface { @@ -35,7 +36,7 @@ class EmphasisRenderer implements InlineRendererInterface $attrs = []; foreach ($inline->getData('attributes', []) as $key => $value) { - $attrs[$key] = $htmlRenderer->escape($value, true); + $attrs[$key] = Xml::escape($value, true); } return new HtmlElement('em', $attrs, $htmlRenderer->renderInlines($inline->children())); diff --git a/vendor/league/commonmark/src/Inline/Renderer/ImageRenderer.php b/vendor/league/commonmark/src/Inline/Renderer/ImageRenderer.php index 6a7e18050d..25fca1ab6b 100644 --- a/vendor/league/commonmark/src/Inline/Renderer/ImageRenderer.php +++ b/vendor/league/commonmark/src/Inline/Renderer/ImageRenderer.php @@ -21,6 +21,7 @@ use League\CommonMark\Inline\Element\Image; use League\CommonMark\Util\Configuration; use League\CommonMark\Util\ConfigurationAwareInterface; use League\CommonMark\Util\RegexHelper; +use League\CommonMark\Util\Xml; class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterface { @@ -43,14 +44,14 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf $attrs = []; foreach ($inline->getData('attributes', []) as $key => $value) { - $attrs[$key] = $htmlRenderer->escape($value, true); + $attrs[$key] = Xml::escape($value, true); } $forbidUnsafeLinks = $this->config->getConfig('safe') || !$this->config->getConfig('allow_unsafe_links'); if ($forbidUnsafeLinks && RegexHelper::isLinkPotentiallyUnsafe($inline->getUrl())) { $attrs['src'] = ''; } else { - $attrs['src'] = $htmlRenderer->escape($inline->getUrl(), true); + $attrs['src'] = Xml::escape($inline->getUrl(), true); } $alt = $htmlRenderer->renderInlines($inline->children()); @@ -58,7 +59,7 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf $attrs['alt'] = preg_replace('/\<[^>]*\>/', '', $alt); if (isset($inline->data['title'])) { - $attrs['title'] = $htmlRenderer->escape($inline->data['title'], true); + $attrs['title'] = Xml::escape($inline->data['title'], true); } return new HtmlElement('img', $attrs, '', true); diff --git a/vendor/league/commonmark/src/Inline/Renderer/LinkRenderer.php b/vendor/league/commonmark/src/Inline/Renderer/LinkRenderer.php index 54b32c59a6..293710b4d3 100644 --- a/vendor/league/commonmark/src/Inline/Renderer/LinkRenderer.php +++ b/vendor/league/commonmark/src/Inline/Renderer/LinkRenderer.php @@ -21,6 +21,7 @@ use League\CommonMark\Inline\Element\Link; use League\CommonMark\Util\Configuration; use League\CommonMark\Util\ConfigurationAwareInterface; use League\CommonMark\Util\RegexHelper; +use League\CommonMark\Util\Xml; class LinkRenderer implements InlineRendererInterface, ConfigurationAwareInterface { @@ -43,16 +44,16 @@ class LinkRenderer implements InlineRendererInterface, ConfigurationAwareInterfa $attrs = []; foreach ($inline->getData('attributes', []) as $key => $value) { - $attrs[$key] = $htmlRenderer->escape($value, true); + $attrs[$key] = Xml::escape($value, true); } $forbidUnsafeLinks = $this->config->getConfig('safe') || !$this->config->getConfig('allow_unsafe_links'); if (!($forbidUnsafeLinks && RegexHelper::isLinkPotentiallyUnsafe($inline->getUrl()))) { - $attrs['href'] = $htmlRenderer->escape($inline->getUrl(), true); + $attrs['href'] = Xml::escape($inline->getUrl(), true); } if (isset($inline->data['title'])) { - $attrs['title'] = $htmlRenderer->escape($inline->data['title'], true); + $attrs['title'] = Xml::escape($inline->data['title'], true); } return new HtmlElement('a', $attrs, $htmlRenderer->renderInlines($inline->children())); diff --git a/vendor/league/commonmark/src/Inline/Renderer/NewlineRenderer.php b/vendor/league/commonmark/src/Inline/Renderer/NewlineRenderer.php index 4a94c675a3..024abaeb55 100644 --- a/vendor/league/commonmark/src/Inline/Renderer/NewlineRenderer.php +++ b/vendor/league/commonmark/src/Inline/Renderer/NewlineRenderer.php @@ -35,8 +35,8 @@ class NewlineRenderer implements InlineRendererInterface if ($inline->getType() === Newline::HARDBREAK) { return new HtmlElement('br', [], '', true) . "\n"; - } else { - return $htmlRenderer->getOption('soft_break', "\n"); } + + return $htmlRenderer->getOption('soft_break', "\n"); } } diff --git a/vendor/league/commonmark/src/Inline/Renderer/StrongRenderer.php b/vendor/league/commonmark/src/Inline/Renderer/StrongRenderer.php index 95234159c4..2ea6c4a52c 100644 --- a/vendor/league/commonmark/src/Inline/Renderer/StrongRenderer.php +++ b/vendor/league/commonmark/src/Inline/Renderer/StrongRenderer.php @@ -18,6 +18,7 @@ use League\CommonMark\ElementRendererInterface; use League\CommonMark\HtmlElement; use League\CommonMark\Inline\Element\AbstractInline; use League\CommonMark\Inline\Element\Strong; +use League\CommonMark\Util\Xml; class StrongRenderer implements InlineRendererInterface { @@ -35,7 +36,7 @@ class StrongRenderer implements InlineRendererInterface $attrs = []; foreach ($inline->getData('attributes', []) as $key => $value) { - $attrs[$key] = $htmlRenderer->escape($value, true); + $attrs[$key] = Xml::escape($value, true); } return new HtmlElement('strong', $attrs, $htmlRenderer->renderInlines($inline->children())); diff --git a/vendor/league/commonmark/src/Inline/Renderer/TextRenderer.php b/vendor/league/commonmark/src/Inline/Renderer/TextRenderer.php index 575c3bc028..dcd3cdea88 100644 --- a/vendor/league/commonmark/src/Inline/Renderer/TextRenderer.php +++ b/vendor/league/commonmark/src/Inline/Renderer/TextRenderer.php @@ -17,6 +17,7 @@ namespace League\CommonMark\Inline\Renderer; use League\CommonMark\ElementRendererInterface; use League\CommonMark\Inline\Element\AbstractInline; use League\CommonMark\Inline\Element\Text; +use League\CommonMark\Util\Xml; class TextRenderer implements InlineRendererInterface { @@ -32,6 +33,6 @@ class TextRenderer implements InlineRendererInterface throw new \InvalidArgumentException('Incompatible inline type: ' . get_class($inline)); } - return $htmlRenderer->escape($inline->getContent()); + return Xml::escape($inline->getContent()); } } diff --git a/vendor/league/commonmark/src/InlineParserEngine.php b/vendor/league/commonmark/src/InlineParserEngine.php index 926934d091..45deacaef3 100644 --- a/vendor/league/commonmark/src/InlineParserEngine.php +++ b/vendor/league/commonmark/src/InlineParserEngine.php @@ -51,12 +51,7 @@ class InlineParserEngine */ protected function parseCharacter($character, InlineParserContext $inlineParserContext) { - $matchingParsers = $this->environment->getInlineParsersForCharacter($character); - if (empty($matchingParsers)) { - return false; - } - - foreach ($matchingParsers as $parser) { + foreach ($this->environment->getInlineParsersForCharacter($character) as $parser) { if ($parser->parse($inlineParserContext)) { return true; } diff --git a/vendor/league/commonmark/src/Node/Node.php b/vendor/league/commonmark/src/Node/Node.php index fb8683c889..55be265333 100644 --- a/vendor/league/commonmark/src/Node/Node.php +++ b/vendor/league/commonmark/src/Node/Node.php @@ -7,6 +7,11 @@ use League\CommonMark\Util\ArrayCollection; abstract class Node { /** + * @var int + */ + protected $depth = 0; + + /** * @var Node|null */ protected $parent; @@ -61,6 +66,7 @@ abstract class Node protected function setParent(Node $node = null) { $this->parent = $node; + $this->depth = ($node === null) ? 0 : $node->depth + 1; } /** @@ -129,6 +135,7 @@ abstract class Node $this->parent = null; $this->next = null; $this->previous = null; + $this->depth = 0; } /** @@ -226,6 +233,14 @@ abstract class Node } /** + * @return int + */ + public function getDepth() + { + return $this->depth; + } + + /** * @return NodeWalker */ public function walker() diff --git a/vendor/league/commonmark/src/Reference/Reference.php b/vendor/league/commonmark/src/Reference/Reference.php index 2cf8cb8386..c150c2791e 100644 --- a/vendor/league/commonmark/src/Reference/Reference.php +++ b/vendor/league/commonmark/src/Reference/Reference.php @@ -85,7 +85,7 @@ class Reference { // Collapse internal whitespace to single space and remove // leading/trailing whitespace - $string = preg_replace('/\s+/', '', trim($string)); + $string = preg_replace('/\s+/', ' ', trim($string)); return mb_strtoupper($string, 'UTF-8'); } diff --git a/vendor/league/commonmark/src/Reference/ReferenceMap.php b/vendor/league/commonmark/src/Reference/ReferenceMap.php index cd14b39a45..db2ceedcda 100644 --- a/vendor/league/commonmark/src/Reference/ReferenceMap.php +++ b/vendor/league/commonmark/src/Reference/ReferenceMap.php @@ -58,9 +58,11 @@ class ReferenceMap { $label = Reference::normalizeReference($label); - if (isset($this->references[$label])) { - return $this->references[$label]; + if (!isset($this->references[$label])) { + return; } + + return $this->references[$label]; } /** diff --git a/vendor/league/commonmark/src/ReferenceParser.php b/vendor/league/commonmark/src/ReferenceParser.php index f131bd5ea5..3324dd3f26 100644 --- a/vendor/league/commonmark/src/ReferenceParser.php +++ b/vendor/league/commonmark/src/ReferenceParser.php @@ -71,7 +71,7 @@ class ReferenceParser $cursor->advance(); // Link URL - $cursor->advanceToFirstNonSpace(); + $cursor->advanceToNextNonSpaceOrNewline(); $destination = LinkParserHelper::parseLinkDestination($cursor); if (empty($destination)) { @@ -81,7 +81,7 @@ class ReferenceParser } $previousState = $cursor->saveState(); - $cursor->advanceToFirstNonSpace(); + $cursor->advanceToNextNonSpaceOrNewline(); $title = LinkParserHelper::parseLinkTitle($cursor); if ($title === null) { diff --git a/vendor/league/commonmark/src/Util/ArrayCollection.php b/vendor/league/commonmark/src/Util/ArrayCollection.php index 6d73b0cc1c..e2492636b9 100644 --- a/vendor/league/commonmark/src/Util/ArrayCollection.php +++ b/vendor/league/commonmark/src/Util/ArrayCollection.php @@ -93,11 +93,11 @@ class ArrayCollection implements \IteratorAggregate, \Countable, \ArrayAccess /** * @param mixed $key * - * @return mixed + * @return mixed|null */ public function remove($key) { - if (!isset($this->elements[$key]) && !array_key_exists($key, $this->elements)) { + if (!array_key_exists($key, $this->elements)) { return; } @@ -142,7 +142,7 @@ class ArrayCollection implements \IteratorAggregate, \Countable, \ArrayAccess */ public function containsKey($key) { - return isset($this->elements[$key]) || array_key_exists($key, $this->elements); + return array_key_exists($key, $this->elements); } /** @@ -189,7 +189,7 @@ class ArrayCollection implements \IteratorAggregate, \Countable, \ArrayAccess */ public function offsetSet($offset, $value) { - if (!isset($offset)) { + if ($offset === null) { $this->add($value); } else { $this->set($offset, $value); diff --git a/vendor/league/commonmark/src/Util/Html5Entities.php b/vendor/league/commonmark/src/Util/Html5Entities.php index c13d38e78b..d0509f719b 100644 --- a/vendor/league/commonmark/src/Util/Html5Entities.php +++ b/vendor/league/commonmark/src/Util/Html5Entities.php @@ -14,7 +14,7 @@ namespace League\CommonMark\Util; -class Html5Entities +final class Html5Entities { public static $entitiesByName = [ 'Aacute' => 'Á', @@ -2256,9 +2256,9 @@ class Html5Entities if (substr($entity, 0, 2) === '&#') { if (strtolower(substr($entity, 2, 1)) === 'x') { return self::fromHex(substr($entity, 3, -1)); - } else { - return self::fromDecimal(substr($entity, 2, -1)); } + + return self::fromDecimal(substr($entity, 2, -1)); } $name = substr($entity, 1, -1); diff --git a/vendor/league/commonmark/src/Util/LinkParserHelper.php b/vendor/league/commonmark/src/Util/LinkParserHelper.php index 31fc4ab089..116a921e5e 100644 --- a/vendor/league/commonmark/src/Util/LinkParserHelper.php +++ b/vendor/league/commonmark/src/Util/LinkParserHelper.php @@ -16,7 +16,7 @@ namespace League\CommonMark\Util; use League\CommonMark\Cursor; -class LinkParserHelper +final class LinkParserHelper { /** * Attempt to parse link destination @@ -27,19 +27,45 @@ class LinkParserHelper */ public static function parseLinkDestination(Cursor $cursor) { - if ($res = $cursor->match(RegexHelper::getInstance()->getLinkDestinationBracesRegex())) { + if ($res = $cursor->match(RegexHelper::REGEX_LINK_DESTINATION_BRACES)) { // Chop off surrounding <..>: return UrlEncoder::unescapeAndEncode( - RegexHelper::unescape(substr($res, 1, strlen($res) - 2)) + RegexHelper::unescape(substr($res, 1, -1)) ); } - $res = $cursor->match(RegexHelper::getInstance()->getLinkDestinationRegex()); - if ($res !== null) { - return UrlEncoder::unescapeAndEncode( - RegexHelper::unescape($res) - ); + $oldState = $cursor->saveState(); + $openParens = 0; + while (($c = $cursor->getCharacter()) !== null) { + if ($c === '\\') { + $cursor->advanceBy(2); + } elseif ($c === '(') { + $cursor->advance(); + $openParens++; + } elseif ($c === ')') { + if ($openParens < 1) { + break; + } + + $cursor->advance(); + $openParens--; + } elseif (preg_match(RegexHelper::REGEX_WHITESPACE_CHAR, $c)) { + break; + } else { + $cursor->advance(); + } } + + $newPos = $cursor->getPosition(); + $cursor->restoreState($oldState); + + $cursor->advanceBy($newPos - $cursor->getPosition()); + + $res = $cursor->getPreviousText(); + + return UrlEncoder::unescapeAndEncode( + RegexHelper::unescape($res) + ); } /** @@ -49,11 +75,10 @@ class LinkParserHelper */ public static function parseLinkLabel(Cursor $cursor) { - $escapedChar = RegexHelper::getInstance()->getPartialRegex(RegexHelper::ESCAPED_CHAR); - $match = $cursor->match('/^\[(?:[^\\\\\[\]]|' . $escapedChar . '|\\\\)*\]/'); + $match = $cursor->match('/^\[(?:[^\\\\\[\]]|' . RegexHelper::PARTIAL_ESCAPED_CHAR . '|\\\\)*\]/'); $length = mb_strlen($match, 'utf-8'); - if ($match === null || $length > 1001) { + if ($match === null || $length > 1001 || preg_match('/[^\\\\]\\\\\]$/', $match)) { return 0; } @@ -69,9 +94,9 @@ class LinkParserHelper */ public static function parseLinkTitle(Cursor $cursor) { - if ($title = $cursor->match(RegexHelper::getInstance()->getLinkTitleRegex())) { + if ($title = $cursor->match('/' . RegexHelper::PARTIAL_LINK_TITLE . '/')) { // Chop off quotes from title and unescape - return RegexHelper::unescape(substr($title, 1, strlen($title) - 2)); + return RegexHelper::unescape(substr($title, 1, -1)); } } } diff --git a/vendor/league/commonmark/src/Util/RegexHelper.php b/vendor/league/commonmark/src/Util/RegexHelper.php index 269c47248a..4a8ea4b81f 100644 --- a/vendor/league/commonmark/src/Util/RegexHelper.php +++ b/vendor/league/commonmark/src/Util/RegexHelper.php @@ -17,42 +17,131 @@ namespace League\CommonMark\Util; use League\CommonMark\Block\Element\HtmlBlock; /** - * Provides regular expressions and utilties for parsing Markdown - * - * Singletons are generally bad, but it allows us to build the regexes once (and only once). + * Provides regular expressions and utilities for parsing Markdown */ -class RegexHelper +final class RegexHelper { + /** @deprecated Use PARTIAL_ESCAPABLE instead */ const ESCAPABLE = 0; + + /** @deprecated Use PARTIAL_ESCAPED_CHAR instead */ const ESCAPED_CHAR = 1; + + /** @deprecated Use PARTIAL_IN_DOUBLE_QUOTES instead */ const IN_DOUBLE_QUOTES = 2; + + /** @deprecated Use PARTIAL_IN_SINGLE_QUOTES instead */ const IN_SINGLE_QUOTES = 3; + + /** @deprecated Use PARTIAL_IN_PARENS instead */ const IN_PARENS = 4; + + /** @deprecated Use PARTIAL_REG_CHAR instead */ const REG_CHAR = 5; + + /** @deprecated Use PARTIAL_IN_PARENS_NOSP instead */ const IN_PARENS_NOSP = 6; + + /** @deprecated Use PARTIAL_TAGNAME instead */ const TAGNAME = 7; + + /** @deprecated Use PARTIAL_BLOCKTAGNAME instead */ const BLOCKTAGNAME = 8; + + /** @deprecated Use PARTIAL_ATTRIBUTENAME instead */ const ATTRIBUTENAME = 9; + + /** @deprecated Use PARTIAL_UNQUOTEDVALUE instead */ const UNQUOTEDVALUE = 10; + + /** @deprecated Use PARTIAL_SINGLEQUOTEDVALUE instead */ const SINGLEQUOTEDVALUE = 11; + + /** @deprecated Use PARTIAL_DOUBLEQUOTEDVALUE instead */ const DOUBLEQUOTEDVALUE = 12; + + /** @deprecated Use PARTIAL_ATTRIBUTEVALUE instead */ const ATTRIBUTEVALUE = 13; + + /** @deprecated Use PARTIAL_ATTRIBUTEVALUESPEC instead */ const ATTRIBUTEVALUESPEC = 14; + + /** @deprecated Use PARTIAL_ATTRIBUTE instead */ const ATTRIBUTE = 15; + + /** @deprecated Use PARTIAL_OPENTAG instead */ const OPENTAG = 16; + + /** @deprecated Use PARTIAL_CLOSETAG instead */ const CLOSETAG = 17; + + /** @deprecated Use PARTIAL_OPENBLOCKTAG instead */ const OPENBLOCKTAG = 18; + + /** @deprecated Use PARTIAL_CLOSEBLOCKTAG instead */ const CLOSEBLOCKTAG = 19; + + /** @deprecated Use PARTIAL_HTMLCOMMENT instead */ const HTMLCOMMENT = 20; + + /** @deprecated Use PARTIAL_PROCESSINGINSTRUCTION instead */ const PROCESSINGINSTRUCTION = 21; + + /** @deprecated Use PARTIAL_DECLARATION instead */ const DECLARATION = 22; + + /** @deprecated Use PARTIAL_CDATA instead */ const CDATA = 23; + + /** @deprecated Use PARTIAL_HTMLTAG instead */ const HTMLTAG = 24; + + /** @deprecated Use PARTIAL_HTMLBLOCKOPEN instead */ const HTMLBLOCKOPEN = 25; + + /** @deprecated Use PARTIAL_LINK_TITLE instead */ const LINK_TITLE = 26; - const REGEX_ESCAPABLE = '[!"#$%&\'()*+,.\/:;<=>?@[\\\\\]^_`{|}~-]'; - const REGEX_ENTITY = '&(?:#x[a-f0-9]{1,8}|#[0-9]{1,8}|[a-z][a-z0-9]{1,31});'; + // Partial regular expressions (wrap with `/` on each side before use) + const PARTIAL_ENTITY = '&(?:#x[a-f0-9]{1,8}|#[0-9]{1,8}|[a-z][a-z0-9]{1,31});'; + const PARTIAL_ESCAPABLE = '[!"#$%&\'()*+,.\/:;<=>?@[\\\\\]^_`{|}~-]'; + const PARTIAL_ESCAPED_CHAR = '\\\\' . self::PARTIAL_ESCAPABLE; + const PARTIAL_IN_DOUBLE_QUOTES = '"(' . self::PARTIAL_ESCAPED_CHAR . '|[^"\x00])*"'; + const PARTIAL_IN_SINGLE_QUOTES = '\'(' . self::PARTIAL_ESCAPED_CHAR . '|[^\'\x00])*\''; + const PARTIAL_IN_PARENS = '\\((' . self::PARTIAL_ESCAPED_CHAR . '|[^)\x00])*\\)'; + const PARTIAL_REG_CHAR = '[^\\\\()\x00-\x20]'; + const PARTIAL_IN_PARENS_NOSP = '\((' . self::PARTIAL_REG_CHAR . '|' . self::PARTIAL_ESCAPED_CHAR . '|\\\\)*\)'; + const PARTIAL_TAGNAME = '[A-Za-z][A-Za-z0-9-]*'; + const PARTIAL_BLOCKTAGNAME = '(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h1|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|title|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)'; + const PARTIAL_ATTRIBUTENAME = '[a-zA-Z_:][a-zA-Z0-9:._-]*'; + const PARTIAL_UNQUOTEDVALUE = '[^"\'=<>`\x00-\x20]+'; + const PARTIAL_SINGLEQUOTEDVALUE = '\'[^\']*\''; + const PARTIAL_DOUBLEQUOTEDVALUE = '"[^"]*"'; + const PARTIAL_ATTRIBUTEVALUE = '(?:' . self::PARTIAL_UNQUOTEDVALUE . '|' . self::PARTIAL_SINGLEQUOTEDVALUE . '|' . self::PARTIAL_DOUBLEQUOTEDVALUE . ')'; + const PARTIAL_ATTRIBUTEVALUESPEC = '(?:' . '\s*=' . '\s*' . self::PARTIAL_ATTRIBUTEVALUE . ')'; + const PARTIAL_ATTRIBUTE = '(?:' . '\s+' . self::PARTIAL_ATTRIBUTENAME . self::PARTIAL_ATTRIBUTEVALUESPEC . '?)'; + const PARTIAL_OPENTAG = '<' . self::PARTIAL_TAGNAME . self::PARTIAL_ATTRIBUTE . '*' . '\s*\/?>'; + const PARTIAL_CLOSETAG = '<\/' . self::PARTIAL_TAGNAME . '\s*[>]'; + const PARTIAL_OPENBLOCKTAG = '<' . self::PARTIAL_BLOCKTAGNAME . self::PARTIAL_ATTRIBUTE . '*' . '\s*\/?>'; + const PARTIAL_CLOSEBLOCKTAG = '<\/' . self::PARTIAL_BLOCKTAGNAME . '\s*[>]'; + const PARTIAL_HTMLCOMMENT = '<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->'; + const PARTIAL_PROCESSINGINSTRUCTION = '[<][?].*?[?][>]'; + const PARTIAL_DECLARATION = '<![A-Z]+' . '\s+[^>]*>'; + const PARTIAL_CDATA = '<!\[CDATA\[[\s\S]*?]\]>'; + const PARTIAL_HTMLTAG = '(?:' . self::PARTIAL_OPENTAG . '|' . self::PARTIAL_CLOSETAG . '|' . self::PARTIAL_HTMLCOMMENT . '|' . + self::PARTIAL_PROCESSINGINSTRUCTION . '|' . self::PARTIAL_DECLARATION . '|' . self::PARTIAL_CDATA . ')'; + const PARTIAL_HTMLBLOCKOPEN = '<(?:' . self::PARTIAL_BLOCKTAGNAME . '(?:[\s\/>]|$)' . '|' . + '\/' . self::PARTIAL_BLOCKTAGNAME . '(?:[\s>]|$)' . '|' . '[?!])'; + const PARTIAL_LINK_TITLE = '^(?:"(' . self::PARTIAL_ESCAPED_CHAR . '|[^"\x00])*"' . + '|' . '\'(' . self::PARTIAL_ESCAPED_CHAR . '|[^\'\x00])*\'' . + '|' . '\((' . self::PARTIAL_ESCAPED_CHAR . '|[^)\x00])*\))'; + + /** @deprecated Use PARTIAL_ESCAPABLE instead */ + const REGEX_ESCAPABLE = self::PARTIAL_ESCAPABLE; + + /** @deprecated Use PARTIAL_ENTITY instead */ + const REGEX_ENTITY = self::PARTIAL_ENTITY; + const REGEX_PUNCTUATION = '/^[\x{2000}-\x{206F}\x{2E00}-\x{2E7F}\p{Pc}\p{Pd}\p{Pe}\p{Pf}\p{Pi}\p{Po}\p{Ps}\\\\\'!"#\$%&\(\)\*\+,\-\.\\/:;<=>\?@\[\]\^_`\{\|\}~]/u'; const REGEX_UNSAFE_PROTOCOL = '/^javascript:|vbscript:|file:|data:/i'; const REGEX_SAFE_DATA_PROTOCOL = '/^data:image\/(?:png|gif|jpeg|webp)/i'; @@ -61,25 +150,23 @@ class RegexHelper const REGEX_WHITESPACE_CHAR = '/^[ \t\n\x0b\x0c\x0d]/'; const REGEX_WHITESPACE = '/[ \t\n\x0b\x0c\x0d]+/'; const REGEX_UNICODE_WHITESPACE_CHAR = '/^\pZ|\s/u'; - const REGEX_UNICODE_WHITESPACE = '/\pZ|\s/u'; - - protected $regex = []; - - protected static $instance; + const REGEX_THEMATIC_BREAK = '/^(?:(?:\*[ \t]*){3,}|(?:_[ \t]*){3,}|(?:-[ \t]*){3,})[ \t]*$/'; + const REGEX_LINK_DESTINATION_BRACES = '/^(?:' . '[<](?:[^ <>\\t\\n\\\\\\x00]' . '|' . self::PARTIAL_ESCAPED_CHAR . '|' . '\\\\)*[>]' . ')/'; /** - * Constructor + * @deprecated Instance methods will be removed in 0.18 or 1.0 (whichever comes first) */ - protected function __construct() - { - $this->buildRegexPatterns(); - } + protected static $instance; /** * @return RegexHelper + * + * @deprecated Instances are no longer needed and will be removed in 0.18 or 1.0 */ public static function getInstance() { + @trigger_error('RegexHelper no longer uses the singleton pattern. Directly grab the REGEX_ or PARTIAL_ constant you need instead.', E_USER_DEPRECATED); + if (self::$instance === null) { self::$instance = new self(); } @@ -88,49 +175,6 @@ class RegexHelper } /** - * Builds the regular expressions required to parse Markdown - * - * We could hard-code them all as pre-built constants, but that would be more difficult to manage. - */ - protected function buildRegexPatterns() - { - $regex = []; - $regex[self::ESCAPABLE] = self::REGEX_ESCAPABLE; - $regex[self::ESCAPED_CHAR] = '\\\\' . $regex[self::ESCAPABLE]; - $regex[self::IN_DOUBLE_QUOTES] = '"(' . $regex[self::ESCAPED_CHAR] . '|[^"\x00])*"'; - $regex[self::IN_SINGLE_QUOTES] = '\'(' . $regex[self::ESCAPED_CHAR] . '|[^\'\x00])*\''; - $regex[self::IN_PARENS] = '\\((' . $regex[self::ESCAPED_CHAR] . '|[^)\x00])*\\)'; - $regex[self::REG_CHAR] = '[^\\\\()\x00-\x20]'; - $regex[self::IN_PARENS_NOSP] = '\((' . $regex[self::REG_CHAR] . '|' . $regex[self::ESCAPED_CHAR] . '|\\\\)*\)'; - $regex[self::TAGNAME] = '[A-Za-z][A-Za-z0-9-]*'; - $regex[self::BLOCKTAGNAME] = '(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h1|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|title|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)'; - $regex[self::ATTRIBUTENAME] = '[a-zA-Z_:][a-zA-Z0-9:._-]*'; - $regex[self::UNQUOTEDVALUE] = '[^"\'=<>`\x00-\x20]+'; - $regex[self::SINGLEQUOTEDVALUE] = '\'[^\']*\''; - $regex[self::DOUBLEQUOTEDVALUE] = '"[^"]*"'; - $regex[self::ATTRIBUTEVALUE] = '(?:' . $regex[self::UNQUOTEDVALUE] . '|' . $regex[self::SINGLEQUOTEDVALUE] . '|' . $regex[self::DOUBLEQUOTEDVALUE] . ')'; - $regex[self::ATTRIBUTEVALUESPEC] = '(?:' . '\s*=' . '\s*' . $regex[self::ATTRIBUTEVALUE] . ')'; - $regex[self::ATTRIBUTE] = '(?:' . '\s+' . $regex[self::ATTRIBUTENAME] . $regex[self::ATTRIBUTEVALUESPEC] . '?)'; - $regex[self::OPENTAG] = '<' . $regex[self::TAGNAME] . $regex[self::ATTRIBUTE] . '*' . '\s*\/?>'; - $regex[self::CLOSETAG] = '<\/' . $regex[self::TAGNAME] . '\s*[>]'; - $regex[self::OPENBLOCKTAG] = '<' . $regex[self::BLOCKTAGNAME] . $regex[self::ATTRIBUTE] . '*' . '\s*\/?>'; - $regex[self::CLOSEBLOCKTAG] = '<\/' . $regex[self::BLOCKTAGNAME] . '\s*[>]'; - $regex[self::HTMLCOMMENT] = '<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->'; - $regex[self::PROCESSINGINSTRUCTION] = '[<][?].*?[?][>]'; - $regex[self::DECLARATION] = '<![A-Z]+' . '\s+[^>]*>'; - $regex[self::CDATA] = '<!\[CDATA\[[\s\S]*?]\]>'; - $regex[self::HTMLTAG] = '(?:' . $regex[self::OPENTAG] . '|' . $regex[self::CLOSETAG] . '|' . $regex[self::HTMLCOMMENT] . '|' . - $regex[self::PROCESSINGINSTRUCTION] . '|' . $regex[self::DECLARATION] . '|' . $regex[self::CDATA] . ')'; - $regex[self::HTMLBLOCKOPEN] = '<(?:' . $regex[self::BLOCKTAGNAME] . '(?:[\s\/>]|$)' . '|' . - '\/' . $regex[self::BLOCKTAGNAME] . '(?:[\s>]|$)' . '|' . '[?!])'; - $regex[self::LINK_TITLE] = '^(?:"(' . $regex[self::ESCAPED_CHAR] . '|[^"\x00])*"' . - '|' . '\'(' . $regex[self::ESCAPED_CHAR] . '|[^\'\x00])*\'' . - '|' . '\((' . $regex[self::ESCAPED_CHAR] . '|[^)\x00])*\))'; - - $this->regex = $regex; - } - - /** * Returns a partial regex * * It'll need to be wrapped with /.../ before use @@ -138,50 +182,90 @@ class RegexHelper * @param int $const * * @return string + * + * @deprecated Just grab the constant directly */ public function getPartialRegex($const) { - return $this->regex[$const]; + @trigger_error('RegexHelper no longer supports the getPartialRegex() function. Directly grab the PARTIAL_ constant you need instead.', E_USER_DEPRECATED); + + switch ($const) { + case self::ESCAPABLE: return self::PARTIAL_ESCAPABLE; + case self::ESCAPED_CHAR: return self::PARTIAL_ESCAPED_CHAR; + case self::IN_DOUBLE_QUOTES: return self::PARTIAL_IN_DOUBLE_QUOTES; + case self::IN_SINGLE_QUOTES: return self::PARTIAL_IN_SINGLE_QUOTES; + case self::IN_PARENS: return self::PARTIAL_IN_PARENS; + case self::REG_CHAR: return self::PARTIAL_REG_CHAR; + case self::IN_PARENS_NOSP: return self::PARTIAL_IN_PARENS_NOSP; + case self::TAGNAME: return self::PARTIAL_TAGNAME; + case self::BLOCKTAGNAME: return self::PARTIAL_BLOCKTAGNAME; + case self::ATTRIBUTENAME: return self::PARTIAL_ATTRIBUTENAME; + case self::UNQUOTEDVALUE: return self::PARTIAL_UNQUOTEDVALUE; + case self::SINGLEQUOTEDVALUE: return self::PARTIAL_SINGLEQUOTEDVALUE; + case self::DOUBLEQUOTEDVALUE: return self::PARTIAL_DOUBLEQUOTEDVALUE; + case self::ATTRIBUTEVALUE: return self::PARTIAL_ATTRIBUTEVALUE; + case self::ATTRIBUTEVALUESPEC: return self::PARTIAL_ATTRIBUTEVALUESPEC; + case self::ATTRIBUTE: return self::PARTIAL_ATTRIBUTE; + case self::OPENTAG: return self::PARTIAL_OPENTAG; + case self::CLOSETAG: return self::PARTIAL_CLOSETAG; + case self::OPENBLOCKTAG: return self::PARTIAL_OPENBLOCKTAG; + case self::CLOSEBLOCKTAG: return self::PARTIAL_CLOSEBLOCKTAG; + case self::HTMLCOMMENT: return self::PARTIAL_HTMLCOMMENT; + case self::PROCESSINGINSTRUCTION: return self::PARTIAL_PROCESSINGINSTRUCTION; + case self::DECLARATION: return self::PARTIAL_DECLARATION; + case self::CDATA: return self::PARTIAL_CDATA; + case self::HTMLTAG: return self::PARTIAL_HTMLTAG; + case self::HTMLBLOCKOPEN: return self::PARTIAL_HTMLBLOCKOPEN; + case self::LINK_TITLE: return self::PARTIAL_LINK_TITLE; + } } /** * @return string + * + * @deprecated Use PARTIAL_HTMLTAG and wrap it yourself instead */ public function getHtmlTagRegex() { - return '/^' . $this->regex[self::HTMLTAG] . '/i'; + @trigger_error('RegexHelper::getHtmlTagRegex() has been deprecated. Use the RegexHelper::PARTIAL_HTMLTAG constant instead.', E_USER_DEPRECATED); + + return '/^' . self::PARTIAL_HTMLTAG . '/i'; } /** * @return string + * + * @deprecated Use PARTIAL_LINK_TITLE and wrap it yourself instead */ public function getLinkTitleRegex() { - return '/' . $this->regex[self::LINK_TITLE] . '/'; - } + @trigger_error('RegexHelper::getLinkTitleRegex() has been deprecated. Use the RegexHelper::PARTIAL_LINK_TITLE constant instead.', E_USER_DEPRECATED); - /** - * @return string - */ - public function getLinkDestinationRegex() - { - return '/^' . '(?:' . $this->regex[self::REG_CHAR] . '+|' . $this->regex[self::ESCAPED_CHAR] . '|\\\\|' . $this->regex[self::IN_PARENS_NOSP] . ')*' . '/'; + return '/' . self::PARTIAL_LINK_TITLE . '/'; } /** * @return string + * + * @deprecated Use REGEX_LINK_DESTINATION_BRACES instead */ public function getLinkDestinationBracesRegex() { - return '/^(?:' . '[<](?:[^ <>\\t\\n\\\\\\x00]' . '|' . $this->regex[self::ESCAPED_CHAR] . '|' . '\\\\)*[>]' . ')/'; + @trigger_error('RegexHelper::getLinkDestinationBracesRegex() has been deprecated. Use the RegexHelper::REGEX_LINK_DESTINATION_BRACES constant instead.', E_USER_DEPRECATED); + + return self::REGEX_LINK_DESTINATION_BRACES; } /** * @return string + * + * @deprecated Use the REGEX_THEMATIC_BREAK constant directly */ public function getThematicBreakRegex() { - return '/^(?:(?:\*[ \t]*){3,}|(?:_[ \t]*){3,}|(?:-[ \t]*){3,})[ \t]*$/'; + @trigger_error('RegexHelper::getThematicBreakRegex() has been deprecated. Use the RegexHelper::REGEX_THEMATIC_BREAK constant instead.', E_USER_DEPRECATED); + + return self::REGEX_THEMATIC_BREAK; } /** @@ -247,10 +331,10 @@ class RegexHelper */ public static function unescape($string) { - $allEscapedChar = '/\\\\(' . self::REGEX_ESCAPABLE . ')/'; + $allEscapedChar = '/\\\\(' . self::PARTIAL_ESCAPABLE . ')/'; $escaped = preg_replace($allEscapedChar, '$1', $string); - $replaced = preg_replace_callback('/' . self::REGEX_ENTITY . '/i', function ($e) { + $replaced = preg_replace_callback('/' . self::PARTIAL_ENTITY . '/i', function ($e) { return Html5Entities::decodeEntity($e[0]); }, $escaped); @@ -276,11 +360,9 @@ class RegexHelper case HtmlBlock::TYPE_5_CDATA: return '/^<!\[CDATA\[/'; case HtmlBlock::TYPE_6_BLOCK_ELEMENT: - return '%^<[/]?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[123456]|head|header|hr|html|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|pre|section|source|title|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:\s|[/]?[>]|$)%i'; + return '%^<[/]?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[123456]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|title|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:\s|[/]?[>]|$)%i'; case HtmlBlock::TYPE_7_MISC_ELEMENT: - $self = self::getInstance(); - - return '/^(?:' . $self->getPartialRegex(self::OPENTAG) . '|' . $self->getPartialRegex(self::CLOSETAG) . ')\\s*$/i'; + return '/^(?:' . self::PARTIAL_OPENTAG . '|' . self::PARTIAL_CLOSETAG . ')\\s*$/i'; } } diff --git a/vendor/league/commonmark/src/Util/UrlEncoder.php b/vendor/league/commonmark/src/Util/UrlEncoder.php index 8d4fcfbdd4..67682ca15a 100644 --- a/vendor/league/commonmark/src/Util/UrlEncoder.php +++ b/vendor/league/commonmark/src/Util/UrlEncoder.php @@ -14,7 +14,7 @@ namespace League\CommonMark\Util; -class UrlEncoder +final class UrlEncoder { protected static $dontEncode = [ '%21' => '!', @@ -48,6 +48,53 @@ class UrlEncoder { $decoded = html_entity_decode($uri); - return strtr(rawurlencode(rawurldecode($decoded)), self::$dontEncode); + return self::encode(self::decode($decoded)); + } + + /** + * Decode a percent-encoded URI + * + * @param string $uri + * + * @return string + */ + private static function decode($uri) + { + return preg_replace_callback('/%([0-9a-f]{2})/iu', function ($matches) { + // Convert percent-encoded codes to uppercase + $upper = strtoupper($matches[0]); + // Keep excluded characters as-is + if (array_key_exists($upper, self::$dontEncode)) { + return $upper; + } + + // Otherwise, return the character for this codepoint + return chr(hexdec($matches[1])); + }, $uri); + } + + /** + * Encode a URI, preserving already-encoded and excluded characters + * + * @param string $uri + * + * @return string + */ + private static function encode($uri) + { + return preg_replace_callback('/(%[0-9a-f]{2})|./iu', function ($matches) { + // Keep already-encoded characters as-is + if (count($matches) > 1) { + return $matches[0]; + } + + // Keep excluded characters as-is + if (in_array($matches[0], self::$dontEncode)) { + return $matches[0]; + } + + // Otherwise, encode the character + return rawurlencode($matches[0]); + }, $uri); } } diff --git a/vendor/league/commonmark/src/Util/Xml.php b/vendor/league/commonmark/src/Util/Xml.php new file mode 100644 index 0000000000..7407d9ca31 --- /dev/null +++ b/vendor/league/commonmark/src/Util/Xml.php @@ -0,0 +1,38 @@ +<?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\Util; + +/** + * Utility class for handling/generating XML and HTML + */ +final class Xml +{ + /** + * @param string $string + * @param bool $preserveEntities + * + * @return string + */ + public static function escape($string, $preserveEntities = false) + { + if ($preserveEntities) { + $string = preg_replace('/[&](?;|[a-z][a-z0-9]{1,31};)/i', '&', $string); + } else { + $string = str_replace('&', '&', $string); + } + + return str_replace(['<', '>', '"'], ['<', '>', '"'], $string); + } +} |
