updated composer
This commit is contained in:
@@ -182,7 +182,7 @@ class FencedCode extends AbstractStringContainerBlock
|
||||
|
||||
// check for closing code fence
|
||||
if ($cursor->getIndent() <= 3 && $cursor->getNextNonSpaceCharacter() === $container->getChar()) {
|
||||
$match = RegexHelper::matchAll('/^(?:`{3,}|~{3,})(?= *$)/', $cursor->getLine(), $cursor->getNextNonSpacePosition());
|
||||
$match = RegexHelper::matchFirst('/^(?:`{3,}|~{3,})(?= *$)/', $cursor->getLine(), $cursor->getNextNonSpacePosition());
|
||||
if ($match !== null && \strlen($match[0]) >= $container->getLength()) {
|
||||
// don't add closing fence to container; instead, close it:
|
||||
$this->setLength(-1); // -1 means we've passed closer
|
||||
|
||||
@@ -27,7 +27,7 @@ final class ATXHeadingParser implements BlockParserInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
$match = RegexHelper::matchAll('/^#{1,6}(?:[ \t]+|$)/', $cursor->getLine(), $cursor->getNextNonSpacePosition());
|
||||
$match = RegexHelper::matchFirst('/^#{1,6}(?:[ \t]+|$)/', $cursor->getLine(), $cursor->getNextNonSpacePosition());
|
||||
if (!$match) {
|
||||
return false;
|
||||
}
|
||||
|
||||
+10
-3
@@ -59,7 +59,7 @@ final class ListParser implements BlockParserInterface, ConfigurationAwareInterf
|
||||
$data->delimiter = null;
|
||||
$data->bulletChar = $rest[0];
|
||||
$markerLength = 1;
|
||||
} elseif (($matches = RegexHelper::matchAll('/^(\d{1,9})([.)])/', $rest)) && (!($context->getContainer() instanceof Paragraph) || $matches[1] === '1')) {
|
||||
} elseif (($matches = RegexHelper::matchFirst('/^(\d{1,9})([.)])/', $rest)) && (!($context->getContainer() instanceof Paragraph) || $matches[1] === '1')) {
|
||||
$data = new ListData();
|
||||
$data->markerOffset = $indent;
|
||||
$data->type = ListBlock::TYPE_ORDERED;
|
||||
@@ -136,9 +136,16 @@ final class ListParser implements BlockParserInterface, ConfigurationAwareInterf
|
||||
return $this->listMarkerRegex = '/^[*+-]/';
|
||||
}
|
||||
|
||||
$markers = $this->config->get('unordered_list_markers', ['*', '+', '-']);
|
||||
$deprecatedMarkers = $this->config->get('unordered_list_markers', ConfigurationInterface::MISSING);
|
||||
if ($deprecatedMarkers !== ConfigurationInterface::MISSING) {
|
||||
@\trigger_error('The "unordered_list_markers" configuration option is deprecated in league/commonmark 1.6 and will be replaced with "commonmark > unordered_list_markers" in 2.0', \E_USER_DEPRECATED);
|
||||
} else {
|
||||
$deprecatedMarkers = ['*', '+', '-'];
|
||||
}
|
||||
|
||||
if (!\is_array($markers)) {
|
||||
$markers = $this->config->get('commonmark/unordered_list_markers', $deprecatedMarkers);
|
||||
|
||||
if (!\is_array($markers) || $markers === []) {
|
||||
throw new \RuntimeException('Invalid configuration option "unordered_list_markers": value must be an array of strings');
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ final class SetExtHeadingParser implements BlockParserInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
$match = RegexHelper::matchAll('/^(?:=+|-+)[ \t]*$/', $cursor->getLine(), $cursor->getNextNonSpacePosition());
|
||||
$match = RegexHelper::matchFirst('/^(?:=+|-+)[ \t]*$/', $cursor->getLine(), $cursor->getNextNonSpacePosition());
|
||||
if ($match === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
+5
-13
@@ -17,7 +17,7 @@ namespace League\CommonMark;
|
||||
/**
|
||||
* Converts CommonMark-compatible Markdown to HTML.
|
||||
*/
|
||||
class CommonMarkConverter extends Converter
|
||||
class CommonMarkConverter extends MarkdownConverter
|
||||
{
|
||||
/**
|
||||
* The currently-installed version.
|
||||
@@ -27,10 +27,7 @@ class CommonMarkConverter extends Converter
|
||||
* @deprecated in 1.5.0 and will be removed from 2.0.0.
|
||||
* Use \Composer\InstalledVersions provided by composer-runtime-api instead.
|
||||
*/
|
||||
public const VERSION = '1.5.7';
|
||||
|
||||
/** @var EnvironmentInterface */
|
||||
protected $environment;
|
||||
public const VERSION = '1.6.2';
|
||||
|
||||
/**
|
||||
* Create a new commonmark converter instance.
|
||||
@@ -42,19 +39,14 @@ class CommonMarkConverter extends Converter
|
||||
{
|
||||
if ($environment === null) {
|
||||
$environment = Environment::createCommonMarkEnvironment();
|
||||
} else {
|
||||
@\trigger_error(\sprintf('Passing an $environment into the "%s" constructor is deprecated in 1.6 and will not be supported in 2.0; use MarkdownConverter instead', self::class), \E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
if ($environment instanceof ConfigurableEnvironmentInterface) {
|
||||
$environment->mergeConfig($config);
|
||||
}
|
||||
|
||||
$this->environment = $environment;
|
||||
|
||||
parent::__construct(new DocParser($environment), new HtmlRenderer($environment));
|
||||
}
|
||||
|
||||
public function getEnvironment(): EnvironmentInterface
|
||||
{
|
||||
return $this->environment;
|
||||
parent::__construct($environment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ interface ConfigurableEnvironmentInterface extends EnvironmentInterface
|
||||
* @param array<string, mixed> $config
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @deprecated in 1.6 and will be removed in 2.0; use mergeConfig() instead
|
||||
*/
|
||||
public function setConfig(array $config = []);
|
||||
|
||||
|
||||
+3
-3
@@ -14,7 +14,7 @@ namespace League\CommonMark;
|
||||
/**
|
||||
* Converts CommonMark-compatible Markdown to HTML.
|
||||
*
|
||||
* @deprecated This class is deprecated since league/commonmark 1.4, use CommonMarkConverter instead.
|
||||
* @deprecated This class is deprecated since league/commonmark 1.4, use MarkdownConverter instead.
|
||||
*/
|
||||
class Converter implements ConverterInterface
|
||||
{
|
||||
@@ -40,8 +40,8 @@ class Converter implements ConverterInterface
|
||||
*/
|
||||
public function __construct(DocParserInterface $docParser, ElementRendererInterface $htmlRenderer)
|
||||
{
|
||||
if (!($this instanceof CommonMarkConverter)) {
|
||||
@trigger_error(sprintf('The %s class is deprecated since league/commonmark 1.4, use %s instead.', self::class, CommonMarkConverter::class), E_USER_DEPRECATED);
|
||||
if (!($this instanceof MarkdownConverter)) {
|
||||
@trigger_error(sprintf('The %s class is deprecated since league/commonmark 1.4, use %s instead.', self::class, MarkdownConverter::class), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->docParser = $docParser;
|
||||
|
||||
+34
-2
@@ -64,14 +64,14 @@ final class EmphasisDelimiterProcessor implements DelimiterProcessorInterface, C
|
||||
|
||||
// Calculate actual number of delimiters used from this closer
|
||||
if ($opener->getLength() >= 2 && $closer->getLength() >= 2) {
|
||||
if ($this->config && $this->config->get('enable_strong', true)) {
|
||||
if ($this->enableStrong()) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($this->config && $this->config->get('enable_em', true)) {
|
||||
if ($this->enableEm()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -102,4 +102,36 @@ final class EmphasisDelimiterProcessor implements DelimiterProcessorInterface, C
|
||||
{
|
||||
$this->config = $configuration;
|
||||
}
|
||||
|
||||
private function enableStrong(): bool
|
||||
{
|
||||
if ($this->config === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$deprecatedEnableStrong = $this->config->get('enable_strong', ConfigurationInterface::MISSING);
|
||||
if ($deprecatedEnableStrong !== ConfigurationInterface::MISSING) {
|
||||
@\trigger_error('The "enable_strong" configuration option is deprecated in league/commonmark 1.6 and will be replaced with "commonmark > enable_strong" in 2.0', \E_USER_DEPRECATED);
|
||||
} else {
|
||||
$deprecatedEnableStrong = true;
|
||||
}
|
||||
|
||||
return $this->config->get('commonmark/enable_strong', $deprecatedEnableStrong);
|
||||
}
|
||||
|
||||
private function enableEm(): bool
|
||||
{
|
||||
if ($this->config === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$deprecatedEnableEm = $this->config->get('enable_em', ConfigurationInterface::MISSING);
|
||||
if ($deprecatedEnableEm !== ConfigurationInterface::MISSING) {
|
||||
@\trigger_error('The "enable_em" configuration option is deprecated in league/commonmark 1.6 and will be replaced with "commonmark > enable_em" in 2.0', \E_USER_DEPRECATED);
|
||||
} else {
|
||||
$deprecatedEnableEm = true;
|
||||
}
|
||||
|
||||
return $this->config->get('commonmark/enable_em', $deprecatedEnableEm);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-1
@@ -47,7 +47,15 @@ final class DocParser implements DocParserInterface
|
||||
{
|
||||
$this->environment = $environment;
|
||||
$this->inlineParserEngine = new InlineParserEngine($environment);
|
||||
$this->maxNestingLevel = $environment->getConfig('max_nesting_level', \INF);
|
||||
$this->maxNestingLevel = $environment->getConfig('max_nesting_level', \PHP_INT_MAX);
|
||||
|
||||
if (\is_float($this->maxNestingLevel)) {
|
||||
if ($this->maxNestingLevel === \INF) {
|
||||
@\trigger_error('Using the "INF" constant for the "max_nesting_level" configuration option is deprecated in league/commonmark 1.6 and will not be allowed in 2.0; use "PHP_INT_MAX" instead', \E_USER_DEPRECATED);
|
||||
} else {
|
||||
@\trigger_error('Using a float for the "max_nesting_level" configuration option is deprecated in league/commonmark 1.6 and will not be allowed in 2.0', \E_USER_DEPRECATED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+7
-1
@@ -104,6 +104,10 @@ final class Environment implements ConfigurableEnvironmentInterface
|
||||
|
||||
public function mergeConfig(array $config = [])
|
||||
{
|
||||
if (\func_num_args() === 0) {
|
||||
@\trigger_error('Calling Environment::mergeConfig() without any parameters is deprecated in league/commonmark 1.6 and will not be allowed in 2.0', \E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->assertUninitialized('Failed to modify configuration.');
|
||||
|
||||
$this->config->merge($config);
|
||||
@@ -111,6 +115,8 @@ final class Environment implements ConfigurableEnvironmentInterface
|
||||
|
||||
public function setConfig(array $config = [])
|
||||
{
|
||||
@\trigger_error('The Environment::setConfig() method is deprecated in league/commonmark 1.6 and will be removed in 2.0. Use mergeConfig() instead.', \E_USER_DEPRECATED);
|
||||
|
||||
$this->assertUninitialized('Failed to modify configuration.');
|
||||
|
||||
$this->config->replace($config);
|
||||
@@ -305,7 +311,7 @@ final class Environment implements ConfigurableEnvironmentInterface
|
||||
],
|
||||
'html_input' => self::HTML_INPUT_ALLOW,
|
||||
'allow_unsafe_links' => true,
|
||||
'max_nesting_level' => \INF,
|
||||
'max_nesting_level' => \PHP_INT_MAX,
|
||||
]);
|
||||
|
||||
return $environment;
|
||||
|
||||
@@ -22,6 +22,7 @@ use League\CommonMark\Delimiter\Processor\EmphasisDelimiterProcessor;
|
||||
use League\CommonMark\Inline\Element as InlineElement;
|
||||
use League\CommonMark\Inline\Parser as InlineParser;
|
||||
use League\CommonMark\Inline\Renderer as InlineRenderer;
|
||||
use League\CommonMark\Util\ConfigurationInterface;
|
||||
|
||||
final class CommonMarkCoreExtension implements ExtensionInterface
|
||||
{
|
||||
@@ -69,11 +70,25 @@ final class CommonMarkCoreExtension implements ExtensionInterface
|
||||
->addInlineRenderer(InlineElement\Text::class, new InlineRenderer\TextRenderer(), 0)
|
||||
;
|
||||
|
||||
if ($environment->getConfig('use_asterisk', true)) {
|
||||
$deprecatedUseAsterisk = $environment->getConfig('use_asterisk', ConfigurationInterface::MISSING);
|
||||
if ($deprecatedUseAsterisk !== ConfigurationInterface::MISSING) {
|
||||
@\trigger_error('The "use_asterisk" configuration option is deprecated in league/commonmark 1.6 and will be replaced with "commonmark > use_asterisk" in 2.0', \E_USER_DEPRECATED);
|
||||
} else {
|
||||
$deprecatedUseAsterisk = true;
|
||||
}
|
||||
|
||||
if ($environment->getConfig('commonmark/use_asterisk', $deprecatedUseAsterisk)) {
|
||||
$environment->addDelimiterProcessor(new EmphasisDelimiterProcessor('*'));
|
||||
}
|
||||
|
||||
if ($environment->getConfig('use_underscore', true)) {
|
||||
$deprecatedUseUnderscore = $environment->getConfig('use_underscore', ConfigurationInterface::MISSING);
|
||||
if ($deprecatedUseUnderscore !== ConfigurationInterface::MISSING) {
|
||||
@\trigger_error('The "use_underscore" configuration option is deprecated in league/commonmark 1.6 and will be replaced with "commonmark > use_underscore" in 2.0', \E_USER_DEPRECATED);
|
||||
} else {
|
||||
$deprecatedUseUnderscore = true;
|
||||
}
|
||||
|
||||
if ($environment->getConfig('commonmark/use_underscore', $deprecatedUseUnderscore)) {
|
||||
$environment->addDelimiterProcessor(new EmphasisDelimiterProcessor('_'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ final class FootnoteParser implements BlockParserInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
$match = RegexHelper::matchAll(
|
||||
$match = RegexHelper::matchFirst(
|
||||
'/^\[\^([^\n^\]]+)\]\:\s/',
|
||||
$cursor->getLine(),
|
||||
$cursor->getNextNonSpacePosition()
|
||||
|
||||
+2
-3
@@ -16,8 +16,7 @@ use League\CommonMark\Block\Element\Heading;
|
||||
use League\CommonMark\Event\DocumentParsedEvent;
|
||||
use League\CommonMark\Exception\InvalidOptionException;
|
||||
use League\CommonMark\Extension\HeadingPermalink\Slug\SlugGeneratorInterface as DeprecatedSlugGeneratorInterface;
|
||||
use League\CommonMark\Inline\Element\Code;
|
||||
use League\CommonMark\Inline\Element\Text;
|
||||
use League\CommonMark\Inline\Element\AbstractStringContainer;
|
||||
use League\CommonMark\Node\Node;
|
||||
use League\CommonMark\Normalizer\SlugNormalizer;
|
||||
use League\CommonMark\Normalizer\TextNormalizerInterface;
|
||||
@@ -119,7 +118,7 @@ final class HeadingPermalinkProcessor implements ConfigurationAwareInterface
|
||||
|
||||
$walker = $node->walker();
|
||||
while ($event = $walker->next()) {
|
||||
if ($event->isEntering() && (($child = $event->getNode()) instanceof Text || $child instanceof Code)) {
|
||||
if ($event->isEntering() && (($child = $event->getNode()) instanceof AbstractStringContainer)) {
|
||||
$text .= $child->getContent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
namespace League\CommonMark\Extension\Mention;
|
||||
|
||||
use League\CommonMark\ConfigurableEnvironmentInterface;
|
||||
use League\CommonMark\Exception\InvalidOptionException;
|
||||
use League\CommonMark\Extension\ExtensionInterface;
|
||||
use League\CommonMark\Extension\Mention\Generator\MentionGeneratorInterface;
|
||||
|
||||
@@ -21,20 +22,44 @@ final class MentionExtension implements ExtensionInterface
|
||||
{
|
||||
$mentions = $environment->getConfig('mentions', []);
|
||||
foreach ($mentions as $name => $mention) {
|
||||
foreach (['symbol', 'regex', 'generator'] as $key) {
|
||||
if (\array_key_exists('symbol', $mention)) {
|
||||
@\trigger_error('The "mentions/*/symbol" configuration option is deprecated in league/commonmark 1.6; rename "symbol" to "prefix" for compatibility with 2.0', \E_USER_DEPRECATED);
|
||||
$mention['prefix'] = $mention['symbol'];
|
||||
}
|
||||
|
||||
if (\array_key_exists('pattern', $mention)) {
|
||||
// v2.0 does not allow full regex patterns passeed into the configuration
|
||||
if (!self::isAValidPartialRegex($mention['pattern'])) {
|
||||
throw new InvalidOptionException(\sprintf('Option "mentions/%s/pattern" must not include starting/ending delimiters (like "/")', $name));
|
||||
}
|
||||
|
||||
$mention['pattern'] = '/' . $mention['pattern'] . '/i';
|
||||
} elseif (\array_key_exists('regex', $mention)) {
|
||||
@\trigger_error('The "mentions/*/regex" configuration option is deprecated in league/commonmark 1.6; rename "regex" to "pattern" for compatibility with 2.0', \E_USER_DEPRECATED);
|
||||
$mention['pattern'] = $mention['regex'];
|
||||
}
|
||||
|
||||
foreach (['prefix', 'pattern', 'generator'] as $key) {
|
||||
if (empty($mention[$key])) {
|
||||
throw new \RuntimeException("Missing \"$key\" from MentionParser configuration");
|
||||
}
|
||||
}
|
||||
if ($mention['generator'] instanceof MentionGeneratorInterface) {
|
||||
$environment->addInlineParser(new MentionParser($mention['symbol'], $mention['regex'], $mention['generator']));
|
||||
$environment->addInlineParser(new MentionParser($mention['prefix'], $mention['pattern'], $mention['generator']));
|
||||
} elseif (is_string($mention['generator'])) {
|
||||
$environment->addInlineParser(MentionParser::createWithStringTemplate($mention['symbol'], $mention['regex'], $mention['generator']));
|
||||
$environment->addInlineParser(MentionParser::createWithStringTemplate($mention['prefix'], $mention['pattern'], $mention['generator']));
|
||||
} elseif (is_callable($mention['generator'])) {
|
||||
$environment->addInlineParser(MentionParser::createWithCallback($mention['symbol'], $mention['regex'], $mention['generator']));
|
||||
$environment->addInlineParser(MentionParser::createWithCallback($mention['prefix'], $mention['pattern'], $mention['generator']));
|
||||
} else {
|
||||
throw new \RuntimeException(sprintf('The "generator" provided for the MentionParser configuration must be a string template, callable, or an object that implements %s.', MentionGeneratorInterface::class));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function isAValidPartialRegex(string $regex): bool
|
||||
{
|
||||
$regex = '/' . $regex . '/i';
|
||||
|
||||
return @\preg_match($regex, '') !== false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,11 +39,12 @@ final class TableParser implements BlockParserInterface, EnvironmentAwareInterfa
|
||||
}
|
||||
|
||||
$lines = $container->getStrings();
|
||||
if (count($lines) !== 1) {
|
||||
if (count($lines) === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (\strpos($lines[0], '|') === false) {
|
||||
$lastLine = \array_pop($lines);
|
||||
if (\strpos($lastLine, '|') === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -57,7 +58,7 @@ final class TableParser implements BlockParserInterface, EnvironmentAwareInterfa
|
||||
return false;
|
||||
}
|
||||
|
||||
$head = $this->parseRow(trim((string) array_pop($lines)), $columns, TableCell::TYPE_HEAD);
|
||||
$head = $this->parseRow(trim((string) $lastLine), $columns, TableCell::TYPE_HEAD);
|
||||
if (null === $head) {
|
||||
$cursor->restoreState($oldState);
|
||||
|
||||
|
||||
+19
-1
@@ -24,6 +24,7 @@ use League\CommonMark\Extension\TableOfContents\Normalizer\AsIsNormalizerStrateg
|
||||
use League\CommonMark\Extension\TableOfContents\Normalizer\FlatNormalizerStrategy;
|
||||
use League\CommonMark\Extension\TableOfContents\Normalizer\NormalizerStrategyInterface;
|
||||
use League\CommonMark\Extension\TableOfContents\Normalizer\RelativeNormalizerStrategy;
|
||||
use League\CommonMark\Inline\Element\AbstractStringContainer;
|
||||
use League\CommonMark\Inline\Element\Link;
|
||||
|
||||
final class TableOfContentsGenerator implements TableOfContentsGeneratorInterface
|
||||
@@ -80,7 +81,7 @@ final class TableOfContentsGenerator implements TableOfContentsGeneratorInterfac
|
||||
$toc->setEndLine($heading->getEndLine());
|
||||
|
||||
// Create the new link
|
||||
$link = new Link('#' . $headingLink->getSlug(), $heading->getStringContent());
|
||||
$link = new Link('#' . $headingLink->getSlug(), self::getHeadingText($heading));
|
||||
$paragraph = new Paragraph();
|
||||
$paragraph->setStartLine($heading->getStartLine());
|
||||
$paragraph->setEndLine($heading->getEndLine());
|
||||
@@ -151,4 +152,21 @@ final class TableOfContentsGenerator implements TableOfContentsGeneratorInterfac
|
||||
throw new InvalidOptionException(\sprintf('Invalid table of contents normalization strategy "%s"', $this->normalizationStrategy));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private static function getHeadingText(Heading $heading)
|
||||
{
|
||||
$text = '';
|
||||
|
||||
$walker = $heading->walker();
|
||||
while ($event = $walker->next()) {
|
||||
if ($event->isEntering() && ($child = $event->getNode()) instanceof AbstractStringContainer) {
|
||||
$text .= $child->getContent();
|
||||
}
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,14 @@ class GithubFlavoredMarkdownConverter extends CommonMarkConverter
|
||||
{
|
||||
if ($environment === null) {
|
||||
$environment = Environment::createGFMEnvironment();
|
||||
} else {
|
||||
@\trigger_error(\sprintf('Passing an $environment into the "%s" constructor is deprecated in 1.6 and will not be supported in 2.0; use MarkdownConverter instead', self::class), \E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
parent::__construct($config, $environment);
|
||||
if ($environment instanceof ConfigurableEnvironmentInterface) {
|
||||
$environment->mergeConfig($config);
|
||||
}
|
||||
|
||||
MarkdownConverter::__construct($environment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Colin O'Dell <colinodell@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace League\CommonMark;
|
||||
|
||||
class MarkdownConverter extends Converter
|
||||
{
|
||||
/** @var EnvironmentInterface */
|
||||
protected $environment;
|
||||
|
||||
public function __construct(EnvironmentInterface $environment)
|
||||
{
|
||||
$this->environment = $environment;
|
||||
|
||||
parent::__construct(new DocParser($environment), new HtmlRenderer($environment));
|
||||
}
|
||||
|
||||
public function getEnvironment(): EnvironmentInterface
|
||||
{
|
||||
return $this->environment;
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,10 @@ class ArrayCollection implements \IteratorAggregate, \Countable, \ArrayAccess
|
||||
public function __construct(array $elements = [])
|
||||
{
|
||||
$this->elements = $elements;
|
||||
|
||||
if (self::class !== static::class) {
|
||||
@\trigger_error('Extending the ArrayCollection class is deprecated in league/commonmark 1.6 and will not be allowed in 2.0', \E_USER_DEPRECATED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,6 +40,8 @@ final class Configuration implements ConfigurationInterface
|
||||
public function get(?string $key = null, $default = null)
|
||||
{
|
||||
if ($key === null) {
|
||||
@\trigger_error('Calling Configuration::get() without a $key is deprecated in league/commonmark 1.6 and will not be allowed in 2.0', \E_USER_DEPRECATED);
|
||||
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
@@ -57,6 +59,10 @@ final class Configuration implements ConfigurationInterface
|
||||
|
||||
public function set(string $key, $value = null)
|
||||
{
|
||||
if (\func_num_args() === 1) {
|
||||
@\trigger_error('Calling Configuration::set() without a $value is deprecated in league/commonmark 1.6 and will not be allowed in 2.0', \E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
// accept a/b/c as ['a']['b']['c']
|
||||
if (\strpos($key, '/')) {
|
||||
$this->setByPath($key, $value);
|
||||
@@ -65,6 +71,11 @@ final class Configuration implements ConfigurationInterface
|
||||
$this->config[$key] = $value;
|
||||
}
|
||||
|
||||
public function exists(string $key): bool
|
||||
{
|
||||
return $this->getConfigByPath($key, self::MISSING) !== self::MISSING;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $keyPath
|
||||
* @param string|null $default
|
||||
|
||||
@@ -13,6 +13,13 @@ namespace League\CommonMark\Util;
|
||||
|
||||
interface ConfigurationInterface
|
||||
{
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public const MISSING = '833f2700-af8d-49d4-9171-4b5f12d3bfbc';
|
||||
|
||||
/**
|
||||
* Merge an existing array into the current configuration
|
||||
*
|
||||
|
||||
@@ -102,9 +102,13 @@ final class RegexHelper
|
||||
* @param int $offset
|
||||
*
|
||||
* @return array<string>|null
|
||||
*
|
||||
* @deprecated in 1.6; use matchFirst() instead
|
||||
*/
|
||||
public static function matchAll(string $pattern, string $subject, int $offset = 0): ?array
|
||||
{
|
||||
@\trigger_error('RegexHelper::matchAll() is deprecated in league/commonmark 1.6 and will be removed in 2.0; use RegexHelper::matchFirst() instead', \E_USER_DEPRECATED);
|
||||
|
||||
if ($offset !== 0) {
|
||||
$subject = \substr($subject, $offset);
|
||||
}
|
||||
@@ -125,6 +129,28 @@ final class RegexHelper
|
||||
return $matches ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Functional wrapper around preg_match_all which only returns the first set of matches
|
||||
*
|
||||
* @return string[]|null
|
||||
*
|
||||
* @psalm-pure
|
||||
*/
|
||||
public static function matchFirst(string $pattern, string $subject, int $offset = 0): ?array
|
||||
{
|
||||
if ($offset !== 0) {
|
||||
$subject = \substr($subject, $offset);
|
||||
}
|
||||
|
||||
\preg_match_all($pattern, $subject, $matches, \PREG_SET_ORDER);
|
||||
|
||||
if ($matches === []) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $matches[0] ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace backslash escapes with literal characters
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user