update inbox list
This commit is contained in:
90
vendor/league/commonmark/src/Reference/Reference.php
vendored
Normal file
90
vendor/league/commonmark/src/Reference/Reference.php
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
<?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\Reference;
|
||||
|
||||
final class Reference implements ReferenceInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $label;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $destination;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* @var array<int, array<int, string>>
|
||||
*
|
||||
* Source: https://github.com/symfony/polyfill-mbstring/blob/master/Mbstring.php
|
||||
*/
|
||||
private static $caseFold = [
|
||||
['µ', 'ſ', "\xCD\x85", 'ς', "\xCF\x90", "\xCF\x91", "\xCF\x95", "\xCF\x96", "\xCF\xB0", "\xCF\xB1", "\xCF\xB5", "\xE1\xBA\x9B", "\xE1\xBE\xBE", "\xC3\x9F", "\xE1\xBA\x9E"],
|
||||
['μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "\xE1\xB9\xA1", 'ι', 'ss', 'ss'],
|
||||
];
|
||||
|
||||
public function __construct(string $label, string $destination, string $title)
|
||||
{
|
||||
$this->label = self::normalizeReference($label);
|
||||
$this->destination = $destination;
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
public function getLabel(): string
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function getDestination(): string
|
||||
{
|
||||
return $this->destination;
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize reference label
|
||||
*
|
||||
* This enables case-insensitive label matching
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function normalizeReference(string $string): string
|
||||
{
|
||||
// Collapse internal whitespace to single space and remove
|
||||
// leading/trailing whitespace
|
||||
$string = \preg_replace('/\s+/', ' ', \trim($string));
|
||||
|
||||
if (!\defined('MB_CASE_FOLD')) {
|
||||
// We're not on a version of PHP (7.3+) which has this feature
|
||||
$string = \str_replace(self::$caseFold[0], self::$caseFold[1], $string);
|
||||
|
||||
return \mb_strtoupper($string, 'UTF-8');
|
||||
}
|
||||
|
||||
return \mb_convert_case($string, \MB_CASE_FOLD, 'UTF-8');
|
||||
}
|
||||
}
|
||||
27
vendor/league/commonmark/src/Reference/ReferenceInterface.php
vendored
Normal file
27
vendor/league/commonmark/src/Reference/ReferenceInterface.php
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<?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\Reference;
|
||||
|
||||
/**
|
||||
* Link reference
|
||||
*/
|
||||
interface ReferenceInterface
|
||||
{
|
||||
public function getLabel(): string;
|
||||
|
||||
public function getDestination(): string;
|
||||
|
||||
public function getTitle(): string;
|
||||
}
|
||||
55
vendor/league/commonmark/src/Reference/ReferenceMap.php
vendored
Normal file
55
vendor/league/commonmark/src/Reference/ReferenceMap.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\Reference;
|
||||
|
||||
/**
|
||||
* A collection of references, indexed by label
|
||||
*/
|
||||
final class ReferenceMap implements ReferenceMapInterface
|
||||
{
|
||||
/**
|
||||
* @var ReferenceInterface[]
|
||||
*/
|
||||
protected $references = [];
|
||||
|
||||
public function addReference(ReferenceInterface $reference): void
|
||||
{
|
||||
$key = Reference::normalizeReference($reference->getLabel());
|
||||
$this->references[$key] = $reference;
|
||||
}
|
||||
|
||||
public function contains(string $label): bool
|
||||
{
|
||||
$label = Reference::normalizeReference($label);
|
||||
|
||||
return isset($this->references[$label]);
|
||||
}
|
||||
|
||||
public function getReference(string $label): ?ReferenceInterface
|
||||
{
|
||||
$label = Reference::normalizeReference($label);
|
||||
|
||||
if (!isset($this->references[$label])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->references[$label];
|
||||
}
|
||||
|
||||
public function listReferences(): iterable
|
||||
{
|
||||
return \array_values($this->references);
|
||||
}
|
||||
}
|
||||
49
vendor/league/commonmark/src/Reference/ReferenceMapInterface.php
vendored
Normal file
49
vendor/league/commonmark/src/Reference/ReferenceMapInterface.php
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
<?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\Reference;
|
||||
|
||||
/**
|
||||
* A collection of references
|
||||
*/
|
||||
interface ReferenceMapInterface
|
||||
{
|
||||
/**
|
||||
* @param ReferenceInterface $reference
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addReference(ReferenceInterface $reference): void;
|
||||
|
||||
/**
|
||||
* @param string $label
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function contains(string $label): bool;
|
||||
|
||||
/**
|
||||
* @param string $label
|
||||
*
|
||||
* @return ReferenceInterface|null
|
||||
*/
|
||||
public function getReference(string $label): ?ReferenceInterface;
|
||||
|
||||
/**
|
||||
* Lists all registered references.
|
||||
*
|
||||
* @return ReferenceInterface[]
|
||||
*/
|
||||
public function listReferences(): iterable;
|
||||
}
|
||||
123
vendor/league/commonmark/src/Reference/ReferenceParser.php
vendored
Normal file
123
vendor/league/commonmark/src/Reference/ReferenceParser.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\Reference;
|
||||
|
||||
use League\CommonMark\Cursor;
|
||||
use League\CommonMark\Util\LinkParserHelper;
|
||||
|
||||
final class ReferenceParser
|
||||
{
|
||||
/**
|
||||
* @var ReferenceMapInterface
|
||||
*/
|
||||
private $referenceMap;
|
||||
|
||||
public function __construct(ReferenceMapInterface $referenceMap)
|
||||
{
|
||||
$this->referenceMap = $referenceMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to parse a link reference, modifying the refmap.
|
||||
*
|
||||
* @param Cursor $cursor
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function parse(Cursor $cursor)
|
||||
{
|
||||
if ($cursor->isAtEnd()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$initialState = $cursor->saveState();
|
||||
|
||||
$matchChars = LinkParserHelper::parseLinkLabel($cursor);
|
||||
if ($matchChars === 0) {
|
||||
$cursor->restoreState($initialState);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// We need to trim the opening and closing brackets from the previously-matched text
|
||||
$label = \substr($cursor->getPreviousText(), 1, -1);
|
||||
|
||||
if (\preg_match('/[^\s]/', $label) === 0) {
|
||||
$cursor->restoreState($initialState);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($cursor->getCharacter() !== ':') {
|
||||
$cursor->restoreState($initialState);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Advance past the colon
|
||||
$cursor->advanceBy(1);
|
||||
|
||||
// Link URL
|
||||
$cursor->advanceToNextNonSpaceOrNewline();
|
||||
|
||||
$destination = LinkParserHelper::parseLinkDestination($cursor);
|
||||
if ($destination === null) {
|
||||
$cursor->restoreState($initialState);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$previousState = $cursor->saveState();
|
||||
|
||||
if ($cursor->advanceToNextNonSpaceOrNewline() > 0) {
|
||||
$title = LinkParserHelper::parseLinkTitle($cursor);
|
||||
}
|
||||
|
||||
if (!isset($title)) {
|
||||
$title = '';
|
||||
$cursor->restoreState($previousState);
|
||||
}
|
||||
|
||||
// Make sure we're at line end:
|
||||
$atLineEnd = true;
|
||||
if ($cursor->match('/^ *(?:\n|$)/') === null) {
|
||||
if ($title === '') {
|
||||
$atLineEnd = false;
|
||||
} else {
|
||||
// The potential title we found is not at the line end,
|
||||
// but it could still be a legal link reference if we
|
||||
// discard the title
|
||||
$title = '';
|
||||
// rewind before spaces
|
||||
$cursor->restoreState($previousState);
|
||||
// and instead check if the link URL is at the line end
|
||||
$atLineEnd = $cursor->match('/^ *(?:\n|$)/') !== null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$atLineEnd) {
|
||||
$cursor->restoreState($initialState);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$this->referenceMap->contains($label)) {
|
||||
$reference = new Reference($label, $destination, $title);
|
||||
$this->referenceMap->addReference($reference);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user