diff options
Diffstat (limited to 'vendor/league')
101 files changed, 2554 insertions, 2016 deletions
diff --git a/vendor/league/commonmark/.phpstorm.meta.php b/vendor/league/commonmark/.phpstorm.meta.php index 1089f48a37..e797ee11b7 100644 --- a/vendor/league/commonmark/.phpstorm.meta.php +++ b/vendor/league/commonmark/.phpstorm.meta.php @@ -11,8 +11,8 @@ namespace PHPSTORM_META { - expectedArguments(\League\CommonMark\Context::setEncoding(), 0, 'UTF-8', 'ASCII', 'ISO-8859-1'); - expectedArguments(\League\CommonMark\Cursor::__construct(), 1, 'UTF-8', 'ASCII', 'ISO-8859-1'); + expectedArguments(\League\CommonMark\Context::setEncoding(), 0, 'UTF-8', 'ASCII'); + expectedArguments(\League\CommonMark\Cursor::__construct(), 1, 'UTF-8', 'ASCII'); expectedArguments(\League\CommonMark\HtmlElement::__construct(), 0, 'a', 'abbr', 'address', 'area', 'article', 'aside', 'audio', 'b', 'base', 'bdi', 'bdo', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'cite', 'code', 'col', 'colgroup', 'data', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'iframe', 'img', 'input', 'ins', 'kdb', 'keygen', 'label', 'legend', 'li', 'link', 'main', 'map', 'mark', 'menu', 'menuitem', 'meta', 'meter', 'nav', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'param', 'pre', 'progress', 'q', 's', 'samp', 'script', 'section', 'select', 'small', 'source', 'span', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'u', 'ul', 'var', 'video', 'wbr'); expectedArguments(\League\CommonMark\Block\Element\Heading::__construct(), 0, 1, 2, 3, 4, 5, 6); expectedReturnValues(\League\CommonMark\Block\Element\Heading::getLevel(), 1, 2, 3, 4, 5, 6); @@ -27,4 +27,9 @@ namespace PHPSTORM_META registerArgumentsSet('league_commonmark_newline_types', \League\CommonMark\Inline\Element\Newline::HARDBREAK, \League\CommonMark\Inline\Element\Newline::SOFTBREAK); expectedArguments(\League\CommonMark\Inline\Element\Newline::__construct(), 0, argumentsSet('league_commonmark_newline_types')); expectedReturnValues(\League\CommonMark\Inline\Element\Newline::getType(), argumentsSet('league_commonmark_newline_types')); + + registerArgumentsSet('league_commonmark_options', 'renderer', 'enable_em', 'enable_strong', 'use_asterisk', 'use_underscore', 'html_input', 'allow_unsafe_links', 'max_nesting_level'); + expectedArguments(\League\CommonMark\EnvironmentInterface::getConfig(), 0, argumentsSet('league_commonmark_options')); + expectedArguments(\League\CommonMark\Util\ConfigurationInterface::get(), 0, argumentsSet('league_commonmark_options')); + expectedArguments(\League\CommonMark\Util\ConfigurationInterface::set(), 0, argumentsSet('league_commonmark_options')); } diff --git a/vendor/league/commonmark/CHANGELOG-0.x.md b/vendor/league/commonmark/CHANGELOG-0.x.md new file mode 100644 index 0000000000..16f96dd124 --- /dev/null +++ b/vendor/league/commonmark/CHANGELOG-0.x.md @@ -0,0 +1,842 @@ +# Change Log +All notable changes to this project will be documented in this file. +Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) principles. + +## [0.19.3] - 2019-06-18 + +### Fixed + + - Fixed bug where elements with content of `"0"` wouldn't be rendered (#376) + +## [0.19.2] - 2019-05-19 + +### Fixed + + - Fixed bug where default values for nested configuration paths were inadvertently cast to strings + +## [0.19.1] - 2019-04-10 + +### Added + + - Added the missing `addExtension()` method to the new `ConfigurableEnvironmentInterface` + +### Fixed + + - Fixed extensions not being able to register other extensions + +## [0.19.0] - 2019-04-10 + +### Added + + - The priority of parsers, processors, and renderers can now be set when `add()`ing them; you no longer need to rely on the order in which they are added + - Added support for trying multiple parsers per block/inline + - Extracted two new base interfaces from `Environment`: + - `EnvironmentInterface` + - `ConfigurableEnvironmentInterface` + - Extracted a new `AbstractStringContainerBlock` base class and corresponding `StringContainerInterface` from `AbstractBlock` + - Added `Cursor::getEncoding()` method + - Added `.phpstorm.meta.php` file for better IDE code completion + - Made some minor optimizations here and there + +### Changed + + - Pretty much everything now has parameter and return types (#346) + - Attributes passed to `HtmlElement` will now be escaped by default + - `Environment` is now a `final` class + - `Environment::getBlockRendererForClass()` was replaced with `Environment::getBlockRenderersForClass()` (note the added `s`) + - `Environment::getInlineRendererForClass()` was replaced with `Environment::getInlineRenderersForClass()` (note the added `s`) + - The `Environment::get____()` methods now return an iterator instead of an array + - `Context::addBlock()` no longer returns the same block instance you passed into the method, as this served no useful purpose + - `RegexHelper::isEscapable()` no longer accepts `null` values + - `Node::replaceChildren()` now accepts any type of `iterable`, not just `array`s + - Some block elements now extend `AbstractStringContainerBlock` instead of `AbstractBlock` + - `InlineContainerInterface` now extends the new `StringContainerInterface` + - The `handleRemainingContents()` method (formerly on `AbstractBlock`, now on `AbstractStringContainerBlock`) is now an `abstract method + - The `InlineParserContext` constructor now requires an `AbstractStringContainerBlock` instead of an `AbstractBlock` + +### Removed + + - Removed support for PHP 5.6 and 7.0 (#346) + - Removed support for `add()`ing parsers with just the target block/inline class name - you need to include the full namespace now + - Removed the following unused methods from `Environment`: + - `getInlineParser($name)` + - `getInlineParsers()` + - `createInlineParserEngine()` + - Removed the unused `getName()` methods: + - `AbstractBlockParser::getName()` + - `AbstractInlineParser::getName()` + - `BlockParserInterface::getName()` + - `InlinerParserInterface::getName()` + - Removed the now-useless classes: + - `AbstractBlockParser` + - `AbstractInlinerParser` + - `InlineContainer` + - Removed the `AbstractBlock::acceptsLines()` method + - Removed the now-useless constructor from `AbstractBlock` + - Removed previously-deprecated functionality: + - `InlineContainer` class + - `RegexHelper::$instance` + - `RegexHelper::getInstance()` + - `RegexHelper::getPartialRegex()` + - `RegexHelper::getHtmlTagRegex()` + - `RegexHelper::getLinkTitleRegex()` + - `RegexHelper::getLinkDestinationBracesRegex()` + - `RegexHelper::getThematicBreakRegex()` + - Removed the second `$preserveEntities` parameter from `Xml:escape()` + +## [0.18.5] - 2019-03-28 + +### Fixed + + - Fixed the adjoining `Text` collapser not handling the full tree (thephpleague/commonmark-ext-autolink#10) + +## [0.18.4] - 2019-03-23 + +### Changed + + - Modified how URL normalization decodes certain characters in order to align with the JS library's output + - Disallowed unescaped `(` in parenthesized link title + +### Fixed + + - Fixed two exponential backtracking issues + +## [0.18.3] - 2019-03-21 + +This is a **security update** release. + +### Changed + + - XML/HTML entities in attributes will no longer be preserved when rendering (#353) + +### Fixed + + - Fix XSS vulnerability caused by improper preservation of entities when rendering (#353) + +### Deprecated + + - Deprecated the `$preserveEntites` argument of `Xml::escape()` for removal in the next release (#353) + +## [0.18.2] - 2019-03-16 + +### Fixed + + - Fixed adjoining `Text` elements not being collapsed after delimiter processing + +### Deprecated + + - Deprecated the `CommonmarkConverter::VERSION` constant for removal in 1.0.0 + +## [0.18.1] - 2018-12-29 + +This is a **security update** release. + +### Fixed + + - Fix XSS vulnerability caused by URL normalization not handling/encoding newlines properly (#337, CVE-2018-20583) + +## [0.18.0] - 2018-09-18 + +### Added + + - Added `ConverterInterface` to `Converter` and `CommonMarkConverter` (#330) + - Added `ListItem::getListData()` method (#329) + +### Changed + + - Links with `target="_blank"` will also get `rel="noopener noreferrer"` by default (#331) + - Implemented several performance optimizations (#324) + +## [0.17.5] - 2018-03-29 + +### Fixed + + - Fixed incorrect version constant value (again) + - Fixed release checklist to prevent the above from happening + - Fixed incorrect dates in CHANGELOG + +## [0.17.4] - 2018-03-28 + +### Added + + - Added `ListBlock::setTight()` method + +## [0.17.3] - 2018-03-26 + +### Fixed + + - Fixed incorrect version constant value + +## [0.17.2] - 2018-03-25 + +### Added + + - Added new `RegexHelper::isEscapable()` method + +### Fixed + + - Fixed spec compliance bug where escaped spaces should not be allowed in link destinations + +## [0.17.1] - 2018-03-18 + +### Added + + - Added a new constant containing the current version: `CommonMarkConverter::VERSION` (#314) + +## [0.17.0] - 2017-12-30 + +This release contains several breaking changes and a minimum PHP version bump - see <UPGRADE.md> for more details. + +### Added + + - Added new `max_nesting_level` setting (#243) + - Added minor performance optimizations to `Cursor` + +### Changed + + - Minimum PHP version is now 5.6.5. + - All full and partial regular expressions in `RegexHelper` are now defined as constants instead of being built on-the-fly. + - `Cursor::saveState()` now returns an `array` instead of a `CursorState` object. + - `Cursor::restoreState()` now accepts an `array` parameter instead of a `CursorState` object. + - Saving/restoring the Cursor state no longer tracks things that don't change (like the text content). + - `RegexHelper` is now `final`. + - References to `InlineContainer` changed to new `InlineContainerInterface` interface. + - `MiscExtension::addInlineParser()` and `MiscExtension::addBlockRenderer()` now return `$this` instead of nothing. + +### Fixed + - Fixed `Reference::normalizeReference()` not properly collapsing whitespace to a single space + +### Deprecated + + - `RegexHelper::getInstance()` and all instance (non-static) methods have been deprecated. + - The `InlineContainer` interface has been deprecated. Use `InlineContainerInterface` instead. + +### Removed + + - Removed support for PHP 5.4 and 5.5. + - Removed `CursorState` class + - Removed all previous deprecations: + - `Cursor::getFirstNonSpacePosition()` + - `Cursor::getFirstNonSpaceCharacter()` + - `Cursor::advanceWhileMatches()` + - `Cursor::advanceToFirstNonSpace()` + - `ElementRendererInterface::escape()` + - `HtmlRenderer::escape()` + - `RegexHelper::REGEX_UNICODE_WHITESPACE` + - `RegexHelper::getLinkDestinationRegex()` + +## [0.16.0] - 2017-10-30 + +This release contains breaking changes, several performance improvements, and two deprecations: + +### Added + + - Added new `Xml` utility class; moved HTML/XML escaping logic into there (see deprecations below) + +### Changed + + - `Environment::getInlineParsersForCharacter()` now returns an empty array (instead of `null`) when no matching parsers are found + - Three utility classes are now marked `final`: + - `Html5Entities` + - `LinkParserHelper` + - `UrlEncoder` + +### Fixed + + - Improved performance of several methods (for a 10% overall performance boost - #292) + +### Deprecated + +The following methods were deprecated and are scheduled for removal in 0.17.0 or 1.0.0 (whichever comes first). See <UPGRADE.md> for more information. + + - `Cursor::advanceWhileMatches()` deprecated; use `Cursor::match()` instead. + - `HtmlRenderer::escape()` deprecated; use `Xml::escape()` instead. + +### Removed + + - Removed `DelimiterStack::findFirstMatchingOpener()` which was previously deprecated in 0.15.0 + +## [0.15.7] - 2017-10-26 + +### Fixed + + - Improved performance of `Cursor::advanceBy()` (for a 16% performance boost) + +## [0.15.6] - 2017-08-08 + +### Fixed + + - Fixed URI normalization not properly encoding/decoding special characters in certain cases (#287) + +## [0.15.5] - 2017-08-05 + +This release bumps spec compliance to 0.28 without breaking changes to the API. + +### Added + + - Project is now tested against PHP 7.2 + +### Changed + + - Bumped CommonMark spec target to 0.28 + - Changed internal implementation of `LinkParserHelper::parseLinkDestination()` to allow nested parens + - Changed precedence of strong/emph when both nestings are possible (rule 14) + - Allow tabs before and after ATX closing header + +### Fixed + + - Fixed HTML type 6 block regex matching against `<pre>` (it shouldn't) and not matching `<iframe>` (it should) + - Fixed reference parser incorrectly handling escaped `]` characters + - Fixed "multiple of 3" delimiter run calculations + +### Deprecated + +An unused constant and static method were deprecated and will be removed in a future release. See <UPGRADE.md> for more information. + + - Deprecated `RegexHelper::REGEX_UNICODE_WHITESPACE` (no longer used) + - Deprecated `RegexHelper::getLinkDestinationRegex()` (no longer used) + +## [0.15.4] - 2017-05-09 + +### Added + + - Added new methods to `Cursor` (#280): + - `advanceToNextNonSpaceOrNewline()` - Identical replacement for the (now-deprecated) `advanceToFirstNonSpace()` method + - `advanceToNextNonSpaceOrTab()` - Similar replacement for `advanceToFirstNonSpace()` but with proper tab handling + - `getNextNonSpaceCharacter()` - Identical replacement for the (now-deprecated) `getFirstNonSpaceCharacter()` method + - `getNextNonSpacePosition()` - Identical replacement for the (now-deprecated) `getFirstNonSpacePosition()` method + - Added new method to `CursorState` (#280): + - `getNextNonSpaceCache()` - Identical replacement for the (now-deprecated) `getFirstNonSpaceCache()` method + +### Fixed + + - Fixed duplicate characters in non-intended lines containing tabs (#279) + +### Deprecated + +**All deprecations listed here will be removed in a future 0.x release.** See [UPGRADE.md](UPGRADE.md) for instructions on preparing your code for the eventual removal of these methods. + + - Deprecated `Cursor::advanceToFirstNonSpace()` (#280) + - Use `advanceToNextNonSpaceOrTab()` or `advanceToNextNonSpaceOrNewline()` instead, depending on your requirements + - Deprecated `Cursor::getFirstNonSpaceCharacter()` (#280) + - Use `Cursor::getNextNonSpaceCharacter()` instead + - Deprecated `Cursor::getFirstNonSpacePosition()` (#280) + - Use `Cursor::getNextNonSpacePosition()` instead + - Deprecated `CursorState::getFirstNonSpaceCache()` (#280) + - Use `CursorState::getNextNonSpaceCache()` instead + +## [0.15.3] - 2016-12-18 + +### Fixed + - Allow inline parsers matching regex delimiter to be created (#271, #272) + +## [0.15.2] - 2016-11-22 + +### Changed + - Bumped spec target version to 0.27 (#268) + - H2-H6 elements are now parsed as HTML block elements instead of HTML inlines + +### Fixed + - Fixed incomplete punctuation regex + - Fixed shortcut links not being allowed before a `(` + - Fixed distinction between Unicode whitespace and regular whitespace + +## [0.15.1] - 2016-11-08 + +### Fixed + - Fixed setext heading underlines not allowing trailing tabs (#266) + +## [0.15.0] - 2016-09-14 + +### Added + - Added preliminary support for PHP 7.1 (#259) + - Added more regression tests (#258, #260) + +### Changed + - Bumped spec target version to 0.26 (#260) + - The `CursorState` constructor requires an additional parameter (#258) + - Ordered lists cannot interupt a paragraph unless they start with `1` (#260) + - Blank list items cannot interupt a paragraph (#260) + +### Deprecated + - Deprecated `DelimiterStack::findFirstMatchingOpener()` - use `findMatchingOpener()` instead (#260) + +### Fixed + - Fixed tabs in ATX headers and thematic breaks (#260) + - Fixed issue where cursor state was not being restored properly (#258, #260) + - This fixed the lists-with-tabs regression reported in #258 + +### Removed + - Removed an unnecessary check in `Cursor::advanceBy()` (#260) + - Removed the two-blanks-break-out-of-lists feature (#260) + + +## [0.14.0] - 2016-07-02 +### Added + - The `safe` option is deprecated and replaced by 2 new options (#253, #255): + - `html_input` (`strip`, `allow` or `escape`): how to handle untrusted HTML input (the default is `strip` for BC reasons) + - `allow_unsafe_links` (`true` or `false`): whether to allow risky image URLs and links (the default is `true` for BC reasons) + +### Deprecated + - The `safe` option is now deprecated and will be removed in the 1.0.0 release. + +## [0.13.4] - 2016-06-14 + +### Fixed + - Fixed path to `autoload.php` within bin/commonmark (#250) + +## [0.13.3] - 2016-05-21 + +### Added + - Added `setUrl()` method for `Link` and `Image` elements (#227, #244) + - Added cebe/markdown to the benchmark tool (#245) + +## [0.13.2] - 2016-03-27 + +### Added + - Added ability to invoke `Converter` as a function (#233, #239) + - Added new `advanceBySpaceOrTab` convenience method to `Cursor` + +### Changed + - Bumped spec target version to 0.25 + - Adjusted how tabs are handled by the `Cursor` (#234) + - Made a couple small micro-optimizations to heavily used functions (#240) + - Updated URLs in docblocks to use HTTPS where possible (#238) + +## [0.13.1] - 2016-03-09 + +### Changed + - Refactored `EmphasisParser::parse()` to simplify it (#223) + - Updated dev dependencies (#218 & #220) + +### Fixed + - Fixed invalid regex generated when no inline parsers are defined (#224) + - Fixed logic bug with blank line after empty list item (#230) + - Fixed some incorrect code comments + +### Removed + - Removed unused variables (#223) + +## [0.13.0] - 2016-01-13 + +### Added + - Added AST document processors (#210) + - Added optional `Environment` parameter to `CommonMarkConverter` constructor + +### Changed + - Renamed "header" things to "heading" for spec consistency + - `Header` => `Heading` + - `ATXHeaderParser` => `ATXHeadingParser` + - `SetExtHeaderParser` => `SetExtHeadingParser` + - `HeaderRenderer` => `HeadingRenderer` + - Renamed "HorizontalRule" to "ThematicBreak" for spec consistency + - `HorizontalRule` => `ThematicBreak` + - `HorizontalRuleParser` => `ThematicBreakParser` + - `HorizontalRuleRenderer` => `ThematicBreakRenderer` + - `HorizontalRuleRendererTest` => `ThematicBreakRendererTest` + - `RegexHelper::getHRuleRegex()` => `RegexHelper::getThematicBreakRegex()` + - Renamed inline "Html" and "RawHtml" to "HtmlInline" for consistency + - `Html` => `HtmlInline` + - `RawHtmlParser` => `HtmlInlineParser` + - `RawHtmlRenderer` => `HtmlInlineRenderer` + - Don't allow whitespace between link text and link label of a reference link (spec change) + - Don't allow spaces in link destinations, even in `<>` + - Allow multiline setext header content + - The `Heading` constructor now allows `$contents` to be a `string` (old behavior) or `string[]` (new) + +### Fixed + - Fixed several list issues and regressions (jgm/commonmark.js#59) + +### Removed + - Removed schema whitelist from autolink regex + - Moved SmartPunct functionality into new [league/commonmark-extras](https://github.com/thephpleague/commonmark-extras) package + +## [0.12.0] - 2015-11-04 + +### Added + - Added ability to configure characters and disable emphasis/strong (#135) + - Added new ConfigurationAwareInterface support for all parsers, processors, and renderers (#201) + - Added HTML safe mode to handle untrusted input (#200, #201) + - Safe mode is disabled by default for backwards-compatibility + - To enable it, set the `safe` option to `true` + - Added AppVeyor integration for automated unit/functional testing on Windows (#195) + +### Changed + - `AbstractBlock::finalize()` now requires a second parameter, `$endLineNumber` + - `RegexHelper::REGEX_ENTITY` no longer includes the starting `/` or the ending `/i` (#194) + - `Node::setParent()` now accepts null values (#203) + +### Fixed + - Fixed incorrect `endLine` positions (#187) + - Fixed `DocParser::preProcessInput` dropping up to 2 ending newlines instead of just one + - Fixed `EntityParser` not checking for ampersands at the start of the current position (#192, #194) + +### Removed + - Removed protected function Context::addChild() + - It was a duplicate of the Context::addBlock() method + - Disabled STDIN reading on `bin/commonmark` for Windows due to PHP issues (#189, #195) + +## [0.11.3] - 2015-09-25 +### Fixed + - Reset container after closing containing lists (#183; jgm/commonmark.js#67) + - The temporary fix from 0.11.2 was reverted + +## [0.11.2] - 2015-09-23 +### Fixed + - Fixed parser checking acceptsLines on the wrong element (#183) + +## [0.11.1] - 2015-09-22 +### Changed + - Tightened up some loose comparisons + +### Fixed + - Fixed missing "bin" directive in composer.json + - Updated a docblock to match recent changes to method parameters + +### Removed + - Removed unused variable from within QuoteProcessor's closure + +## [0.11.0] - 2015-09-19 +### Added + - Added new `Node` class, which both `AbstractBlock` and `AbstractInline` extend from (#169) + - Added a `NodeWalker` and `NodeWalkerEvent` to traverse the AST without using recursion + - Added new `InlineContainer` interface for blocks + - Added new `getContainer()` and `getReferenceMap()` methods to `InlineParserContext` + - Added `iframe` to whitelist of HTML block tags (as per spec) + - Added `./bin/commonmark` for converting Markdown at the command line + +### Changed + - Bumped spec target version to 0.22 + - Revised AST to use a double-linked list (#169) + - `AbstractBlock` and `AbstractInline` both extend from `Node` + - Sub-classes must implement new `isContainer()` method + - Other major changes to `AbstractBlock`: + - `getParent()` is now `parent()` + - `setParent()` now expects a `Node` instead of an `AbstractBlock` + - `getChildren()` is now `children()` + - `getLastChild()` is now `lastChild()` + - `addChild()` is now `appendChild()` + - `InlineParserContext` is constructed using the container `AbstractBlock` and the document's `RefereceMap` + - The constructor will automatically create the `Cursor` using the container's string contents + - `InlineParserEngine::parse` now requires the `Node` container and the document's `ReferenceMap` instead of a `ContextInterface` and `Cursor` + - Changed `Delimiter` to reference the actual inline `Node` instead of the position + - The `int $pos` protected member and constructor arg is now `Node $node` + - Use `getInlineNode()` and `setInlineNode()` instead of `getPos()` and `setPos()` + - Changed `DocParser::processInlines` to use a `NodeWalker` to iterate through inlines + - Walker passed as second argument instead of `AbstractBlock` + - Uses a `while` loop instead of recursion to traverse the AST + - `Image` and `Link` now only accept a string as their second argument + - Refactored how `CloseBracketParser::parse()` works internally + - `CloseBracketParser::createInline` no longer accepts label inlines + - Disallow list item starting with multiple blank lines (see jgm/CommonMark#332) + - Modified `AbstractBlock::setLastLineBlank()` + - Functionality moved to `AbstractBlock::shouldLastLineBeBlank()` and new `DocParser::setAndPropagateLastLineBlank()` method + - `AbstractBlock::setLastLineBlank()` is now a setter method for `AbstractBlock::$lastLineBlank` + - `AbstractBlock::handleRemainingContents()` is no longer abstract + - A default implementation is provided + - Removed duplicate code from sub-classes which used the default implementation - they'll just use the parent method from now on + +### Fixed + - Fixed logic error in calculation of offset (see jgm/commonmark.js@94053a8) + - Fixed bug where `DocParser` checked the wrong method to determine remainder handling behavior + - Fixed bug where `HorizontalRuleParser` failed to advance the cursor beyond the parsed horizontal rule characters + - Fixed `DocParser` not ignoring the final newline of the input (like the reference parser does) + +### Removed + - Removed `Block\Element\AbstractInlineContainer` + - Extend `AbstractBlock` and implement `InlineContainer` instead + - Use child methods instead of `getInlines` and `setInlines` + - Removed `AbstractBlock::replaceChild()` + - Call `Node::replaceWith()` directly the child node instead + - Removed the `getInlines()` method from `InlineParserContext` + - Add parsed inlines using `$inlineContext->getContainer()->appendChild()` instead of `$inlineContext->getInlines()->add()` + - Removed the `ContextInterface` argument from `AbstractInlineParser::parse()` and `InlineParserEngine::parseCharacter` + - Removed the first `ArrayCollection $inlines` argument from `InlineProcessorInterface::processInlines()` + - Removed `CloseBracketParser::nullify()` + - Removed `pre` from rule 6 of HTML blocks (see jgm/CommonMark#355) + +## [0.10.0] - 2015-07-25 +### Added + - Added parent references to inline elements (#124) + - Added smart punctuation extension (#134) + - Added HTML block types + - Added indentation caching to the cursor + - Added automated code style checks (#133) + - Added support for tag attributes in renderers (#101, #165) + +### Changed + - Bumped spec target version to 0.21 + - Revised HTML block parsing to conform to new spec (jgm/commonmark.js@99bd473) + - Imposed 9-digit limit on ordered list markers, per spec + - Allow non-initial hyphens in html tag names (jgm/CommonMark#239) + - Updated list of block tag names + - Changed tab/indentation handling to meet the new spec behavior + - Modified spec tests to show spaces and tabs in test results + - Replaced `HtmlRendererInterface` with `ElementRendererInterface` (#141) + - Removed the unnecessary `trim()` and string cast from `ListItemRenderer` + +### Fixed + - Fixed link reference definition edge case (#120) + - Allow literal (non-escaping) backslashes in link destinations (#118) + - Allow backslash-escaped backslashes in link labels (#119) + - Allow link labels up to 999 characters (per the spec) + - Properly split on whitespace when determining code block class (jgm/commonmark.js#54) + - Fixed code style issues (#132, #133, #151, #152) + - Fixed wording for invalid inline exception (#136) + +### Removed + - Removed the advance-by-one optimization due to added cursor complexity + +## [0.9.0] - 2015-06-18 +### Added + - Added public $data array to block elements (#95) + - Added `isIndented` helper method to `Cursor` + - Added a new `Converter` base class which `CommonMarkConverter` extends from (#105) + +### Changed + - Bumped spec target version to 0.20 (#112) + - Renamed ListBlock::$data and ListItem::$data to $listData + - Require link labels to contain non-whitespace (jgm/CommonMark#322) + - Use U+FFFD for entities resolving to 0 (jgm/CommonMark#323) + - Moved `IndentedCodeParser::CODE_INDENT_LEVEL` to `Cursor::INDENT_LEVEL` + - Changed arrays to short syntax (#116) + - Improved efficiency of DelimiterStack iteration (jgm/commonmark.js#43) + +### Fixed + - Fixed open block tag followed by newline not being recognized (jgm/CommonMark#324) + - Fixed indented lists sometimes being parsed incorrectly (jgm/commonmark.js#42) + +## [0.8.0] - 2015-04-29 +### Added + - Allow swapping built-in renderers without using their fully qualified names (#84) + - Lots of unit tests (for existing code) + - Ability to include arbitrary functional tests in addition to spec-based tests + +### Changed + - Dropped support for PHP 5.3 (#64 and #76) + - Bumped spec target version to 0.19 + - Made the AbstractInlineContainer be abstract + - Moved environment config. logic into separate class + +### Fixed + - Fixed underscore emphasis to conform to spec changes (jgm/CommonMark#317) + +### Removed + - Removed PHP 5.3 workaround (see commit 5747822) + - Removed unused AbstractWebResource::setUrl() method + - Removed unnecessary check for hrule when parsing lists (#85) + +## [0.7.2] - 2015-03-08 +### Changed + - Bumped spec target version to 0.18 + +### Fixed + - Fixed broken parsing of emphasized text ending with a '0' character (#81) + +## [0.7.1] - 2015-03-01 +### Added + - All references can now be obtained from the `ReferenceMap` via `listReferences()` (#73) + - Test against PHP 7.0 (nightly) but allow failures + +### Changed + - ListData::$start now defaults to null instead of 0 (#74) + - Replace references to HtmlRenderer with new HtmlRendererInterface + +### Fixed + - Fixed 0-based ordered lists starting at 1 instead of 0 (#74) + - Fixed errors parsing multi-byte characters (#78 and #79) + +## [0.7.0] - 2015-02-16 +### Added + - More unit tests to increase code coverage + +### Changed + - Enabled the InlineParserEngine to parse several non-special characters at once (performance boost) + - NewlineParser no longer attempts to parse spaces; look-behind is used instead (major performance boost) + - Moved closeUnmatchedBlocks into its own class + - Image and link elements now extend AbstractInlineContainer; label data is stored via $inlineContents instead + - Renamed AbstractInlineContainer::$inlineContents and its getter/setter + +### Removed + - Removed the InlineCollection class + - Removed the unused ArrayCollection::splice() method + - Removed impossible-to-reach code in Cursor::advanceToFirstNonSpace + - Removed unnecessary test from the InlineParserEngine + - Removed unnecessary/unused RegexHelper::getMainRegex() method + +## [0.6.1] - 2015-01-25 +### Changed + - Bumped spec target version to 0.17 + - Updated emphasis parsing for underscores to prevent intra-word emphasis + - Deferred closing of fenced code blocks + +## [0.6.0] - 2015-01-09 +### Added + - Bulk registration of parsers/renderers via extensions (#45) + - Proper UTF-8 support, especially in the Cursor; mbstring extension is now required (#49) + - Environment is now configurable; options can be accessed in its parsers/renderers (#56) + - Added some unit tests + +### Changed + - Bumped spec target version to 0.15 (#50) + - Parsers/renderers are now lazy-initialized (#52) + - Some private elements are now protected for easier extending, especially on Element classes (#53) + - Renderer option keys changed from camelCase to underscore_case (#56) + - Moved CommonMark parser/render definitions into CommonMarkCoreExtension + +### Fixed + - Improved parsing of emphasis around punctuation + - Improved regexes for CDATA and HTML comments + - Fixed issue with HTML content that is considered false in loose comparisons, like `'0'` (#55) + - Fixed DocParser trying to add empty strings to closed containers (#58) + - Fixed incorrect use of a null parameter value in the HtmlElementTest + +### Removed + - Removed unused ReferenceDefinition* classes (#51) + - Removed UnicodeCaseFolder in favor of mb_strtoupper + +## [0.5.1] - 2014-12-27 +### Fixed + - Fixed infinite loop and link-in-link-in-image parsing (#37) + +### Removed + - Removed hard dependency on mbstring extension; workaround used if not installed (#38) + +## [0.5.0] - 2014-12-24 +### Added + - Support for custom directives, parsers, and renderers + +### Changed + - Major refactoring to de-couple directives from the parser, support custom directive functionality, and reduce complexity + - Updated references to stmd.js in README and docblocks + - Modified CHANGELOG formatting + - Improved travis configuration + - Put tests in autoload-dev + +### Fixed + - Fixed CommonMarkConverter re-creating object each time new text is converted (#26) + +### Removed + - Removed HtmlRenderer::render() (use the renderBlock method instead) + - Removed dependency on symfony/options-resolver (fixes #20) + +## [0.4.0] - 2014-12-15 +### Added + - Added some missing copyright info + +### Changed + - Changed namespace to League\CommonMark + - Made compatible with spec version 0.13 + - Moved delimiter stack functionality into separate class + +### Fixed + - Fixed regex which caused HHVM tests to fail + +## [0.3.0] - 2014-11-28 +### Added + - Made renderer options configurable (issue #7) + +### Changed + - Made compatible with spec version 0.12 + - Stack-based parsing now used for emphasis, links and images + - Protected some of the internal renderer methods which shouldn't have been `public` + - Minor code clean-up (including PSR-2 compliance) + +### Removed + - Removed unnecessary distinction between ATX and Setext headers + +## [0.2.1] - 2014-11-09 +### Added + - Added simpler string replacement to a method + +### Changed + - Removed "is" prefix from boolean methods + * Updated to latest version of PHPUnit + * Target specific spec version + +## [0.2.0] - 2014-11-09 +### Changed + - Mirrored significant changes and improvements from stmd.js + - Made compatible with spec version 0.10 + - Updated location of JGM's repository + - Allowed HHVM tests to fail without affecting overall build success + +### Removed + - Removed composer.lock + - Removed fixed reference to jgm/stmd@0275f34 + +## [0.1.2] - 2014-09-28 +### Added + - Added performance benchmarking tool (issue #2) + - Added more badges to the README + +### Changed + - Fix JS -> PHP null judgement (issue #4) + - Updated phpunit dependency + +## [0.1.1] - 2014-09-08 +### Added + - Add anchors to regexes + +### Changed + - Updated target spec (now compatible with jgm/stmd:spec.txt @ 2cf0750) + - Adjust HTML output for fenced code + - Adjust block-level tag regex (remove "br", add "iframe") + - Fix incorrect handling of nested emphasis + +## 0.1.0 +### Added + - Initial commit (compatible with jgm/stmd:spec.txt @ 0275f34) + +[0.19.3]: https://github.com/thephpleague/commonmark/compare/0.19.2...0.19.3 +[0.19.2]: https://github.com/thephpleague/commonmark/compare/0.19.1...0.19.2 +[0.19.1]: https://github.com/thephpleague/commonmark/compare/0.19.0...0.19.1 +[0.19.0]: https://github.com/thephpleague/commonmark/compare/0.18.5...0.19.0 +[0.18.5]: https://github.com/thephpleague/commonmark/compare/0.18.4...0.18.5 +[0.18.4]: https://github.com/thephpleague/commonmark/compare/0.18.3...0.18.4 +[0.18.3]: https://github.com/thephpleague/commonmark/compare/0.18.2...0.18.3 +[0.18.2]: https://github.com/thephpleague/commonmark/compare/0.18.1...0.18.2 +[0.18.1]: https://github.com/thephpleague/commonmark/compare/0.18.0...0.18.1 +[0.18.0]: https://github.com/thephpleague/commonmark/compare/0.17.5...0.18.0 +[0.17.5]: https://github.com/thephpleague/commonmark/compare/0.17.4...0.17.5 +[0.17.4]: https://github.com/thephpleague/commonmark/compare/0.17.3...0.17.4 +[0.17.3]: https://github.com/thephpleague/commonmark/compare/0.17.2...0.17.3 +[0.17.2]: https://github.com/thephpleague/commonmark/compare/0.17.1...0.17.2 +[0.17.1]: https://github.com/thephpleague/commonmark/compare/0.17.0...0.17.1 +[0.17.0]: https://github.com/thephpleague/commonmark/compare/0.16.0...0.17.0 +[0.16.0]: https://github.com/thephpleague/commonmark/compare/0.15.7...0.16.0 +[0.15.7]: https://github.com/thephpleague/commonmark/compare/0.15.6...0.15.7 +[0.15.6]: https://github.com/thephpleague/commonmark/compare/0.15.5...0.15.6 +[0.15.5]: https://github.com/thephpleague/commonmark/compare/0.15.4...0.15.5 +[0.15.4]: https://github.com/thephpleague/commonmark/compare/0.15.3...0.15.4 +[0.15.3]: https://github.com/thephpleague/commonmark/compare/0.15.2...0.15.3 +[0.15.2]: https://github.com/thephpleague/commonmark/compare/0.15.1...0.15.2 +[0.15.1]: https://github.com/thephpleague/commonmark/compare/0.15.0...0.15.1 +[0.15.0]: https://github.com/thephpleague/commonmark/compare/0.14.0...0.15.0 +[0.14.0]: https://github.com/thephpleague/commonmark/compare/0.13.4...0.14.0 +[0.13.4]: https://github.com/thephpleague/commonmark/compare/0.13.3...0.13.4 +[0.13.3]: https://github.com/thephpleague/commonmark/compare/0.13.2...0.13.3 +[0.13.2]: https://github.com/thephpleague/commonmark/compare/0.13.1...0.13.2 +[0.13.1]: https://github.com/thephpleague/commonmark/compare/0.13.0...0.13.1 +[0.13.0]: https://github.com/thephpleague/commonmark/compare/0.12.0...0.13.0 +[0.12.0]: https://github.com/thephpleague/commonmark/compare/0.11.3...0.12.0 +[0.11.3]: https://github.com/thephpleague/commonmark/compare/0.11.2...0.11.3 +[0.11.2]: https://github.com/thephpleague/commonmark/compare/0.11.1...0.11.2 +[0.11.1]: https://github.com/thephpleague/commonmark/compare/0.11.0...0.11.1 +[0.11.0]: https://github.com/thephpleague/commonmark/compare/0.10.0...0.11.0 +[0.10.0]: https://github.com/thephpleague/commonmark/compare/0.9.0...0.10.0 +[0.9.0]: https://github.com/thephpleague/commonmark/compare/0.8.0...0.9.0 +[0.8.0]: https://github.com/thephpleague/commonmark/compare/0.7.2...0.8.0 +[0.7.2]: https://github.com/thephpleague/commonmark/compare/0.7.1...0.7.2 +[0.7.1]: https://github.com/thephpleague/commonmark/compare/0.7.0...0.7.1 +[0.7.0]: https://github.com/thephpleague/commonmark/compare/0.6.1...0.7.0 +[0.6.1]: https://github.com/thephpleague/commonmark/compare/0.6.0...0.6.1 +[0.6.0]: https://github.com/thephpleague/commonmark/compare/0.5.1...0.6.0 +[0.5.1]: https://github.com/thephpleague/commonmark/compare/0.5.0...0.5.1 +[0.5.0]: https://github.com/thephpleague/commonmark/compare/0.4.0...0.5.0 +[0.4.0]: https://github.com/thephpleague/commonmark/compare/0.3.0...0.4.0 +[0.3.0]: https://github.com/thephpleague/commonmark/compare/0.2.1...0.3.0 +[0.2.1]: https://github.com/thephpleague/commonmark/compare/0.2.0...0.2.1 +[0.2.0]: https://github.com/thephpleague/commonmark/compare/0.1.2...0.2.0 +[0.1.2]: https://github.com/thephpleague/commonmark/compare/0.1.1...0.1.2 +[0.1.1]: https://github.com/thephpleague/commonmark/compare/0.1.0...0.1.1 diff --git a/vendor/league/commonmark/CHANGELOG.md b/vendor/league/commonmark/CHANGELOG.md index 17b2335049..73aadb95e1 100644 --- a/vendor/league/commonmark/CHANGELOG.md +++ b/vendor/league/commonmark/CHANGELOG.md @@ -4,842 +4,154 @@ Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) princi ## [Unreleased][unreleased] -## [0.19.3] - 2019-06-18 +## [1.0.0] - 2019-06-29 -### Fixed - - - Fixed bug where elements with content of `"0"` wouldn't be rendered (#376) - -## [0.19.2] - 2019-05-19 - -### Fixed - - - Fixed bug where default values for nested configuration paths were inadvertently cast to strings - -## [0.19.1] - 2019-04-10 - -### Added - - - Added the missing `addExtension()` method to the new `ConfigurableEnvironmentInterface` - -### Fixed - - - Fixed extensions not being able to register other extensions - -## [0.19.0] - 2019-04-10 - -### Added - - - The priority of parsers, processors, and renderers can now be set when `add()`ing them; you no longer need to rely on the order in which they are added - - Added support for trying multiple parsers per block/inline - - Extracted two new base interfaces from `Environment`: - - `EnvironmentInterface` - - `ConfigurableEnvironmentInterface` - - Extracted a new `AbstractStringContainerBlock` base class and corresponding `StringContainerInterface` from `AbstractBlock` - - Added `Cursor::getEncoding()` method - - Added `.phpstorm.meta.php` file for better IDE code completion - - Made some minor optimizations here and there - -### Changed - - - Pretty much everything now has parameter and return types (#346) - - Attributes passed to `HtmlElement` will now be escaped by default - - `Environment` is now a `final` class - - `Environment::getBlockRendererForClass()` was replaced with `Environment::getBlockRenderersForClass()` (note the added `s`) - - `Environment::getInlineRendererForClass()` was replaced with `Environment::getInlineRenderersForClass()` (note the added `s`) - - The `Environment::get____()` methods now return an iterator instead of an array - - `Context::addBlock()` no longer returns the same block instance you passed into the method, as this served no useful purpose - - `RegexHelper::isEscapable()` no longer accepts `null` values - - `Node::replaceChildren()` now accepts any type of `iterable`, not just `array`s - - Some block elements now extend `AbstractStringContainerBlock` instead of `AbstractBlock` - - `InlineContainerInterface` now extends the new `StringContainerInterface` - - The `handleRemainingContents()` method (formerly on `AbstractBlock`, now on `AbstractStringContainerBlock`) is now an `abstract method - - The `InlineParserContext` constructor now requires an `AbstractStringContainerBlock` instead of an `AbstractBlock` - -### Removed - - - Removed support for PHP 5.6 and 7.0 (#346) - - Removed support for `add()`ing parsers with just the target block/inline class name - you need to include the full namespace now - - Removed the following unused methods from `Environment`: - - `getInlineParser($name)` - - `getInlineParsers()` - - `createInlineParserEngine()` - - Removed the unused `getName()` methods: - - `AbstractBlockParser::getName()` - - `AbstractInlineParser::getName()` - - `BlockParserInterface::getName()` - - `InlinerParserInterface::getName()` - - Removed the now-useless classes: - - `AbstractBlockParser` - - `AbstractInlinerParser` - - `InlineContainer` - - Removed the `AbstractBlock::acceptsLines()` method - - Removed the now-useless constructor from `AbstractBlock` - - Removed previously-deprecated functionality: - - `InlineContainer` class - - `RegexHelper::$instance` - - `RegexHelper::getInstance()` - - `RegexHelper::getPartialRegex()` - - `RegexHelper::getHtmlTagRegex()` - - `RegexHelper::getLinkTitleRegex()` - - `RegexHelper::getLinkDestinationBracesRegex()` - - `RegexHelper::getThematicBreakRegex()` - - Removed the second `$preserveEntities` parameter from `Xml:escape()` - -## [0.18.5] - 2019-03-28 - -### Fixed - - - Fixed the adjoining `Text` collapser not handling the full tree (thephpleague/commonmark-ext-autolink#10) - -## [0.18.4] - 2019-03-23 - -### Changed - - - Modified how URL normalization decodes certain characters in order to align with the JS library's output - - Disallowed unescaped `(` in parenthesized link title - -### Fixed - - - Fixed two exponential backtracking issues - -## [0.18.3] - 2019-03-21 - -This is a **security update** release. - -### Changed - - - XML/HTML entities in attributes will no longer be preserved when rendering (#353) - -### Fixed - - - Fix XSS vulnerability caused by improper preservation of entities when rendering (#353) - -### Deprecated - - - Deprecated the `$preserveEntites` argument of `Xml::escape()` for removal in the next release (#353) - -## [0.18.2] - 2019-03-16 - -### Fixed - - - Fixed adjoining `Text` elements not being collapsed after delimiter processing - -### Deprecated - - - Deprecated the `CommonmarkConverter::VERSION` constant for removal in 1.0.0 - -## [0.18.1] - 2018-12-29 - -This is a **security update** release. - -### Fixed - - - Fix XSS vulnerability caused by URL normalization not handling/encoding newlines properly (#337, CVE-2018-20583) - -## [0.18.0] - 2018-09-18 - -### Added - - - Added `ConverterInterface` to `Converter` and `CommonMarkConverter` (#330) - - Added `ListItem::getListData()` method (#329) - -### Changed - - - Links with `target="_blank"` will also get `rel="noopener noreferrer"` by default (#331) - - Implemented several performance optimizations (#324) - -## [0.17.5] - 2018-03-29 - -### Fixed - - - Fixed incorrect version constant value (again) - - Fixed release checklist to prevent the above from happening - - Fixed incorrect dates in CHANGELOG - -## [0.17.4] - 2018-03-28 - -### Added - - - Added `ListBlock::setTight()` method - -## [0.17.3] - 2018-03-26 - -### Fixed - - - Fixed incorrect version constant value - -## [0.17.2] - 2018-03-25 - -### Added - - - Added new `RegexHelper::isEscapable()` method - -### Fixed - - - Fixed spec compliance bug where escaped spaces should not be allowed in link destinations - -## [0.17.1] - 2018-03-18 - -### Added - - - Added a new constant containing the current version: `CommonMarkConverter::VERSION` (#314) - -## [0.17.0] - 2017-12-30 - -This release contains several breaking changes and a minimum PHP version bump - see <UPGRADE.md> for more details. - -### Added - - - Added new `max_nesting_level` setting (#243) - - Added minor performance optimizations to `Cursor` - -### Changed - - - Minimum PHP version is now 5.6.5. - - All full and partial regular expressions in `RegexHelper` are now defined as constants instead of being built on-the-fly. - - `Cursor::saveState()` now returns an `array` instead of a `CursorState` object. - - `Cursor::restoreState()` now accepts an `array` parameter instead of a `CursorState` object. - - Saving/restoring the Cursor state no longer tracks things that don't change (like the text content). - - `RegexHelper` is now `final`. - - References to `InlineContainer` changed to new `InlineContainerInterface` interface. - - `MiscExtension::addInlineParser()` and `MiscExtension::addBlockRenderer()` now return `$this` instead of nothing. - -### Fixed - - Fixed `Reference::normalizeReference()` not properly collapsing whitespace to a single space - -### Deprecated - - - `RegexHelper::getInstance()` and all instance (non-static) methods have been deprecated. - - The `InlineContainer` interface has been deprecated. Use `InlineContainerInterface` instead. - -### Removed - - - Removed support for PHP 5.4 and 5.5. - - Removed `CursorState` class - - Removed all previous deprecations: - - `Cursor::getFirstNonSpacePosition()` - - `Cursor::getFirstNonSpaceCharacter()` - - `Cursor::advanceWhileMatches()` - - `Cursor::advanceToFirstNonSpace()` - - `ElementRendererInterface::escape()` - - `HtmlRenderer::escape()` - - `RegexHelper::REGEX_UNICODE_WHITESPACE` - - `RegexHelper::getLinkDestinationRegex()` - -## [0.16.0] - 2017-10-30 - -This release contains breaking changes, several performance improvements, and two deprecations: - -### Added - - - Added new `Xml` utility class; moved HTML/XML escaping logic into there (see deprecations below) - -### Changed - - - `Environment::getInlineParsersForCharacter()` now returns an empty array (instead of `null`) when no matching parsers are found - - Three utility classes are now marked `final`: - - `Html5Entities` - - `LinkParserHelper` - - `UrlEncoder` - -### Fixed - - - Improved performance of several methods (for a 10% overall performance boost - #292) - -### Deprecated - -The following methods were deprecated and are scheduled for removal in 0.17.0 or 1.0.0 (whichever comes first). See <UPGRADE.md> for more information. - - - `Cursor::advanceWhileMatches()` deprecated; use `Cursor::match()` instead. - - `HtmlRenderer::escape()` deprecated; use `Xml::escape()` instead. - -### Removed - - - Removed `DelimiterStack::findFirstMatchingOpener()` which was previously deprecated in 0.15.0 - -## [0.15.7] - 2017-10-26 - -### Fixed - - - Improved performance of `Cursor::advanceBy()` (for a 16% performance boost) - -## [0.15.6] - 2017-08-08 - -### Fixed - - - Fixed URI normalization not properly encoding/decoding special characters in certain cases (#287) - -## [0.15.5] - 2017-08-05 - -This release bumps spec compliance to 0.28 without breaking changes to the API. - -### Added - - - Project is now tested against PHP 7.2 - -### Changed - - - Bumped CommonMark spec target to 0.28 - - Changed internal implementation of `LinkParserHelper::parseLinkDestination()` to allow nested parens - - Changed precedence of strong/emph when both nestings are possible (rule 14) - - Allow tabs before and after ATX closing header - -### Fixed - - - Fixed HTML type 6 block regex matching against `<pre>` (it shouldn't) and not matching `<iframe>` (it should) - - Fixed reference parser incorrectly handling escaped `]` characters - - Fixed "multiple of 3" delimiter run calculations +No changes were made since 1.0.0-rc1. -### Deprecated - -An unused constant and static method were deprecated and will be removed in a future release. See <UPGRADE.md> for more information. - - - Deprecated `RegexHelper::REGEX_UNICODE_WHITESPACE` (no longer used) - - Deprecated `RegexHelper::getLinkDestinationRegex()` (no longer used) - -## [0.15.4] - 2017-05-09 +## [1.0.0-rc1] - 2019-06-19 ### Added - - Added new methods to `Cursor` (#280): - - `advanceToNextNonSpaceOrNewline()` - Identical replacement for the (now-deprecated) `advanceToFirstNonSpace()` method - - `advanceToNextNonSpaceOrTab()` - Similar replacement for `advanceToFirstNonSpace()` but with proper tab handling - - `getNextNonSpaceCharacter()` - Identical replacement for the (now-deprecated) `getFirstNonSpaceCharacter()` method - - `getNextNonSpacePosition()` - Identical replacement for the (now-deprecated) `getFirstNonSpacePosition()` method - - Added new method to `CursorState` (#280): - - `getNextNonSpaceCache()` - Identical replacement for the (now-deprecated) `getFirstNonSpaceCache()` method - -### Fixed - - - Fixed duplicate characters in non-intended lines containing tabs (#279) - -### Deprecated - -**All deprecations listed here will be removed in a future 0.x release.** See [UPGRADE.md](UPGRADE.md) for instructions on preparing your code for the eventual removal of these methods. - - - Deprecated `Cursor::advanceToFirstNonSpace()` (#280) - - Use `advanceToNextNonSpaceOrTab()` or `advanceToNextNonSpaceOrNewline()` instead, depending on your requirements - - Deprecated `Cursor::getFirstNonSpaceCharacter()` (#280) - - Use `Cursor::getNextNonSpaceCharacter()` instead - - Deprecated `Cursor::getFirstNonSpacePosition()` (#280) - - Use `Cursor::getNextNonSpacePosition()` instead - - Deprecated `CursorState::getFirstNonSpaceCache()` (#280) - - Use `CursorState::getNextNonSpaceCache()` instead - -## [0.15.3] - 2016-12-18 - -### Fixed - - Allow inline parsers matching regex delimiter to be created (#271, #272) - -## [0.15.2] - 2016-11-22 - -### Changed - - Bumped spec target version to 0.27 (#268) - - H2-H6 elements are now parsed as HTML block elements instead of HTML inlines - -### Fixed - - Fixed incomplete punctuation regex - - Fixed shortcut links not being allowed before a `(` - - Fixed distinction between Unicode whitespace and regular whitespace - -## [0.15.1] - 2016-11-08 - -### Fixed - - Fixed setext heading underlines not allowing trailing tabs (#266) - -## [0.15.0] - 2016-09-14 - -### Added - - Added preliminary support for PHP 7.1 (#259) - - Added more regression tests (#258, #260) + - Extracted a `ReferenceMapInterface` from the `ReferenceMap` class + - Added optional `ReferenceMapInterface` parameter to the `Document` constructor ### Changed - - Bumped spec target version to 0.26 (#260) - - The `CursorState` constructor requires an additional parameter (#258) - - Ordered lists cannot interupt a paragraph unless they start with `1` (#260) - - Blank list items cannot interupt a paragraph (#260) - -### Deprecated - - Deprecated `DelimiterStack::findFirstMatchingOpener()` - use `findMatchingOpener()` instead (#260) - -### Fixed - - Fixed tabs in ATX headers and thematic breaks (#260) - - Fixed issue where cursor state was not being restored properly (#258, #260) - - This fixed the lists-with-tabs regression reported in #258 - -### Removed - - Removed an unnecessary check in `Cursor::advanceBy()` (#260) - - Removed the two-blanks-break-out-of-lists feature (#260) - - -## [0.14.0] - 2016-07-02 -### Added - - The `safe` option is deprecated and replaced by 2 new options (#253, #255): - - `html_input` (`strip`, `allow` or `escape`): how to handle untrusted HTML input (the default is `strip` for BC reasons) - - `allow_unsafe_links` (`true` or `false`): whether to allow risky image URLs and links (the default is `true` for BC reasons) - -### Deprecated - - The `safe` option is now deprecated and will be removed in the 1.0.0 release. -## [0.13.4] - 2016-06-14 + - Replaced all references to `ReferenceMap` with `ReferenceMapInterface` + - `ReferenceMap::addReference()` no longer returns `$this` ### Fixed - - Fixed path to `autoload.php` within bin/commonmark (#250) -## [0.13.3] - 2016-05-21 - -### Added - - Added `setUrl()` method for `Link` and `Image` elements (#227, #244) - - Added cebe/markdown to the benchmark tool (#245) + - Fixed bug where elements with content of `"0"` wouldn't be rendered (#376) -## [0.13.2] - 2016-03-27 +## [1.0.0-beta4] - 2019-06-05 ### Added - - Added ability to invoke `Converter` as a function (#233, #239) - - Added new `advanceBySpaceOrTab` convenience method to `Cursor` - -### Changed - - Bumped spec target version to 0.25 - - Adjusted how tabs are handled by the `Cursor` (#234) - - Made a couple small micro-optimizations to heavily used functions (#240) - - Updated URLs in docblocks to use HTTPS where possible (#238) -## [0.13.1] - 2016-03-09 - -### Changed - - Refactored `EmphasisParser::parse()` to simplify it (#223) - - Updated dev dependencies (#218 & #220) - -### Fixed - - Fixed invalid regex generated when no inline parsers are defined (#224) - - Fixed logic bug with blank line after empty list item (#230) - - Fixed some incorrect code comments + - Added event dispatcher functionality (#359, #372) ### Removed - - Removed unused variables (#223) -## [0.13.0] - 2016-01-13 + - Removed `DocumentProcessorInterface` functionality in favor of event dispatching (#373) -### Added - - Added AST document processors (#210) - - Added optional `Environment` parameter to `CommonMarkConverter` constructor +## [1.0.0-beta3] - 2019-05-27 ### Changed - - Renamed "header" things to "heading" for spec consistency - - `Header` => `Heading` - - `ATXHeaderParser` => `ATXHeadingParser` - - `SetExtHeaderParser` => `SetExtHeadingParser` - - `HeaderRenderer` => `HeadingRenderer` - - Renamed "HorizontalRule" to "ThematicBreak" for spec consistency - - `HorizontalRule` => `ThematicBreak` - - `HorizontalRuleParser` => `ThematicBreakParser` - - `HorizontalRuleRenderer` => `ThematicBreakRenderer` - - `HorizontalRuleRendererTest` => `ThematicBreakRendererTest` - - `RegexHelper::getHRuleRegex()` => `RegexHelper::getThematicBreakRegex()` - - Renamed inline "Html" and "RawHtml" to "HtmlInline" for consistency - - `Html` => `HtmlInline` - - `RawHtmlParser` => `HtmlInlineParser` - - `RawHtmlRenderer` => `HtmlInlineRenderer` - - Don't allow whitespace between link text and link label of a reference link (spec change) - - Don't allow spaces in link destinations, even in `<>` - - Allow multiline setext header content - - The `Heading` constructor now allows `$contents` to be a `string` (old behavior) or `string[]` (new) -### Fixed - - Fixed several list issues and regressions (jgm/commonmark.js#59) + - Made the `Delimiter` class final and extracted a new `DelimiterInterface` + - Modified most external usages to use this new interface + - Renamed three `Delimiter` methods: + - `getOrigDelims()` renamed to `getOriginalLength()` + - `getNumDelims()` renamed to `getLength()` + - `setNumDelims()` renamed to `setLength()` + - Made additional classes final: + - `DelimiterStack` + - `ReferenceMap` + - `ReferenceParser` + - Moved `ReferenceParser` into the `Reference` sub-namespace ### Removed - - Removed schema whitelist from autolink regex - - Moved SmartPunct functionality into new [league/commonmark-extras](https://github.com/thephpleague/commonmark-extras) package -## [0.12.0] - 2015-11-04 + - Removed unused `Delimiter` methods: + - `setCanOpen()` + - `setCanClose()` + - `setChar()` + - `setIndex()` + - `setInlineNode()` + - Removed fluent interface from `Delimiter` (setter methods now have no return values) -### Added - - Added ability to configure characters and disable emphasis/strong (#135) - - Added new ConfigurationAwareInterface support for all parsers, processors, and renderers (#201) - - Added HTML safe mode to handle untrusted input (#200, #201) - - Safe mode is disabled by default for backwards-compatibility - - To enable it, set the `safe` option to `true` - - Added AppVeyor integration for automated unit/functional testing on Windows (#195) +## [1.0.0-beta2] - 2019-05-27 ### Changed - - `AbstractBlock::finalize()` now requires a second parameter, `$endLineNumber` - - `RegexHelper::REGEX_ENTITY` no longer includes the starting `/` or the ending `/i` (#194) - - `Node::setParent()` now accepts null values (#203) -### Fixed - - Fixed incorrect `endLine` positions (#187) - - Fixed `DocParser::preProcessInput` dropping up to 2 ending newlines instead of just one - - Fixed `EntityParser` not checking for ampersands at the start of the current position (#192, #194) + - `DelimiterProcessorInterface::process()` will accept any type of `AbstractStringContainer` now, not just `Text` nodes + - The `Delimiter` constructor, `getInlineNode()`, and `setInlineNode()` no longer accept generic `Node` elements - only `AbstractStringContainer`s -### Removed - - Removed protected function Context::addChild() - - It was a duplicate of the Context::addBlock() method - - Disabled STDIN reading on `bin/commonmark` for Windows due to PHP issues (#189, #195) - -## [0.11.3] - 2015-09-25 -### Fixed - - Reset container after closing containing lists (#183; jgm/commonmark.js#67) - - The temporary fix from 0.11.2 was reverted - -## [0.11.2] - 2015-09-23 -### Fixed - - Fixed parser checking acceptsLines on the wrong element (#183) - -## [0.11.1] - 2015-09-22 -### Changed - - Tightened up some loose comparisons - -### Fixed - - Fixed missing "bin" directive in composer.json - - Updated a docblock to match recent changes to method parameters ### Removed - - Removed unused variable from within QuoteProcessor's closure -## [0.11.0] - 2015-09-19 -### Added - - Added new `Node` class, which both `AbstractBlock` and `AbstractInline` extend from (#169) - - Added a `NodeWalker` and `NodeWalkerEvent` to traverse the AST without using recursion - - Added new `InlineContainer` interface for blocks - - Added new `getContainer()` and `getReferenceMap()` methods to `InlineParserContext` - - Added `iframe` to whitelist of HTML block tags (as per spec) - - Added `./bin/commonmark` for converting Markdown at the command line + - Removed all deprecated functionality: + - The `safe` option (use `html_input` and `allow_unsafe_links` options instead) + - All deprecated `RegexHelper` constants + - `DocParser::getEnvironment()` (you should obtain it some other way) + - `AbstractInlineContainer` (use `AbstractInline` instead and make `isContainer()` return `true`) -### Changed - - Bumped spec target version to 0.22 - - Revised AST to use a double-linked list (#169) - - `AbstractBlock` and `AbstractInline` both extend from `Node` - - Sub-classes must implement new `isContainer()` method - - Other major changes to `AbstractBlock`: - - `getParent()` is now `parent()` - - `setParent()` now expects a `Node` instead of an `AbstractBlock` - - `getChildren()` is now `children()` - - `getLastChild()` is now `lastChild()` - - `addChild()` is now `appendChild()` - - `InlineParserContext` is constructed using the container `AbstractBlock` and the document's `RefereceMap` - - The constructor will automatically create the `Cursor` using the container's string contents - - `InlineParserEngine::parse` now requires the `Node` container and the document's `ReferenceMap` instead of a `ContextInterface` and `Cursor` - - Changed `Delimiter` to reference the actual inline `Node` instead of the position - - The `int $pos` protected member and constructor arg is now `Node $node` - - Use `getInlineNode()` and `setInlineNode()` instead of `getPos()` and `setPos()` - - Changed `DocParser::processInlines` to use a `NodeWalker` to iterate through inlines - - Walker passed as second argument instead of `AbstractBlock` - - Uses a `while` loop instead of recursion to traverse the AST - - `Image` and `Link` now only accept a string as their second argument - - Refactored how `CloseBracketParser::parse()` works internally - - `CloseBracketParser::createInline` no longer accepts label inlines - - Disallow list item starting with multiple blank lines (see jgm/CommonMark#332) - - Modified `AbstractBlock::setLastLineBlank()` - - Functionality moved to `AbstractBlock::shouldLastLineBeBlank()` and new `DocParser::setAndPropagateLastLineBlank()` method - - `AbstractBlock::setLastLineBlank()` is now a setter method for `AbstractBlock::$lastLineBlank` - - `AbstractBlock::handleRemainingContents()` is no longer abstract - - A default implementation is provided - - Removed duplicate code from sub-classes which used the default implementation - they'll just use the parent method from now on - -### Fixed - - Fixed logic error in calculation of offset (see jgm/commonmark.js@94053a8) - - Fixed bug where `DocParser` checked the wrong method to determine remainder handling behavior - - Fixed bug where `HorizontalRuleParser` failed to advance the cursor beyond the parsed horizontal rule characters - - Fixed `DocParser` not ignoring the final newline of the input (like the reference parser does) +## [1.0.0-beta1] - 2019-05-26 -### Removed - - Removed `Block\Element\AbstractInlineContainer` - - Extend `AbstractBlock` and implement `InlineContainer` instead - - Use child methods instead of `getInlines` and `setInlines` - - Removed `AbstractBlock::replaceChild()` - - Call `Node::replaceWith()` directly the child node instead - - Removed the `getInlines()` method from `InlineParserContext` - - Add parsed inlines using `$inlineContext->getContainer()->appendChild()` instead of `$inlineContext->getInlines()->add()` - - Removed the `ContextInterface` argument from `AbstractInlineParser::parse()` and `InlineParserEngine::parseCharacter` - - Removed the first `ArrayCollection $inlines` argument from `InlineProcessorInterface::processInlines()` - - Removed `CloseBracketParser::nullify()` - - Removed `pre` from rule 6 of HTML blocks (see jgm/CommonMark#355) - -## [0.10.0] - 2015-07-25 ### Added - - Added parent references to inline elements (#124) - - Added smart punctuation extension (#134) - - Added HTML block types - - Added indentation caching to the cursor - - Added automated code style checks (#133) - - Added support for tag attributes in renderers (#101, #165) - -### Changed - - Bumped spec target version to 0.21 - - Revised HTML block parsing to conform to new spec (jgm/commonmark.js@99bd473) - - Imposed 9-digit limit on ordered list markers, per spec - - Allow non-initial hyphens in html tag names (jgm/CommonMark#239) - - Updated list of block tag names - - Changed tab/indentation handling to meet the new spec behavior - - Modified spec tests to show spaces and tabs in test results - - Replaced `HtmlRendererInterface` with `ElementRendererInterface` (#141) - - Removed the unnecessary `trim()` and string cast from `ListItemRenderer` - -### Fixed - - Fixed link reference definition edge case (#120) - - Allow literal (non-escaping) backslashes in link destinations (#118) - - Allow backslash-escaped backslashes in link labels (#119) - - Allow link labels up to 999 characters (per the spec) - - Properly split on whitespace when determining code block class (jgm/commonmark.js#54) - - Fixed code style issues (#132, #133, #151, #152) - - Fixed wording for invalid inline exception (#136) - -### Removed - - Removed the advance-by-one optimization due to added cursor complexity -## [0.9.0] - 2015-06-18 -### Added - - Added public $data array to block elements (#95) - - Added `isIndented` helper method to `Cursor` - - Added a new `Converter` base class which `CommonMarkConverter` extends from (#105) + - Added proper support for delimiters, including custom delimiters + - `addDelimiterProcessor()` added to `ConfigurableEnvironmentInterface` and `Environment` + - Basic delimiters no longer need custom parsers - they'll be parsed automatically + - Added new methods: + - `AdjacentTextMerger::mergeTextNodesBetweenExclusive()` + - `CommonMarkConveter::getEnvironment()` + - `Configuration::set()` + - Extracted some new interfaces from base classes: + - `DocParserInterface` created from `DocParser` + - `ConfigurationInterface` created from `Configuration` + - `ReferenceInterface` created from `Reference` ### Changed - - Bumped spec target version to 0.20 (#112) - - Renamed ListBlock::$data and ListItem::$data to $listData - - Require link labels to contain non-whitespace (jgm/CommonMark#322) - - Use U+FFFD for entities resolving to 0 (jgm/CommonMark#323) - - Moved `IndentedCodeParser::CODE_INDENT_LEVEL` to `Cursor::INDENT_LEVEL` - - Changed arrays to short syntax (#116) - - Improved efficiency of DelimiterStack iteration (jgm/commonmark.js#43) -### Fixed - - Fixed open block tag followed by newline not being recognized (jgm/CommonMark#324) - - Fixed indented lists sometimes being parsed incorrectly (jgm/commonmark.js#42) - -## [0.8.0] - 2015-04-29 -### Added - - Allow swapping built-in renderers without using their fully qualified names (#84) - - Lots of unit tests (for existing code) - - Ability to include arbitrary functional tests in addition to spec-based tests - -### Changed - - Dropped support for PHP 5.3 (#64 and #76) - - Bumped spec target version to 0.19 - - Made the AbstractInlineContainer be abstract - - Moved environment config. logic into separate class - -### Fixed - - Fixed underscore emphasis to conform to spec changes (jgm/CommonMark#317) - -### Removed - - Removed PHP 5.3 workaround (see commit 5747822) - - Removed unused AbstractWebResource::setUrl() method - - Removed unnecessary check for hrule when parsing lists (#85) - -## [0.7.2] - 2015-03-08 -### Changed - - Bumped spec target version to 0.18 - -### Fixed - - Fixed broken parsing of emphasized text ending with a '0' character (#81) - -## [0.7.1] - 2015-03-01 -### Added - - All references can now be obtained from the `ReferenceMap` via `listReferences()` (#73) - - Test against PHP 7.0 (nightly) but allow failures - -### Changed - - ListData::$start now defaults to null instead of 0 (#74) - - Replace references to HtmlRenderer with new HtmlRendererInterface - -### Fixed - - Fixed 0-based ordered lists starting at 1 instead of 0 (#74) - - Fixed errors parsing multi-byte characters (#78 and #79) - -## [0.7.0] - 2015-02-16 -### Added - - More unit tests to increase code coverage - -### Changed - - Enabled the InlineParserEngine to parse several non-special characters at once (performance boost) - - NewlineParser no longer attempts to parse spaces; look-behind is used instead (major performance boost) - - Moved closeUnmatchedBlocks into its own class - - Image and link elements now extend AbstractInlineContainer; label data is stored via $inlineContents instead - - Renamed AbstractInlineContainer::$inlineContents and its getter/setter - -### Removed - - Removed the InlineCollection class - - Removed the unused ArrayCollection::splice() method - - Removed impossible-to-reach code in Cursor::advanceToFirstNonSpace - - Removed unnecessary test from the InlineParserEngine - - Removed unnecessary/unused RegexHelper::getMainRegex() method - -## [0.6.1] - 2015-01-25 -### Changed - - Bumped spec target version to 0.17 - - Updated emphasis parsing for underscores to prevent intra-word emphasis - - Deferred closing of fenced code blocks - -## [0.6.0] - 2015-01-09 -### Added - - Bulk registration of parsers/renderers via extensions (#45) - - Proper UTF-8 support, especially in the Cursor; mbstring extension is now required (#49) - - Environment is now configurable; options can be accessed in its parsers/renderers (#56) - - Added some unit tests - -### Changed - - Bumped spec target version to 0.15 (#50) - - Parsers/renderers are now lazy-initialized (#52) - - Some private elements are now protected for easier extending, especially on Element classes (#53) - - Renderer option keys changed from camelCase to underscore_case (#56) - - Moved CommonMark parser/render definitions into CommonMarkCoreExtension - -### Fixed - - Improved parsing of emphasis around punctuation - - Improved regexes for CDATA and HTML comments - - Fixed issue with HTML content that is considered false in loose comparisons, like `'0'` (#55) - - Fixed DocParser trying to add empty strings to closed containers (#58) - - Fixed incorrect use of a null parameter value in the HtmlElementTest - -### Removed - - Removed unused ReferenceDefinition* classes (#51) - - Removed UnicodeCaseFolder in favor of mb_strtoupper + - Renamed several methods of the `Configuration` class: + - `getConfig()` renamed to `get()` + - `mergeConfig()` renamed to `merge()` + - `setConfig()` renamed to `replace()` + - Changed `ConfigurationAwareInterface::setConfiguration()` to accept the new `ConfigurationInterface` instead of the concrete class + - Renamed the `AdjoiningTextCollapser` class to `AdjacentTextMerger` + - Replaced its `collapseTextNodes()` method with the new `mergeChildNodes()` method + - Made several classes `final`: + - `Configuration` + - `DocParser` + - `HtmlRenderer` + - `InlineParserEngine` + - `NodeWalker` + - `Reference` + - All of the block/inline parsers and renderers + - Reduced visibility of several internal methods to `private`: + - `DelimiterStack::findEarliest()` + - All `protected` methods in `InlineParserEngine` + - Marked some classes and methods as `@internal` + - `ElementRendererInterface` now requires a public `renderInline()` method; added this to `HtmlRenderer` + - Changed `InlineParserEngine::parse()` to require an `AbstractStringContainerBlock` instead of the generic `Node` class + - Un-deprecated the `CommonmarkConverter::VERSION` constant + - The `Converter` constructor now requires an instance of `DocParserInterface` instead of the concrete `DocParser` + - Changed `Emphasis`, `Strong`, and `AbstractWebResource` to directly extend `AbstractInline` instead of the (now-deprecated) intermediary `AbstractInlineContainer` class -## [0.5.1] - 2014-12-27 ### Fixed - - Fixed infinite loop and link-in-link-in-image parsing (#37) -### Removed - - Removed hard dependency on mbstring extension; workaround used if not installed (#38) - -## [0.5.0] - 2014-12-24 -### Added - - Support for custom directives, parsers, and renderers - -### Changed - - Major refactoring to de-couple directives from the parser, support custom directive functionality, and reduce complexity - - Updated references to stmd.js in README and docblocks - - Modified CHANGELOG formatting - - Improved travis configuration - - Put tests in autoload-dev - -### Fixed - - Fixed CommonMarkConverter re-creating object each time new text is converted (#26) - -### Removed - - Removed HtmlRenderer::render() (use the renderBlock method instead) - - Removed dependency on symfony/options-resolver (fixes #20) + - Fixed null errors when inserting sibling `Node`s without parents + - Fixed `NodeWalkerEvent` not requiring a `Node` via its constructor + - Fixed `Reference::normalizeReference()` improperly converting to uppercase instead of performing proper Unicode case-folding + - Fixed strong emphasis delimiters not being preserved when `enable_strong` is set to `false` (it now works identically to `enable_em`) -## [0.4.0] - 2014-12-15 -### Added - - Added some missing copyright info - -### Changed - - Changed namespace to League\CommonMark - - Made compatible with spec version 0.13 - - Moved delimiter stack functionality into separate class - -### Fixed - - Fixed regex which caused HHVM tests to fail - -## [0.3.0] - 2014-11-28 -### Added - - Made renderer options configurable (issue #7) - -### Changed - - Made compatible with spec version 0.12 - - Stack-based parsing now used for emphasis, links and images - - Protected some of the internal renderer methods which shouldn't have been `public` - - Minor code clean-up (including PSR-2 compliance) - -### Removed - - Removed unnecessary distinction between ATX and Setext headers - -## [0.2.1] - 2014-11-09 -### Added - - Added simpler string replacement to a method - -### Changed - - Removed "is" prefix from boolean methods - * Updated to latest version of PHPUnit - * Target specific spec version +### Deprecated -## [0.2.0] - 2014-11-09 -### Changed - - Mirrored significant changes and improvements from stmd.js - - Made compatible with spec version 0.10 - - Updated location of JGM's repository - - Allowed HHVM tests to fail without affecting overall build success + - Deprecated `DocParser::getEnvironment()` (you should obtain it some other way) + - Deprecated `AbstractInlineContainer` (use `AbstractInline` instead and make `isContainer()` return `true`) ### Removed - - Removed composer.lock - - Removed fixed reference to jgm/stmd@0275f34 -## [0.1.2] - 2014-09-28 -### Added - - Added performance benchmarking tool (issue #2) - - Added more badges to the README - -### Changed - - Fix JS -> PHP null judgement (issue #4) - - Updated phpunit dependency - -## [0.1.1] - 2014-09-08 -### Added - - Add anchors to regexes - -### Changed - - Updated target spec (now compatible with jgm/stmd:spec.txt @ 2cf0750) - - Adjust HTML output for fenced code - - Adjust block-level tag regex (remove "br", add "iframe") - - Fix incorrect handling of nested emphasis - -## 0.1.0 -### Added - - Initial commit (compatible with jgm/stmd:spec.txt @ 0275f34) + - Removed inline processor functionality now that we have proper delimiter support: + - Removed `addInlineProcessor()` from `ConfigurableEnvironmentInterface` and `Environment` + - Removed `getInlineProcessors()` from `EnvironmentInterface` and `Environment` + - Removed `EmphasisProcessor` + - Removed `InlineProcessorInterface` + - Removed `EmphasisParser` now that we have proper delimiter support + - Removed support for non-UTF-8-compatible encodings + - Removed `getEncoding()` from `ContextInterface` + - Removed `getEncoding()`, `setEncoding()`, and `$encoding` from `Context` + - Removed `getEncoding()` and the second `$encoding` constructor param from `Cursor` + - Removed now-unused methods + - Removed `DelimiterStack::getTop()` (no replacement) + - Removed `DelimiterStack::iterateByCharacters()` (use the new `processDelimiters()` method instead) + - Removed the protected `DelimiterStack::findMatchingOpener()` method -[unreleased]: https://github.com/thephpleague/commonmark/compare/0.19.3...HEAD -[0.19.3]: https://github.com/thephpleague/commonmark/compare/0.19.2...0.19.3 -[0.19.2]: https://github.com/thephpleague/commonmark/compare/0.19.1...0.19.2 -[0.19.1]: https://github.com/thephpleague/commonmark/compare/0.19.0...0.19.1 -[0.19.0]: https://github.com/thephpleague/commonmark/compare/0.18.5...0.19.0 -[0.18.5]: https://github.com/thephpleague/commonmark/compare/0.18.4...0.18.5 -[0.18.4]: https://github.com/thephpleague/commonmark/compare/0.18.3...0.18.4 -[0.18.3]: https://github.com/thephpleague/commonmark/compare/0.18.2...0.18.3 -[0.18.2]: https://github.com/thephpleague/commonmark/compare/0.18.1...0.18.2 -[0.18.1]: https://github.com/thephpleague/commonmark/compare/0.18.0...0.18.1 -[0.18.0]: https://github.com/thephpleague/commonmark/compare/0.17.5...0.18.0 -[0.17.5]: https://github.com/thephpleague/commonmark/compare/0.17.4...0.17.5 -[0.17.4]: https://github.com/thephpleague/commonmark/compare/0.17.3...0.17.4 -[0.17.3]: https://github.com/thephpleague/commonmark/compare/0.17.2...0.17.3 -[0.17.2]: https://github.com/thephpleague/commonmark/compare/0.17.1...0.17.2 -[0.17.1]: https://github.com/thephpleague/commonmark/compare/0.17.0...0.17.1 -[0.17.0]: https://github.com/thephpleague/commonmark/compare/0.16.0...0.17.0 -[0.16.0]: https://github.com/thephpleague/commonmark/compare/0.15.7...0.16.0 -[0.15.7]: https://github.com/thephpleague/commonmark/compare/0.15.6...0.15.7 -[0.15.6]: https://github.com/thephpleague/commonmark/compare/0.15.5...0.15.6 -[0.15.5]: https://github.com/thephpleague/commonmark/compare/0.15.4...0.15.5 -[0.15.4]: https://github.com/thephpleague/commonmark/compare/0.15.3...0.15.4 -[0.15.3]: https://github.com/thephpleague/commonmark/compare/0.15.2...0.15.3 -[0.15.2]: https://github.com/thephpleague/commonmark/compare/0.15.1...0.15.2 -[0.15.1]: https://github.com/thephpleague/commonmark/compare/0.15.0...0.15.1 -[0.15.0]: https://github.com/thephpleague/commonmark/compare/0.14.0...0.15.0 -[0.14.0]: https://github.com/thephpleague/commonmark/compare/0.13.4...0.14.0 -[0.13.4]: https://github.com/thephpleague/commonmark/compare/0.13.3...0.13.4 -[0.13.3]: https://github.com/thephpleague/commonmark/compare/0.13.2...0.13.3 -[0.13.2]: https://github.com/thephpleague/commonmark/compare/0.13.1...0.13.2 -[0.13.1]: https://github.com/thephpleague/commonmark/compare/0.13.0...0.13.1 -[0.13.0]: https://github.com/thephpleague/commonmark/compare/0.12.0...0.13.0 -[0.12.0]: https://github.com/thephpleague/commonmark/compare/0.11.3...0.12.0 -[0.11.3]: https://github.com/thephpleague/commonmark/compare/0.11.2...0.11.3 -[0.11.2]: https://github.com/thephpleague/commonmark/compare/0.11.1...0.11.2 -[0.11.1]: https://github.com/thephpleague/commonmark/compare/0.11.0...0.11.1 -[0.11.0]: https://github.com/thephpleague/commonmark/compare/0.10.0...0.11.0 -[0.10.0]: https://github.com/thephpleague/commonmark/compare/0.9.0...0.10.0 -[0.9.0]: https://github.com/thephpleague/commonmark/compare/0.8.0...0.9.0 -[0.8.0]: https://github.com/thephpleague/commonmark/compare/0.7.2...0.8.0 -[0.7.2]: https://github.com/thephpleague/commonmark/compare/0.7.1...0.7.2 -[0.7.1]: https://github.com/thephpleague/commonmark/compare/0.7.0...0.7.1 -[0.7.0]: https://github.com/thephpleague/commonmark/compare/0.6.1...0.7.0 -[0.6.1]: https://github.com/thephpleague/commonmark/compare/0.6.0...0.6.1 -[0.6.0]: https://github.com/thephpleague/commonmark/compare/0.5.1...0.6.0 -[0.5.1]: https://github.com/thephpleague/commonmark/compare/0.5.0...0.5.1 -[0.5.0]: https://github.com/thephpleague/commonmark/compare/0.4.0...0.5.0 -[0.4.0]: https://github.com/thephpleague/commonmark/compare/0.3.0...0.4.0 -[0.3.0]: https://github.com/thephpleague/commonmark/compare/0.2.1...0.3.0 -[0.2.1]: https://github.com/thephpleague/commonmark/compare/0.2.0...0.2.1 -[0.2.0]: https://github.com/thephpleague/commonmark/compare/0.1.2...0.2.0 -[0.1.2]: https://github.com/thephpleague/commonmark/compare/0.1.1...0.1.2 -[0.1.1]: https://github.com/thephpleague/commonmark/compare/0.1.0...0.1.1 +[unreleased]: https://github.com/thephpleague/commonmark/compare/1.0.0...HEAD +[1.0.0]: https://github.com/thephpleague/commonmark/compare/1.0.0-rc1...1.0.0 +[1.0.0-rc1]: https://github.com/thephpleague/commonmark/compare/1.0.0-beta4...1.0.0-rc1 +[1.0.0-beta4]: https://github.com/thephpleague/commonmark/compare/1.0.0-beta3...1.0.0-beta4 +[1.0.0-beta3]: https://github.com/thephpleague/commonmark/compare/1.0.0-beta2...1.0.0-beta3 +[1.0.0-beta2]: https://github.com/thephpleague/commonmark/compare/1.0.0-beta1...1.0.0-beta2 +[1.0.0-beta1]: https://github.com/thephpleague/commonmark/compare/0.19.2...1.0.0-beta1 diff --git a/vendor/league/commonmark/LICENSE b/vendor/league/commonmark/LICENSE index 063172aff8..7441468b8b 100644 --- a/vendor/league/commonmark/LICENSE +++ b/vendor/league/commonmark/LICENSE @@ -1,9 +1,6 @@ BSD 3-Clause License -Copyright (c) 2014-2019, Colin O'Dell -All rights reserved. - -Based on commonmark.js: Copyright (c) 2014-2018, John MacFarlane +Copyright (c) 2014-2019, Colin O'Dell. All rights reserved. Based on commonmark.js,copyright (c) 2014-2018, John MacFarlane Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/vendor/league/commonmark/README.md b/vendor/league/commonmark/README.md index 06b238ea57..301b0103d1 100644 --- a/vendor/league/commonmark/README.md +++ b/vendor/league/commonmark/README.md @@ -6,19 +6,15 @@ [](https://travis-ci.org/thephpleague/commonmark) [](https://scrutinizer-ci.com/g/thephpleague/commonmark/code-structure) [](https://scrutinizer-ci.com/g/thephpleague/commonmark) -[](https://insight.sensiolabs.com/projects/9bf971c0-458f-4a19-9898-127728dbd65d) [](https://bestpractices.coreinfrastructure.org/projects/126) -**league/commonmark** is a PHP-based Markdown parser created by [Colin O'Dell][@colinodell] which supports the full [CommonMark] spec. It is based on the [CommonMark JS reference implementation][commonmark.js] by [John MacFarlane] \([@jgm]\). +[](https://www.patreon.com/colinodell) -## Goals + -* Fully support the CommonMark spec (100% compliance) -* Match the C and JavaScript implementations of CommonMark to make a logical and similar API -* Continuously improve performance without sacrificing quality or compliance -* Provide an extensible parser/renderer which users may customize as needed +**league/commonmark** is a highly-extensible PHP Markdown parser created by [Colin O'Dell][@colinodell] which supports the full [CommonMark] spec. It is based on the [CommonMark JS reference implementation][commonmark.js] by [John MacFarlane] \([@jgm]\). -## Installation +## 📦 Installation & Basic Usage This project can be installed via [Composer]: @@ -26,34 +22,34 @@ This project can be installed via [Composer]: $ composer require league/commonmark ``` -**Note:** See [Versioning](#versioning) for important information on which version constraints you should use. - -## Basic Usage - The `CommonMarkConverter` class provides a simple wrapper for converting CommonMark to HTML: ```php use League\CommonMark\CommonMarkConverter; -$converter = new CommonMarkConverter(); +$converter = new CommonMarkConverter([ + 'html_input' => 'strip', + 'allow_unsafe_links' => false, +]); + echo $converter->convertToHtml('# Hello World!'); // <h1>Hello World!</h1> ``` -:warning: **Security warning:** If you will be parsing untrusted input from users, please consider setting the `html_input` and `allow_unsafe_links` options. See <https://commonmark.thephpleague.com/security/> for more details. +Please note that only UTF-8 and ASCII encodings are supported. If your Markdown uses a different encoding please convert it to UTF-8 before running it through this library. -If you also do choose to allow raw HTML input from untrusted users, considering using a library (like [HTML Purifier](https://github.com/ezyang/htmlpurifier)) to provide additional HTML filtering. +🔒 If you will be parsing untrusted input from users, please consider setting the `html_input` and `allow_unsafe_links` options per the example above. See <https://commonmark.thephpleague.com/security/> for more details. If you also do choose to allow raw HTML input from untrusted users, considering using a library (like [HTML Purifier](https://github.com/ezyang/htmlpurifier)) to provide additional HTML filtering. -## Documentation +## 📓 Documentation Full documentation on advanced usage, configuration, and customization can be found at [commonmark.thephpleague.com][docs]. -## Upgrading +## ⏫ Upgrading Information on how to upgrade to newer versions of this library can be found at <https://commonmark.thephpleague.com/releases>. -## Related Packages +## 🗃️ Related Packages ### Integrations @@ -64,7 +60,6 @@ Information on how to upgrade to newer versions of this library can be found at - [Symfony 2 & 3](https://github.com/webuni/commonmark-bundle) - [Symfony 4](https://github.com/avensome/commonmark-bundle) - [Twig Markdown extension](https://github.com/twigphp/markdown-extension) -- [Twig-based renderer](https://github.com/webuni/commonmark-twig-renderer) - [Twig filter and tag](https://github.com/aptoma/twig-markdown) ### League Extensions @@ -74,7 +69,10 @@ The PHP League offers useful extensions that add extra syntax and features: - [`league/commonmark-extras`](https://github.com/thephpleague/commonmark-extras) - Bundles the extensions below into a single dependency for convenience - [`league/commonmark-ext-autolink`](https://github.com/thephpleague/commonmark-ext-autolink) - Extension for league/commonmark which autolinks URLs, emails, and (optionally) @-mentions - [`league/commonmark-ext-smartpunct`](https://github.com/thephpleague/commonmark-ext-smartpunct) - Intelligently converts ASCII quotes, dashes, and ellipses to their Unicode equivalents + - [`league/commonmark-ext-strikethrough`](https://github.com/thephpleague/commonmark-ext-strikethrough) - Adds support for `~~strikethrough~~` syntax + - [`league/commonmark-ext-task-list`](https://github.com/thephpleague/commonmark-ext-task-list) - Support for Github-style task lists - [`league/commonmark-ext-inlines-only`](https://github.com/thephpleague/commonmark-ext-inlines-only) - Renders inline text without paragraph tags or other block-level elements + - [`league/commonmark-ext-external-link`](https://github.com/thephpleague/commonmark-ext-external-link) - Mark external links, make them open in new windows, etc. You can add them to your project or use them as examples to [develop your own custom features](https://commonmark.thephpleague.com/customization/overview/). @@ -85,86 +83,85 @@ Custom parsers/renderers can be bundled into extensions which extend CommonMark. - [CommonMark Table Extension](https://github.com/webuni/commonmark-table-extension) - Adds the ability to create tables in CommonMark documents. - [CommonMark Attributes Extension](https://github.com/webuni/commonmark-attributes-extension) - Adds a syntax to define attributes on the various HTML elements. - [Alt Three Emoji](https://github.com/AltThree/Emoji) An emoji parser for CommonMark. - - [uafrica/commonmark-ext](https://github.com/uafrica/commonmark-ext) - Adds strikethrough support. - [Sup Sub extensions](https://github.com/OWS/commonmark-sup-sub-extensions) - Adds support of superscript and subscript (`<sup>` and `<sub>` HTML tags) +Others can be found on [Packagist under the `commonmark-extension` package type](https://packagist.org/packages/league/commonmark?type=commonmark-extension). + If you build your own, feel free to submit a PR to add it to this list! ### Others Check out the other cool things people are doing with `league/commonmark`: <https://packagist.org/packages/league/commonmark/dependents> -## Compatibility with CommonMark ## - -This project aims to fully support the entire [CommonMark spec]. Other flavors of Markdown may work but are not supported. Any/all changes made to the [spec][CommonMark spec] or [JS reference implementation][commonmark.js] should eventually find their way back into this codebase. - -league/commonmark 0.19.0 and higher supports version 0.29 of the [CommonMark spec]. - -(This package is **not** part of CommonMark, but rather a compatible derivative.) - -## Testing +## 🏷️ Versioning -``` bash -$ composer test -``` - -This will also test league/commonmark against the latest supported spec. +[SemVer](http://semver.org/) is followed closely. Minor and patch releases should not introduce breaking changes to the codebase; however, they might change the resulting AST or HTML output of parsed Markdown (due to bug fixes, spec changes, etc.) As a result, you might get slightly different HTML, but any custom code built onto this library should still function correctly. -## Performance Benchmarks +Any classes or methods marked `@internal` are not intended for use outside of this library and are subject to breaking changes at any time, so please avoid using them. -You can compare the performance of **league/commonmark** to other popular parsers by running the included benchmark tool: +## 🛠️ Maintenance & Support -``` bash -$ ./tests/benchmark/benchmark.php -``` +When a new **minor** version (`1.x`) is released, the previous one will continue to receive security and bug fixes for *at least* 3 months. -## Versioning +When a new **major** version is released (`1.0`, `2.0`, etc), the previous one (`0.19.x`) will receive bug fixes for *at least* 3 months and security updates for 6 months after that new release comes out. -[SemVer](http://semver.org/) will be followed closely. 0.x.0 versions will introduce breaking changes to the codebase, so be careful which version constraints you use. **It's highly recommended that you use [Composer's caret operator](https://getcomposer.org/doc/articles/versions.md#caret) to ensure compatibility**; for example: `^0.18`. This is equivalent to `>=0.18.0 <0.19.0`. +(This policy may change in the future and exceptions may be made on a case-by-case basis.) -0.x.y releases should not introduce breaking changes to the codebase; however, they might change the resulting AST or HTML output of parsed Markdown (due to bug fixes, minor spec changes, etc.) As a result, you might get slightly different HTML, but any custom code built onto this library will still function correctly. +## 👷♀️ Contributing -If you're only using the `CommonMarkConverter` class or `ConverterInterface` to convert Markdown (no other class references, custom parsers, etc.), then it should be safe to use a broader constraint like `~0.18`, `>0.18`, etc. I personally promise to never break this specific class in any future 0.x release. +To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure with us. -## Stability +If you encounter a bug in the spec, please report it to the [CommonMark] project. Any resulting fix will eventually be implemented in this project as well. -While this package does work well, the underlying code should not be considered "stable" yet. The original spec and JS parser may undergo changes in the near future which will result in corresponding changes to this code. Any methods tagged with `@api` are not expected to change, but other methods/classes might. +Contributions to this library are **welcome**, especially ones that: -Major release 1.0.0 will be reserved for when either the CommonMark spec or this project are considered stable (see [outstanding CommonMark spec issues](http://talk.commonmark.org/t/issues-to-resolve-before-1-0-release/1287)). 0.x.y will be used until that happens. + * Improve usability or flexibility without compromising our ability to adhere to the [CommonMark spec] + * Mirror fixes made to the [reference implementation][commonmark.js] + * Optimize performance + * Fix issues with adhering to the [CommonMark spec] -## Contributing +Major refactoring to core parsing logic should be avoided if possible so that we can easily follow updates made to [the reference implementation][commonmark.js]. That being said, we will absolutely consider changes which don't deviate too far from the reference spec or which are favored by other popular CommonMark implementations. -If you encounter a bug in the spec, please report it to the [CommonMark] project. Any resulting fix will eventually be implemented in this project as well. +Please see [CONTRIBUTING](https://github.com/thephpleague/commonmark/blob/master/.github/CONTRIBUTING.md) for additional details. -For now, I'd like to maintain similar logic as the [JS reference implementation][commonmark.js] until everything is stable. I'll gladly accept any contributions which: +## 🧪 Testing - * Mirror fixes made to the [reference implementation][commonmark.js] - * Optimize existing methods or regular expressions - * Fix issues with adhering to the spec examples +``` bash +$ composer test +``` -Major refactoring should be avoided for now so that we can easily follow updates made to [the reference implementation][commonmark.js]. This restriction will likely be lifted once the CommonMark specs and implementations are considered stable. +This will also test league/commonmark against the latest supported spec. -Please see [CONTRIBUTING](https://github.com/thephpleague/commonmark/blob/master/CONTRIBUTING.md) for additional details. +## 🚀 Performance Benchmarks -## Security +You can compare the performance of **league/commonmark** to other popular parsers by running the included benchmark tool: -If you discover any security related issues, please email your report privately to colinodell@gmail.com instead of using the issue tracker. +``` bash +$ ./tests/benchmark/benchmark.php +``` -## Credits & Acknowledgements +## 👥 Credits & Acknowledgements - [Colin O'Dell][@colinodell] - [John MacFarlane][@jgm] - [All Contributors] -This code is a port of the [CommonMark JS reference implementation][commonmark.js] which is written, maintained and copyrighted by [John MacFarlane]. This project simply wouldn't exist without his work. +This code is partially based on the [CommonMark JS reference implementation][commonmark.js] which is written, maintained and copyrighted by [John MacFarlane]. This project simply wouldn't exist without his work. + +### Sponsors + +We'd also like to extend our sincere thanks the following sponsors who support ongoing development of this project: + + - [RIPS Technologies](https://www.ripstech.com/) for supporting this project with a complimentary [RIPS SaaS](https://www.ripstech.com/product/) license + - [JetBrains](https://www.jetbrains.com/) for supporting this project with complimentary [PhpStorm](https://www.jetbrains.com/phpstorm/) licenses -Also a huge thank you to [JetBrains](https://www.jetbrains.com/) for supporting the development of this project with complimentary [PhpStorm](https://www.jetbrains.com/phpstorm/) licenses. +Are you interested in sponsoring development of this project? [Make a pledge](https://www.patreon.com/join/colinodell) of $10 or more and we'll include your name [on our website](https://commonmark.thephpleague.com/#sponsors)! -## License ## +## 📄 License **league/commonmark** is licensed under the BSD-3 license. See the [`LICENSE`](LICENSE) file for more details. -## Governance +## 🏛️ Governance This project is primarily maintained by [Colin O'Dell][@colinodell]. Members of the [PHP League] Leadership Team may occasionally assist with some of these duties. diff --git a/vendor/league/commonmark/UPGRADE.md b/vendor/league/commonmark/UPGRADE.md deleted file mode 100644 index d33e139bdd..0000000000 --- a/vendor/league/commonmark/UPGRADE.md +++ /dev/null @@ -1,244 +0,0 @@ -# Upgrade Instructions - -**Note:** This file has been deprecated. Future upgrade instructions can be found on our website: <https://commonmark.thephpleague.com/releases> - -## UNRELEASED - -## 0.19 - -The `Environment` and extension framework underwent some major changes in this release. - -### PHP support - -This library no longer supports PHP 5.6 or 7.0. Feel free to remove support for those from your extensions as well. - -### HTML attribute escaping - -Previously, any attributes passed into an `HtmlElement` would need to be pre-escaped. This is now done for you so be sure to remove any references to `Xml::escape()` when applied to attributes. - -This does not affect inner contents which may still need pre-escaping of untrusted user input. - -### Removed classes and interface methods - -The `getName()` method has been removed from several classes: - - - `BlockParserInterface` and `AbstractBlockParser` - - `InlineParserInterface` and `AbstractInlineParser` - -This method was originally intended for supporting XML rendering, which was never implemented, and will likely define names a bit differently if/when we do add support. - -After doing this, the two abstract classes mentioned above had notthing left in them, so those were removed. Any parsers previously extending them should directly implement the corresponding interface instead. - -`InlineContainer` was also removed. - -`Xml::escape()` no longer accepts the deprecated `$preserveEntities` parameter. - -### Removed deprecated `RegexHelper` methods - -Several previously-deprecated methods inside of `RegexHelper` were finally removed. That functionality was made available with static methods and constants, so use those instead. - -### Parameter and return types - -Pretty much every method now uses parameter and return types, including several interfaces. Update your implementations accordingly. - -### Environment interfaces - -We have extracted two interfaces from the `Environment` class: - - - `EnvironmentInterface` - contains all the getters; use this in your parsers, renderers, etc. - - `ConfigurableEnvironmentInterface` - contains all the `add` methods, as well as `setConfig()` and `mergeConfig` - -As a result, `EnvironmentAwareInterface` now requires an `EnvironmentInterface` instead of an `Environment`, so update your parsers/processors/renderers accordingly. - -### Block Elements - -A few methods from `AbstractBlock` have been extracted into a new `AbstractStringContainerBlock` class and corresponding `StringContainerInterface` interface: - - - `addLine(string $line)` - - `getStringContent()` - - `handleRemainingContents(ContextInterface $context, Cursor $cursor)` - -These are used to represent a block which can contain strings of text inside (even if those strings do not contain "inline" elements but just plain text). - -To determine how to best upgrade your existing block element classes, look at the value returned by the `acceptsLines()` method: - - - If `acceptsLines()` returns `false`, simply remove the three methods from the bulleted list above, along with `acceptsLines()` and any calls to `parent::__construct()`. - - If `acceptsLines()` returns `true`, change your base class from `AbstractBlock` to `AbstractStringContainerBlock` and remove `acceptsLines()`. - -Additionally, `StringContainerInterface` now extends this new `StringContainerInterface` interface. Just make sure you've implemented the change mentioned above and you should be fine. - -### Extensions - -Extensions work much differently now. In the past, you'd have functions returning an array of things that the `Environment` would register for you. - -The `ExtensionInterface` was changed to have a single `register(ConfigurableEnvironmentInterface $environment)` method. You must now manually `add()` all your parsers, processors, and renderers yourself directly within the environment you are provided. See the changes made to `CommonMarkCoreExtension` for a good example. - -The `Environment` will still automatically inject the `Environment` or `Configuration` for any parsers, processors, and renderers implementing the `EnvironmentAwareInterface` or `ConfigurationAwareInterface` - that behavior hasn't changed. - -### Adding renderers with short names - -`Environment::add___Renderer()` now requires the fully-qualified class name with namespace as its first argument. Providing just the class name without the namespace will no longer work. - -### Prioritization of parsers, processors, and renderers - -The execution order of these things no longer depends on the order you add them - you can now specific custom priorities when `add()`ing them to the `Environment`! The priority can be any integer you want. The default value is `0`. All CommonMark Core things will have a priority between -255 and 255. The higher the number, the earlier it will be executed. - -### Multiple block/inline renderers per class - -Thanks to the new prioritization system, we now support multiple renderers for the same block/inline class! The first renderer to return a non-null result will be considered the "winner" and no subsequent renderers will execute for that block/inline. No change should be required for most extensions unless you were using some weird workaround to support multiple renderers yourself. - -### `RegexHelper::isEscapable()` no longer accepts `null` values - -In cases where you may have previously passed a `null` value in, skip the call to this method. The previous behavior was to return `false` for `null` values, but `null` is never escapable so it's silly to make this call when we know what the result will be. - -## 0.18.3 - -### Deprecated `Xml::escape()` argument - -Starting in `0.19.0`, the `Xml::escape()` function will no longer accept the second `$preserveEntities` argument as this can lead to XSS issues. Remove this argument if your code uses it. See https://github.com/thephpleague/commonmark/issues/353 for further details. - -## 0.18.0 - -No breaking changes were introduced, but we did add a new interface: `ConverterInface`. Consider depending on this interface in your code instead of the concrete implementation. (See #330) - -## 0.17.0 - -## Minimum PHP version - -The minimum PHP version has been increased to 5.6.5. Users on PHP 5.4 and 5.5 can still use previous versions of this library but will not receive future improvements or bug fixes. - -## Removal of deprecated features - -Pretty much everything marked as `@deprecated` in 0.16.0 has been removed. - -## `RegexHelper` - -We're now taking advantage of PHP 5.6's constant expression feature. This removes the need for `RegexHelper` to be a singleton where complex regular expressions are built and referenced using instance methods. **All regexes are now available as class constants.** - -For example, instead of doing this: - -```php -preg_match('/' . RegexHelper::getInstance()->getPartialRegex(RegexHelper::OPENTAG) . '/', $html); -``` - -You can now do this: - -```php -preg_match('/' . RegexHelper::PARTIAL_OPENTAG . '/', $html); -``` - -(Basically, remove that function call and prefix the constant name with `PARTIAL_`). - -Other instance functions like `getLinkTitleRegex()` which returned a regular expression have also been deprecated in favor of pre-defined constants like `PARTIAL_LINK_TITLE`. - -The now-deprecated functionality still exists in 0.17.0 **but will be removed in the next major release.** - -To summarize: - - - All `REGEX_` constants are fully-formed regexes. Most are unchanged. - - All `PARTIAL_` constants need to be wrapped with a `/` on each side before use. - - All instance methods are deprecated - use a constant instead. - -`RegexHelper` is also `final` now - it only contains constants and static methods and was never intended to be extended. - -## Cursor state - -`Cursor::saveState()` and `Cursor::restoreState()` provide the ability to rollback the state of a `Cursor`. For example: - -```php -$oldState = $cursor->saveState(); - -// Made-up example of trying to parse something using calls -$cursor->advanceToNextNonSpaceOrTab(); -$cursor->match('/foo(bar)?/'); -$cursor->advanceToNextNonSpaceOrTab(); - -if ($someConditionThatWeDidntExpect) { - // Roll back and abort - $cursor->restoreState($oldState); - return; -} -``` - -This useful feature encapsulated the internal, `private` state of the `Cursor` inside of a `CursorState` object with public methods. **This was a design mistake** as it meant that any changes to the interal structure of a `Cursor` meant causing BC-breaks on the `CursorState`. - -`CursorState` was also never intended for any other usage besides saving/restoring. - -For those reasons, we've removed the `CursorState` class entirely and now store the state using an array. **Do not depend on the contents or structure of the array for any reason as it may change in any release without warning!** If you really need to reference information about the prior state of the cursor, either `clone` it or grab the info you need before manipulating it. - -## `InlineContainer` interface - -The `InlineContainer` interface was renamed to `InlineContainerInterface`. The old one still exists as a deprecated interface and will be removed in the next major release. - -## 0.16.0 - -You may continue using the deprecated items listed below in version 0.16.x. **However, these deprecations will be removed in a future major release** (0.17.0+ or 1.0.0, whichever comes first) so consider updating your code now to prepare for that release. - -## `Cursor` and `CursorState` methods - -Basically, all methods in these two classes which contain `First` in their name have been deprecated. The original names were misleading as they always operated on the "first" non-space **after the current position**, which is not always the **first occurrence in the string**. You should instead use the `Next` versions instead: - - - Deprecated `Cursor::advanceWhileMatches()` - - Use `Cursor::match()` instead. - - Deprecated `CursorState::getFirstNonSpaceCache()` - - Use `CursorState::getNextNonSpaceCache()` instead (identical behavior) - - Deprecated `Cursor::getFirstNonSpaceCharacter()` - - Use `Cursor::getNextNonSpaceCharacter()` instead (identical behavior) - - Deprecated `Cursor::getFirstNonSpacePosition()` - - Use `Cursor::getNextNonSpacePosition()` instead (identical behavior) - - Deprecated `Cursor::advanceToFirstNonSpace()` - - You'll probably want to use `advanceToNextNonSpaceOrTab()` if you're using this to parse blocks, but beware that it does not behave identically to the original method. - - If you need the exact functionality as the original, use `advanceToNextNonSpaceOrNewline()` instead. We're currently using this internally for parsing links and references. - -The reason we now have two alternatives to the `advancedToFirstNonSpace()` function is because we accidentally assumed that a single approach would work in two different use cases. As you can see in [issue #279](https://github.com/thephpleague/commonmark/issues/279), this assumption was false. We have therefore split the two different parsing strategies into two different methods. Both will behave similarly for strings that only contain spaces, but they differ when newlines or tabs are involved. - -More details about this change can be found here: https://github.com/thephpleague/commonmark/issues/280 - -### `RegexHelper` - -`RegexHelper::REGEX_UNICODE_WHITESPACE` and `RegexHelper::getLinkDestinationRegex()` were no longer needed as of the 0.15.5 release and have therefore been deprecated and marked for removal. - -### `HtmlRenderer::escape()` - -`HtmlRenderer::escape()` was an instance method making it unusable as a general utility method. Its logic has been moved into a new static Xml::escape() method so use that instead - it takes the same exact methods and implements the same behavior. - -### Final Utility Classes - -The following utility classes were never meant to be extended and have therefore been marked `final`: - - - `Html5Entities` - - `LinkParserHelper` - - `UrlEncoder` - -## 0.15.0 - -### `CursorState` constructor - -The `CursorState` constructor now requires an additional boolean parameter `$partiallyConsumedTab`. -No change should be needed in your application unless you are directly instantiating this object (unlikely). - -### `DelimiterStack::findFirstMatchingOpener()` deprecated - -You should use `DelimiterStack::findMatchingOpener()` instead. - -The method signature is almost identical, except for the inclusion of a by-reference boolean `$oddMatch`. - -The deprecated `findFirstMatchingOpener()` method was removed in the 0.16.0 release. - -## 0.14.0 - -### `safe` option deprecated - -The `safe` option has been deprecated and replaced with two new configuration options: - -* `html_input` - How to handle HTML input. Set this option to one of the following values: - - `strip` - Strip all HTML (equivalent to `'safe' => true`) - - `allow` - Allow all HTML input as-is (equivalent to `'safe' => false) - - `escape` - Escape all HTML - -* `allow_unsafe_links` - Whether to allow risky image URLs and links - - `true` - Allow (equivalent to `'safe' => false`) - - `false` - Remove all risky URLs (equivalent to `'safe' => true`) - -Although `safe` will continue to work until 1.0.0 you should consider updating your configuration now if possible. - diff --git a/vendor/league/commonmark/bin/commonmark b/vendor/league/commonmark/bin/commonmark index 9b9696aeb3..ea3fc3b69b 100755 --- a/vendor/league/commonmark/bin/commonmark +++ b/vendor/league/commonmark/bin/commonmark @@ -15,11 +15,14 @@ $options_raw = getopt('', array( )); foreach ($options_raw as $option => $value) { switch ($option) { + case 'safe': + $options['html_input'] = 'strip'; + $options['allow_unsafe_links'] = false; + break; case 'use-asterisk': case 'use-underscore': case 'enable-strong': case 'enable-em': - case 'safe': if ($value !== true && $value !== false) { fail("Invalid value '$value' for option '$option'"); } diff --git a/vendor/league/commonmark/commonmark-banner.png b/vendor/league/commonmark/commonmark-banner.png Binary files differnew file mode 100644 index 0000000000..5ccbd149ff --- /dev/null +++ b/vendor/league/commonmark/commonmark-banner.png diff --git a/vendor/league/commonmark/composer.json b/vendor/league/commonmark/composer.json index 8c6d8b71fc..56d3cff0d1 100644 --- a/vendor/league/commonmark/composer.json +++ b/vendor/league/commonmark/composer.json @@ -66,7 +66,7 @@ }, "bin": ["bin/commonmark"], "scripts": { - "phpstan": "phpstan analyse -l 4 src", + "phpstan": "phpstan analyse", "phpunit": "phpunit --no-coverage", "test": [ "@phpstan", @@ -75,7 +75,7 @@ }, "extra": { "branch-alias": { - "dev-master": "0.20-dev" + "dev-master": "1.1-dev" } }, "config": { diff --git a/vendor/league/commonmark/src/Block/Element/AbstractBlock.php b/vendor/league/commonmark/src/Block/Element/AbstractBlock.php index 235dbfe13c..8fcc7e2f39 100644 --- a/vendor/league/commonmark/src/Block/Element/AbstractBlock.php +++ b/vendor/league/commonmark/src/Block/Element/AbstractBlock.php @@ -20,6 +20,8 @@ use League\CommonMark\Node\Node; /** * Block-level element + * + * @method parent() ?AbstractBlock */ abstract class AbstractBlock extends Node { @@ -90,6 +92,9 @@ abstract class AbstractBlock extends Node /** * Whether this is a code block * + * Code blocks are extra-greedy - they'll try to consume all subsequent + * lines of content without calling matchesNextLine() each time. + * * @return bool */ abstract public function isCode(): bool; @@ -200,7 +205,10 @@ abstract class AbstractBlock extends Node $this->open = false; $this->endLine = $endLineNumber; - $context->setTip($context->getTip()->parent()); + // This should almost always be true + if ($context->getTip() !== null) { + $context->setTip($context->getTip()->parent()); + } } /** diff --git a/vendor/league/commonmark/src/Block/Element/AbstractStringContainerBlock.php b/vendor/league/commonmark/src/Block/Element/AbstractStringContainerBlock.php index 583c26b52f..52bf70511b 100644 --- a/vendor/league/commonmark/src/Block/Element/AbstractStringContainerBlock.php +++ b/vendor/league/commonmark/src/Block/Element/AbstractStringContainerBlock.php @@ -18,6 +18,9 @@ use League\CommonMark\ContextInterface; use League\CommonMark\Cursor; use League\CommonMark\Util\ArrayCollection; +/** + * @method children() AbstractInline[] + */ abstract class AbstractStringContainerBlock extends AbstractBlock implements StringContainerInterface { /** diff --git a/vendor/league/commonmark/src/Block/Element/BlockQuote.php b/vendor/league/commonmark/src/Block/Element/BlockQuote.php index 569bf8ecd8..46bb257065 100644 --- a/vendor/league/commonmark/src/Block/Element/BlockQuote.php +++ b/vendor/league/commonmark/src/Block/Element/BlockQuote.php @@ -16,6 +16,9 @@ namespace League\CommonMark\Block\Element; use League\CommonMark\Cursor; +/** + * @method children() AbstractBlock[] + */ class BlockQuote extends AbstractBlock { /** diff --git a/vendor/league/commonmark/src/Block/Element/Document.php b/vendor/league/commonmark/src/Block/Element/Document.php index 7ed806b33f..4fe386d008 100644 --- a/vendor/league/commonmark/src/Block/Element/Document.php +++ b/vendor/league/commonmark/src/Block/Element/Document.php @@ -16,25 +16,29 @@ namespace League\CommonMark\Block\Element; use League\CommonMark\Cursor; use League\CommonMark\Reference\ReferenceMap; +use League\CommonMark\Reference\ReferenceMapInterface; +/** + * @method children() AbstractBlock[] + */ class Document extends AbstractBlock { /*** - * @var ReferenceMap + * @var ReferenceMapInterface */ protected $referenceMap; - public function __construct() + public function __construct(?ReferenceMapInterface $referenceMap = null) { $this->setStartLine(1); - $this->referenceMap = new ReferenceMap(); + $this->referenceMap = $referenceMap ?? new ReferenceMap(); } /** - * @return ReferenceMap + * @return ReferenceMapInterface */ - public function getReferenceMap(): ReferenceMap + public function getReferenceMap(): ReferenceMapInterface { return $this->referenceMap; } diff --git a/vendor/league/commonmark/src/Block/Element/ListBlock.php b/vendor/league/commonmark/src/Block/Element/ListBlock.php index dd710d18ea..1d0f53bfce 100644 --- a/vendor/league/commonmark/src/Block/Element/ListBlock.php +++ b/vendor/league/commonmark/src/Block/Element/ListBlock.php @@ -17,6 +17,9 @@ namespace League\CommonMark\Block\Element; use League\CommonMark\ContextInterface; use League\CommonMark\Cursor; +/** + * @method children() AbstractBlock[] + */ class ListBlock extends AbstractBlock { const TYPE_UNORDERED = 'Bullet'; diff --git a/vendor/league/commonmark/src/Block/Element/ListItem.php b/vendor/league/commonmark/src/Block/Element/ListItem.php index e557d40f3a..2fec6f037b 100644 --- a/vendor/league/commonmark/src/Block/Element/ListItem.php +++ b/vendor/league/commonmark/src/Block/Element/ListItem.php @@ -16,6 +16,9 @@ namespace League\CommonMark\Block\Element; use League\CommonMark\Cursor; +/** + * @method children() AbstractBlock[] + */ class ListItem extends AbstractBlock { /** diff --git a/vendor/league/commonmark/src/Block/Parser/ATXHeadingParser.php b/vendor/league/commonmark/src/Block/Parser/ATXHeadingParser.php index dfabf7f72a..c39ea3f312 100644 --- a/vendor/league/commonmark/src/Block/Parser/ATXHeadingParser.php +++ b/vendor/league/commonmark/src/Block/Parser/ATXHeadingParser.php @@ -19,7 +19,7 @@ use League\CommonMark\ContextInterface; use League\CommonMark\Cursor; use League\CommonMark\Util\RegexHelper; -class ATXHeadingParser implements BlockParserInterface +final class ATXHeadingParser implements BlockParserInterface { /** * @param ContextInterface $context diff --git a/vendor/league/commonmark/src/Block/Parser/BlockQuoteParser.php b/vendor/league/commonmark/src/Block/Parser/BlockQuoteParser.php index 4c4ab61532..7300ede8f3 100644 --- a/vendor/league/commonmark/src/Block/Parser/BlockQuoteParser.php +++ b/vendor/league/commonmark/src/Block/Parser/BlockQuoteParser.php @@ -18,7 +18,7 @@ use League\CommonMark\Block\Element\BlockQuote; use League\CommonMark\ContextInterface; use League\CommonMark\Cursor; -class BlockQuoteParser implements BlockParserInterface +final class BlockQuoteParser implements BlockParserInterface { /** * @param ContextInterface $context diff --git a/vendor/league/commonmark/src/Block/Parser/FencedCodeParser.php b/vendor/league/commonmark/src/Block/Parser/FencedCodeParser.php index dc279640c2..56ca75717b 100644 --- a/vendor/league/commonmark/src/Block/Parser/FencedCodeParser.php +++ b/vendor/league/commonmark/src/Block/Parser/FencedCodeParser.php @@ -18,7 +18,7 @@ use League\CommonMark\Block\Element\FencedCode; use League\CommonMark\ContextInterface; use League\CommonMark\Cursor; -class FencedCodeParser implements BlockParserInterface +final class FencedCodeParser implements BlockParserInterface { /** * @param ContextInterface $context diff --git a/vendor/league/commonmark/src/Block/Parser/HtmlBlockParser.php b/vendor/league/commonmark/src/Block/Parser/HtmlBlockParser.php index 107ce1a297..24e8886d78 100644 --- a/vendor/league/commonmark/src/Block/Parser/HtmlBlockParser.php +++ b/vendor/league/commonmark/src/Block/Parser/HtmlBlockParser.php @@ -20,7 +20,7 @@ use League\CommonMark\ContextInterface; use League\CommonMark\Cursor; use League\CommonMark\Util\RegexHelper; -class HtmlBlockParser implements BlockParserInterface +final class HtmlBlockParser implements BlockParserInterface { /** * @param ContextInterface $context diff --git a/vendor/league/commonmark/src/Block/Parser/IndentedCodeParser.php b/vendor/league/commonmark/src/Block/Parser/IndentedCodeParser.php index 8e7ed0562c..52cc0e6f74 100644 --- a/vendor/league/commonmark/src/Block/Parser/IndentedCodeParser.php +++ b/vendor/league/commonmark/src/Block/Parser/IndentedCodeParser.php @@ -19,7 +19,7 @@ use League\CommonMark\Block\Element\Paragraph; use League\CommonMark\ContextInterface; use League\CommonMark\Cursor; -class IndentedCodeParser implements BlockParserInterface +final class IndentedCodeParser implements BlockParserInterface { /** * @param ContextInterface $context diff --git a/vendor/league/commonmark/src/Block/Parser/LazyParagraphParser.php b/vendor/league/commonmark/src/Block/Parser/LazyParagraphParser.php index eaa245028a..d9bfa249db 100644 --- a/vendor/league/commonmark/src/Block/Parser/LazyParagraphParser.php +++ b/vendor/league/commonmark/src/Block/Parser/LazyParagraphParser.php @@ -17,7 +17,7 @@ namespace League\CommonMark\Block\Parser; use League\CommonMark\ContextInterface; use League\CommonMark\Cursor; -class LazyParagraphParser implements BlockParserInterface +final class LazyParagraphParser implements BlockParserInterface { /** * @param ContextInterface $context diff --git a/vendor/league/commonmark/src/Block/Parser/ListParser.php b/vendor/league/commonmark/src/Block/Parser/ListParser.php index e12a42fb70..0ca69ab9fa 100644 --- a/vendor/league/commonmark/src/Block/Parser/ListParser.php +++ b/vendor/league/commonmark/src/Block/Parser/ListParser.php @@ -22,7 +22,7 @@ use League\CommonMark\ContextInterface; use League\CommonMark\Cursor; use League\CommonMark\Util\RegexHelper; -class ListParser implements BlockParserInterface +final class ListParser implements BlockParserInterface { /** * @param ContextInterface $context diff --git a/vendor/league/commonmark/src/Block/Parser/SetExtHeadingParser.php b/vendor/league/commonmark/src/Block/Parser/SetExtHeadingParser.php index c69e2dcab6..e7770ad46d 100644 --- a/vendor/league/commonmark/src/Block/Parser/SetExtHeadingParser.php +++ b/vendor/league/commonmark/src/Block/Parser/SetExtHeadingParser.php @@ -18,10 +18,10 @@ use League\CommonMark\Block\Element\Heading; use League\CommonMark\Block\Element\Paragraph; use League\CommonMark\ContextInterface; use League\CommonMark\Cursor; -use League\CommonMark\ReferenceParser; +use League\CommonMark\Reference\ReferenceParser; use League\CommonMark\Util\RegexHelper; -class SetExtHeadingParser implements BlockParserInterface +final class SetExtHeadingParser implements BlockParserInterface { /** * @param ContextInterface $context @@ -47,7 +47,7 @@ class SetExtHeadingParser implements BlockParserInterface $level = $match[0][0] === '=' ? 1 : 2; $strings = $context->getContainer()->getStrings(); - $strings = $this->resolveReferenceLinkDefinitions($strings, $cursor->getEncoding(), $context->getReferenceParser()); + $strings = $this->resolveReferenceLinkDefinitions($strings, $context->getReferenceParser()); if (empty($strings)) { return false; } @@ -63,15 +63,14 @@ class SetExtHeadingParser implements BlockParserInterface * @see https://github.com/commonmark/commonmark.js/commit/993bbe335931af847460effa99b2411eb643577d * * @param string[] $strings - * @param string $encoding * @param ReferenceParser $referenceParser * * @return string[] */ - private function resolveReferenceLinkDefinitions(array $strings, string $encoding, ReferenceParser $referenceParser): array + private function resolveReferenceLinkDefinitions(array $strings, ReferenceParser $referenceParser): array { foreach ($strings as &$string) { - $cursor = new Cursor($string, $encoding); + $cursor = new Cursor($string); while ($cursor->getCharacter() === '[' && $referenceParser->parse($cursor)) { $string = $cursor->getRemainder(); } diff --git a/vendor/league/commonmark/src/Block/Parser/ThematicBreakParser.php b/vendor/league/commonmark/src/Block/Parser/ThematicBreakParser.php index be008316b1..e9e6f214dd 100644 --- a/vendor/league/commonmark/src/Block/Parser/ThematicBreakParser.php +++ b/vendor/league/commonmark/src/Block/Parser/ThematicBreakParser.php @@ -19,7 +19,7 @@ use League\CommonMark\ContextInterface; use League\CommonMark\Cursor; use League\CommonMark\Util\RegexHelper; -class ThematicBreakParser implements BlockParserInterface +final class ThematicBreakParser implements BlockParserInterface { /** * @param ContextInterface $context diff --git a/vendor/league/commonmark/src/Block/Renderer/BlockQuoteRenderer.php b/vendor/league/commonmark/src/Block/Renderer/BlockQuoteRenderer.php index 9a2a572133..3fcb1c7202 100644 --- a/vendor/league/commonmark/src/Block/Renderer/BlockQuoteRenderer.php +++ b/vendor/league/commonmark/src/Block/Renderer/BlockQuoteRenderer.php @@ -19,7 +19,7 @@ use League\CommonMark\Block\Element\BlockQuote; use League\CommonMark\ElementRendererInterface; use League\CommonMark\HtmlElement; -class BlockQuoteRenderer implements BlockRendererInterface +final class BlockQuoteRenderer implements BlockRendererInterface { /** * @param BlockQuote $block diff --git a/vendor/league/commonmark/src/Block/Renderer/DocumentRenderer.php b/vendor/league/commonmark/src/Block/Renderer/DocumentRenderer.php index 7300cb43f1..a7df51659d 100644 --- a/vendor/league/commonmark/src/Block/Renderer/DocumentRenderer.php +++ b/vendor/league/commonmark/src/Block/Renderer/DocumentRenderer.php @@ -18,7 +18,7 @@ use League\CommonMark\Block\Element\AbstractBlock; use League\CommonMark\Block\Element\Document; use League\CommonMark\ElementRendererInterface; -class DocumentRenderer implements BlockRendererInterface +final class DocumentRenderer implements BlockRendererInterface { /** * @param AbstractBlock|Document $block diff --git a/vendor/league/commonmark/src/Block/Renderer/FencedCodeRenderer.php b/vendor/league/commonmark/src/Block/Renderer/FencedCodeRenderer.php index 29577d6fd9..a60b1d73ff 100644 --- a/vendor/league/commonmark/src/Block/Renderer/FencedCodeRenderer.php +++ b/vendor/league/commonmark/src/Block/Renderer/FencedCodeRenderer.php @@ -20,7 +20,7 @@ use League\CommonMark\ElementRendererInterface; use League\CommonMark\HtmlElement; use League\CommonMark\Util\Xml; -class FencedCodeRenderer implements BlockRendererInterface +final class FencedCodeRenderer implements BlockRendererInterface { /** * @param FencedCode $block diff --git a/vendor/league/commonmark/src/Block/Renderer/HeadingRenderer.php b/vendor/league/commonmark/src/Block/Renderer/HeadingRenderer.php index 05d35cbb14..1c4f13f15c 100644 --- a/vendor/league/commonmark/src/Block/Renderer/HeadingRenderer.php +++ b/vendor/league/commonmark/src/Block/Renderer/HeadingRenderer.php @@ -19,7 +19,7 @@ use League\CommonMark\Block\Element\Heading; use League\CommonMark\ElementRendererInterface; use League\CommonMark\HtmlElement; -class HeadingRenderer implements BlockRendererInterface +final class HeadingRenderer implements BlockRendererInterface { /** * @param Heading $block diff --git a/vendor/league/commonmark/src/Block/Renderer/HtmlBlockRenderer.php b/vendor/league/commonmark/src/Block/Renderer/HtmlBlockRenderer.php index 53f106189b..68d8754fc4 100644 --- a/vendor/league/commonmark/src/Block/Renderer/HtmlBlockRenderer.php +++ b/vendor/league/commonmark/src/Block/Renderer/HtmlBlockRenderer.php @@ -18,13 +18,13 @@ use League\CommonMark\Block\Element\AbstractBlock; use League\CommonMark\Block\Element\HtmlBlock; use League\CommonMark\ElementRendererInterface; use League\CommonMark\EnvironmentInterface; -use League\CommonMark\Util\Configuration; use League\CommonMark\Util\ConfigurationAwareInterface; +use League\CommonMark\Util\ConfigurationInterface; -class HtmlBlockRenderer implements BlockRendererInterface, ConfigurationAwareInterface +final class HtmlBlockRenderer implements BlockRendererInterface, ConfigurationAwareInterface { /** - * @var Configuration + * @var ConfigurationInterface */ protected $config; @@ -41,16 +41,11 @@ class HtmlBlockRenderer implements BlockRendererInterface, ConfigurationAwareInt throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block)); } - // Kept for BC reasons - if ($this->config->getConfig('safe') === true) { + if ($this->config->get('html_input') === EnvironmentInterface::HTML_INPUT_STRIP) { return ''; } - if ($this->config->getConfig('html_input') === EnvironmentInterface::HTML_INPUT_STRIP) { - return ''; - } - - if ($this->config->getConfig('html_input') === EnvironmentInterface::HTML_INPUT_ESCAPE) { + if ($this->config->get('html_input') === EnvironmentInterface::HTML_INPUT_ESCAPE) { return \htmlspecialchars($block->getStringContent(), ENT_NOQUOTES); } @@ -58,9 +53,9 @@ class HtmlBlockRenderer implements BlockRendererInterface, ConfigurationAwareInt } /** - * @param Configuration $configuration + * @param ConfigurationInterface $configuration */ - public function setConfiguration(Configuration $configuration) + public function setConfiguration(ConfigurationInterface $configuration) { $this->config = $configuration; } diff --git a/vendor/league/commonmark/src/Block/Renderer/IndentedCodeRenderer.php b/vendor/league/commonmark/src/Block/Renderer/IndentedCodeRenderer.php index b4de15e1a0..62c483f597 100644 --- a/vendor/league/commonmark/src/Block/Renderer/IndentedCodeRenderer.php +++ b/vendor/league/commonmark/src/Block/Renderer/IndentedCodeRenderer.php @@ -20,7 +20,7 @@ use League\CommonMark\ElementRendererInterface; use League\CommonMark\HtmlElement; use League\CommonMark\Util\Xml; -class IndentedCodeRenderer implements BlockRendererInterface +final class IndentedCodeRenderer implements BlockRendererInterface { /** * @param AbstractBlock $block diff --git a/vendor/league/commonmark/src/Block/Renderer/ListBlockRenderer.php b/vendor/league/commonmark/src/Block/Renderer/ListBlockRenderer.php index 755eec7b3e..9683dbd9ba 100644 --- a/vendor/league/commonmark/src/Block/Renderer/ListBlockRenderer.php +++ b/vendor/league/commonmark/src/Block/Renderer/ListBlockRenderer.php @@ -19,7 +19,7 @@ use League\CommonMark\Block\Element\ListBlock; use League\CommonMark\ElementRendererInterface; use League\CommonMark\HtmlElement; -class ListBlockRenderer implements BlockRendererInterface +final class ListBlockRenderer implements BlockRendererInterface { /** * @param ListBlock $block diff --git a/vendor/league/commonmark/src/Block/Renderer/ListItemRenderer.php b/vendor/league/commonmark/src/Block/Renderer/ListItemRenderer.php index 0a66060fcc..6f165a8af0 100644 --- a/vendor/league/commonmark/src/Block/Renderer/ListItemRenderer.php +++ b/vendor/league/commonmark/src/Block/Renderer/ListItemRenderer.php @@ -19,7 +19,7 @@ use League\CommonMark\Block\Element\ListItem; use League\CommonMark\ElementRendererInterface; use League\CommonMark\HtmlElement; -class ListItemRenderer implements BlockRendererInterface +final class ListItemRenderer implements BlockRendererInterface { /** * @param ListItem $block diff --git a/vendor/league/commonmark/src/Block/Renderer/ParagraphRenderer.php b/vendor/league/commonmark/src/Block/Renderer/ParagraphRenderer.php index 4c56bab41d..c530ade6b2 100644 --- a/vendor/league/commonmark/src/Block/Renderer/ParagraphRenderer.php +++ b/vendor/league/commonmark/src/Block/Renderer/ParagraphRenderer.php @@ -19,7 +19,7 @@ use League\CommonMark\Block\Element\Paragraph; use League\CommonMark\ElementRendererInterface; use League\CommonMark\HtmlElement; -class ParagraphRenderer implements BlockRendererInterface +final class ParagraphRenderer implements BlockRendererInterface { /** * @param Paragraph $block diff --git a/vendor/league/commonmark/src/Block/Renderer/ThematicBreakRenderer.php b/vendor/league/commonmark/src/Block/Renderer/ThematicBreakRenderer.php index 2ae9f07925..775f877aea 100644 --- a/vendor/league/commonmark/src/Block/Renderer/ThematicBreakRenderer.php +++ b/vendor/league/commonmark/src/Block/Renderer/ThematicBreakRenderer.php @@ -19,7 +19,7 @@ use League\CommonMark\Block\Element\ThematicBreak; use League\CommonMark\ElementRendererInterface; use League\CommonMark\HtmlElement; -class ThematicBreakRenderer implements BlockRendererInterface +final class ThematicBreakRenderer implements BlockRendererInterface { /** * @param ThematicBreak $block diff --git a/vendor/league/commonmark/src/CommonMarkConverter.php b/vendor/league/commonmark/src/CommonMarkConverter.php index a47b825c2a..595ef2170b 100644 --- a/vendor/league/commonmark/src/CommonMarkConverter.php +++ b/vendor/league/commonmark/src/CommonMarkConverter.php @@ -23,10 +23,11 @@ class CommonMarkConverter extends Converter * The currently-installed version. * * This might be a typical `x.y.z` version, or `x.y-dev`. - * - * @deprecated This will be removed in 1.0.0 */ - const VERSION = '0.19.3'; + const VERSION = '1.0.0'; + + /** @var EnvironmentInterface */ + protected $environment; /** * Create a new commonmark converter instance. @@ -44,6 +45,16 @@ class CommonMarkConverter extends Converter $environment->mergeConfig($config); } + $this->environment = $environment; + parent::__construct(new DocParser($environment), new HtmlRenderer($environment)); } + + /** + * @return EnvironmentInterface + */ + public function getEnvironment(): EnvironmentInterface + { + return $this->environment; + } } diff --git a/vendor/league/commonmark/src/ConfigurableEnvironmentInterface.php b/vendor/league/commonmark/src/ConfigurableEnvironmentInterface.php index d9f0fa3d13..b47b1b92a0 100644 --- a/vendor/league/commonmark/src/ConfigurableEnvironmentInterface.php +++ b/vendor/league/commonmark/src/ConfigurableEnvironmentInterface.php @@ -13,9 +13,9 @@ namespace League\CommonMark; use League\CommonMark\Block\Parser\BlockParserInterface; use League\CommonMark\Block\Renderer\BlockRendererInterface; +use League\CommonMark\Delimiter\Processor\DelimiterProcessorInterface; use League\CommonMark\Extension\ExtensionInterface; use League\CommonMark\Inline\Parser\InlineParserInterface; -use League\CommonMark\Inline\Processor\InlineProcessorInterface; use League\CommonMark\Inline\Renderer\InlineRendererInterface; /** @@ -63,24 +63,13 @@ interface ConfigurableEnvironmentInterface extends EnvironmentInterface public function addInlineParser(InlineParserInterface $parser, int $priority = 0): ConfigurableEnvironmentInterface; /** - * Registers the given inline processor with the Environment + * Registers the given delimiter processor with the Environment * - * @param InlineProcessorInterface $processor Inline processor instance - * @param int $priority Priority (a higher number will be executed earlier) + * @param DelimiterProcessorInterface $processor Delimiter processors instance * - * @return self - */ - public function addInlineProcessor(InlineProcessorInterface $processor, int $priority = 0): ConfigurableEnvironmentInterface; - - /** - * Registers the given document processor with the Environment - * - * @param DocumentProcessorInterface $processor Document processor instance - * @param int $priority Priority (a higher number will be executed earlier) - * - * @return self + * @return ConfigurableEnvironmentInterface */ - public function addDocumentProcessor(DocumentProcessorInterface $processor, int $priority = 0): ConfigurableEnvironmentInterface; + public function addDelimiterProcessor(DelimiterProcessorInterface $processor): ConfigurableEnvironmentInterface; /** * @param string $blockClass The fully-qualified block element class name the renderer below should handle @@ -101,4 +90,15 @@ interface ConfigurableEnvironmentInterface extends EnvironmentInterface * @return self */ public function addInlineRenderer(string $inlineClass, InlineRendererInterface $renderer, int $priority = 0): ConfigurableEnvironmentInterface; + + /** + * Registers the given event listener + * + * @param string $eventClass Fully-qualified class name of the event this listener should respond to + * @param callable $listener Listener to be executed + * @param int $priority Priority (a higher number will be executed earlier) + * + * @return self + */ + public function addEventListener(string $eventClass, callable $listener, int $priority = 0): ConfigurableEnvironmentInterface; } diff --git a/vendor/league/commonmark/src/Context.php b/vendor/league/commonmark/src/Context.php index 476a73f480..a5799d0220 100644 --- a/vendor/league/commonmark/src/Context.php +++ b/vendor/league/commonmark/src/Context.php @@ -16,6 +16,7 @@ namespace League\CommonMark; use League\CommonMark\Block\Element\AbstractBlock; use League\CommonMark\Block\Element\Document; +use League\CommonMark\Reference\ReferenceParser; /** * Maintains the current state of the Markdown parser engine @@ -63,11 +64,6 @@ class Context implements ContextInterface protected $blocksParsed = false; /** - * @var string - */ - protected $encoding = 'UTF-8'; - - /** * @var ReferenceParser */ protected $referenceParser; @@ -175,11 +171,16 @@ class Context implements ContextInterface { $this->getBlockCloser()->closeUnmatchedBlocks(); $block->setStartLine($this->lineNumber); - while (!$this->tip->canContain($block)) { + + while ($this->tip !== null && !$this->tip->canContain($block)) { $this->tip->finalize($this, $this->lineNumber); } - $this->tip->appendChild($block); + // This should always be true + if ($this->tip !== null) { + $this->tip->appendChild($block); + } + $this->tip = $block; $this->container = $block; } @@ -226,24 +227,4 @@ class Context implements ContextInterface { return $this->referenceParser; } - - /** - * @return string - */ - public function getEncoding(): string - { - return $this->encoding; - } - - /** - * @param string $encoding - * - * @return $this - */ - public function setEncoding(string $encoding): self - { - $this->encoding = $encoding; - - return $this; - } } diff --git a/vendor/league/commonmark/src/ContextInterface.php b/vendor/league/commonmark/src/ContextInterface.php index c0902acc5e..db623a0e45 100644 --- a/vendor/league/commonmark/src/ContextInterface.php +++ b/vendor/league/commonmark/src/ContextInterface.php @@ -16,6 +16,7 @@ namespace League\CommonMark; use League\CommonMark\Block\Element\AbstractBlock; use League\CommonMark\Block\Element\Document; +use League\CommonMark\Reference\ReferenceParser; interface ContextInterface { @@ -87,9 +88,4 @@ interface ContextInterface * @return ReferenceParser */ public function getReferenceParser(): ReferenceParser; - - /** - * @return string - */ - public function getEncoding(): string; } diff --git a/vendor/league/commonmark/src/Converter.php b/vendor/league/commonmark/src/Converter.php index 20a6a7b046..500f0b3e81 100644 --- a/vendor/league/commonmark/src/Converter.php +++ b/vendor/league/commonmark/src/Converter.php @@ -22,7 +22,7 @@ class Converter implements ConverterInterface /** * The document parser instance. * - * @var \League\CommonMark\DocParser + * @var \League\CommonMark\DocParserInterface */ protected $docParser; @@ -36,10 +36,10 @@ class Converter implements ConverterInterface /** * Create a new commonmark converter instance. * - * @param DocParser $docParser + * @param DocParserInterface $docParser * @param ElementRendererInterface $htmlRenderer */ - public function __construct(DocParser $docParser, ElementRendererInterface $htmlRenderer) + public function __construct(DocParserInterface $docParser, ElementRendererInterface $htmlRenderer) { $this->docParser = $docParser; $this->htmlRenderer = $htmlRenderer; diff --git a/vendor/league/commonmark/src/Cursor.php b/vendor/league/commonmark/src/Cursor.php index d0dd8e7aca..ca9788211d 100644 --- a/vendor/league/commonmark/src/Cursor.php +++ b/vendor/league/commonmark/src/Cursor.php @@ -79,23 +79,17 @@ class Cursor private $charCache = []; /** - * @param string $line The line being parsed - * @param string $encoding The encoding of that line + * @param string $line The line being parsed (ASCII or UTF-8) */ - public function __construct(string $line, string $encoding = 'UTF-8') + public function __construct(string $line) { $this->line = $line; - $this->encoding = $encoding; - $this->length = \mb_strlen($line, $this->encoding); + $this->length = \mb_strlen($line, 'UTF-8') ?: 0; $this->isMultibyte = $this->length !== \strlen($line); + $this->encoding = $this->isMultibyte ? 'UTF-8' : 'ASCII'; $this->lineContainsTabs = \preg_match('/\t/', $line) > 0; } - public function getEncoding(): string - { - return $this->encoding; - } - /** * Returns the position of the next character which is not a space (or tab) * diff --git a/vendor/league/commonmark/src/Delimiter/Delimiter.php b/vendor/league/commonmark/src/Delimiter/Delimiter.php index 0777547540..de01598f60 100644 --- a/vendor/league/commonmark/src/Delimiter/Delimiter.php +++ b/vendor/league/commonmark/src/Delimiter/Delimiter.php @@ -14,53 +14,53 @@ namespace League\CommonMark\Delimiter; -use League\CommonMark\Node\Node; +use League\CommonMark\Inline\Element\AbstractStringContainer; -class Delimiter +final class Delimiter implements DelimiterInterface { /** @var string */ - protected $char; + private $char; /** @var int */ - protected $numDelims; + private $length; /** @var int */ - protected $origDelims; + private $originalLength; - /** @var Node */ - protected $inlineNode; + /** @var AbstractStringContainer */ + private $inlineNode; - /** @var Delimiter|null */ - protected $previous; + /** @var DelimiterInterface|null */ + private $previous; - /** @var Delimiter|null */ - protected $next; + /** @var DelimiterInterface|null */ + private $next; /** @var bool */ - protected $canOpen; + private $canOpen; /** @var bool */ - protected $canClose; + private $canClose; /** @var bool */ - protected $active; + private $active; /** @var int|null */ - protected $index; + private $index; /** - * @param string $char - * @param int $numDelims - * @param Node $node - * @param bool $canOpen - * @param bool $canClose - * @param int|null $index + * @param string $char + * @param int $numDelims + * @param AbstractStringContainer $node + * @param bool $canOpen + * @param bool $canClose + * @param int|null $index */ - public function __construct(string $char, int $numDelims, Node $node, bool $canOpen, bool $canClose, ?int $index = null) + public function __construct(string $char, int $numDelims, AbstractStringContainer $node, bool $canOpen, bool $canClose, ?int $index = null) { $this->char = $char; - $this->numDelims = $numDelims; - $this->origDelims = $numDelims; + $this->length = $numDelims; + $this->originalLength = $numDelims; $this->inlineNode = $node; $this->canOpen = $canOpen; $this->canClose = $canClose; @@ -69,7 +69,7 @@ class Delimiter } /** - * @return bool + * {@inheritdoc} */ public function canClose(): bool { @@ -77,19 +77,15 @@ class Delimiter } /** - * @param bool $canClose - * - * @return $this + * {@inheritdoc} */ public function setCanClose(bool $canClose) { $this->canClose = $canClose; - - return $this; } /** - * @return bool + * {@inheritdoc} */ public function canOpen(): bool { @@ -97,19 +93,7 @@ class Delimiter } /** - * @param bool $canOpen - * - * @return $this - */ - public function setCanOpen(bool $canOpen) - { - $this->canOpen = $canOpen; - - return $this; - } - - /** - * @return bool + * {@inheritdoc} */ public function isActive(): bool { @@ -117,19 +101,15 @@ class Delimiter } /** - * @param bool $active - * - * @return $this + * {@inheritdoc} */ public function setActive(bool $active) { $this->active = $active; - - return $this; } /** - * @return string + * {@inheritdoc} */ public function getChar(): string { @@ -137,19 +117,7 @@ class Delimiter } /** - * @param string $char - * - * @return $this - */ - public function setChar(string $char) - { - $this->char = $char; - - return $this; - } - - /** - * @return int|null + * {@inheritdoc} */ public function getIndex(): ?int { @@ -157,99 +125,65 @@ class Delimiter } /** - * @param int|null $index - * - * @return $this + * {@inheritdoc} */ - public function setIndex(?int $index) - { - $this->index = $index; - - return $this; - } - - /** - * @return Delimiter|null - */ - public function getNext(): ?self + public function getNext(): ?DelimiterInterface { return $this->next; } /** - * @param Delimiter|null $next - * - * @return $this + * {@inheritdoc} */ - public function setNext(?self $next) + public function setNext(?DelimiterInterface $next) { $this->next = $next; - - return $this; } /** - * @return int + * {@inheritdoc} */ - public function getNumDelims(): int + public function getLength(): int { - return $this->numDelims; + return $this->length; } /** - * @param int $numDelims - * - * @return $this + * {@inheritdoc} */ - public function setNumDelims(int $numDelims) + public function setLength(int $length) { - $this->numDelims = $numDelims; - - return $this; + $this->length = $length; } /** - * @return int + * {@inheritdoc} */ - public function getOrigDelims(): int + public function getOriginalLength(): int { - return $this->origDelims; + return $this->originalLength; } /** - * @return Node + * {@inheritdoc} */ - public function getInlineNode(): Node + public function getInlineNode(): AbstractStringContainer { return $this->inlineNode; } /** - * @param Node $node - * - * @return $this - */ - public function setInlineNode(Node $node) - { - $this->inlineNode = $node; - - return $this; - } - - /** - * @return Delimiter|null + * {@inheritdoc} */ - public function getPrevious(): ?self + public function getPrevious(): ?DelimiterInterface { return $this->previous; } /** - * @param Delimiter|null $previous - * - * @return $this + * {@inheritdoc} */ - public function setPrevious(?self $previous) + public function setPrevious(?DelimiterInterface $previous): DelimiterInterface { $this->previous = $previous; diff --git a/vendor/league/commonmark/src/Delimiter/DelimiterInterface.php b/vendor/league/commonmark/src/Delimiter/DelimiterInterface.php new file mode 100644 index 0000000000..abdca1154e --- /dev/null +++ b/vendor/league/commonmark/src/Delimiter/DelimiterInterface.php @@ -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\Delimiter; + +use League\CommonMark\Inline\Element\AbstractStringContainer; + +interface DelimiterInterface +{ + /** + * @return bool + */ + public function canClose(): bool; + + /** + * @return bool + */ + public function canOpen(): bool; + + /** + * @return bool + */ + public function isActive(): bool; + + /** + * @param bool $active + */ + public function setActive(bool $active); + + /** + * @return string + */ + public function getChar(): string; + + /** + * @return int|null + */ + public function getIndex(): ?int; + + /** + * @return DelimiterInterface|null + */ + public function getNext(): ?DelimiterInterface; + + /** + * @param DelimiterInterface|null $next + */ + public function setNext(?DelimiterInterface $next); + + /** + * @return int + */ + public function getLength(): int; + + /** + * @param int $length + */ + public function setLength(int $length); + + /** + * @return int + */ + public function getOriginalLength(): int; + + /** + * @return AbstractStringContainer + */ + public function getInlineNode(): AbstractStringContainer; + + /** + * @return DelimiterInterface|null + */ + public function getPrevious(): ?DelimiterInterface; + + /** + * @param DelimiterInterface|null $previous + */ + public function setPrevious(?DelimiterInterface $previous); +} diff --git a/vendor/league/commonmark/src/Delimiter/DelimiterStack.php b/vendor/league/commonmark/src/Delimiter/DelimiterStack.php index 04bc1f65f3..f4727d186e 100644 --- a/vendor/league/commonmark/src/Delimiter/DelimiterStack.php +++ b/vendor/league/commonmark/src/Delimiter/DelimiterStack.php @@ -8,25 +8,26 @@ * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) * - (c) John MacFarlane * + * Additional emphasis processing code based on commonmark-java (https://github.com/atlassian/commonmark-java) + * - (c) Atlassian Pty Ltd + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Delimiter; -class DelimiterStack +use League\CommonMark\Delimiter\Processor\DelimiterProcessorCollection; +use League\CommonMark\Inline\AdjacentTextMerger; + +final class DelimiterStack { /** - * @var Delimiter|null + * @var DelimiterInterface|null */ - protected $top; - - public function getTop(): ?Delimiter - { - return $this->top; - } + private $top; - public function push(Delimiter $newDelimiter) + public function push(DelimiterInterface $newDelimiter) { $newDelimiter->setPrevious($this->top); @@ -38,11 +39,11 @@ class DelimiterStack } /** - * @param Delimiter|null $stackBottom + * @param DelimiterInterface|null $stackBottom * - * @return Delimiter|null + * @return DelimiterInterface|null */ - public function findEarliest(Delimiter $stackBottom = null): ?Delimiter + private function findEarliest(DelimiterInterface $stackBottom = null): ?DelimiterInterface { $delimiter = $this->top; while ($delimiter !== null && $delimiter->getPrevious() !== $stackBottom) { @@ -53,9 +54,9 @@ class DelimiterStack } /** - * @param Delimiter $delimiter + * @param DelimiterInterface $delimiter */ - public function removeDelimiter(Delimiter $delimiter) + public function removeDelimiter(DelimiterInterface $delimiter) { if ($delimiter->getPrevious() !== null) { $delimiter->getPrevious()->setNext($delimiter->getNext()); @@ -69,10 +70,26 @@ class DelimiterStack } } + private function removeDelimiterAndNode(DelimiterInterface $delimiter) + { + $delimiter->getInlineNode()->detach(); + $this->removeDelimiter($delimiter); + } + + private function removeDelimitersBetween(DelimiterInterface $opener, DelimiterInterface $closer) + { + $delimiter = $closer->getPrevious(); + while ($delimiter !== null && $delimiter !== $opener) { + $previous = $delimiter->getPrevious(); + $this->removeDelimiter($delimiter); + $delimiter = $previous; + } + } + /** - * @param Delimiter|null $stackBottom + * @param DelimiterInterface|null $stackBottom */ - public function removeAll(Delimiter $stackBottom = null) + public function removeAll(DelimiterInterface $stackBottom = null) { while ($this->top && $this->top !== $stackBottom) { $this->removeDelimiter($this->top); @@ -97,9 +114,9 @@ class DelimiterStack /** * @param string|string[] $characters * - * @return Delimiter|null + * @return DelimiterInterface|null */ - public function searchByCharacter($characters): ?Delimiter + public function searchByCharacter($characters): ?DelimiterInterface { if (!\is_array($characters)) { $characters = [$characters]; @@ -116,73 +133,90 @@ class DelimiterStack return $opener; } - /** - * @param string|string[] $characters - * @param callable $callback - * @param Delimiter $stackBottom - */ - public function iterateByCharacters($characters, callable $callback, Delimiter $stackBottom = null) + public function processDelimiters(?DelimiterInterface $stackBottom, DelimiterProcessorCollection $processors) { - if (!\is_array($characters)) { - $characters = [$characters]; - } - - $openersBottom = \array_fill_keys($characters, $stackBottom); + $openersBottom = []; // Find first closer above stackBottom $closer = $this->findEarliest($stackBottom); + // Move forward, looking for closers, and handling each while ($closer !== null) { - $closerChar = $closer->getChar(); + $delimiterChar = $closer->getChar(); - if (!$closer->canClose() || !\in_array($closerChar, $characters)) { + $delimiterProcessor = $processors->getDelimiterProcessor($delimiterChar); + if (!$closer->canClose() || $delimiterProcessor === null) { $closer = $closer->getNext(); continue; } - $oddMatch = false; - $opener = $this->findMatchingOpener($closer, $openersBottom, $stackBottom, $oddMatch); - if ($opener) { - $closer = $callback($opener, $closer, $this); - } elseif ($oddMatch) { - $closer = $closer->getNext(); - } else { - $oldCloser = $closer; - $closer = $closer->getNext(); - // Set lower bound for future searches for openers: - $openersBottom[$closerChar] = $oldCloser->getPrevious(); - if (!$oldCloser->canOpen()) { - // We can remove a closer that can't be an opener, - // once we've seen there's no matching opener: - $this->removeDelimiter($oldCloser); + $openingDelimiterChar = $delimiterProcessor->getOpeningCharacter(); + + $useDelims = 0; + $openerFound = false; + $potentialOpenerFound = false; + $opener = $closer->getPrevious(); + while ($opener !== null && $opener !== $stackBottom && $opener !== ($openersBottom[$delimiterChar] ?? null)) { + if ($opener->canOpen() && $opener->getChar() === $openingDelimiterChar) { + $potentialOpenerFound = true; + $useDelims = $delimiterProcessor->getDelimiterUse($opener, $closer); + if ($useDelims > 0) { + $openerFound = true; + break; + } } + $opener = $opener->getPrevious(); + } + + if (!$openerFound) { + if (!$potentialOpenerFound) { + // Only do this when we didn't even have a potential + // opener (one that matches the character and can open). + // If an opener was rejected because of the number of + // delimiters (e.g. because of the "multiple of 3" + // Set lower bound for future searches for openersrule), + // we want to consider it next time because the number + // of delimiters can change as we continue processing. + $openersBottom[$delimiterChar] = $closer->getPrevious(); + if (!$closer->canOpen()) { + // We can remove a closer that can't be an opener, + // once we've seen there's no matching opener. + $this->removeDelimiter($closer); + } + } + $closer = $closer->getNext(); continue; } - } - } - /** - * @param Delimiter $closer - * @param array $openersBottom - * @param Delimiter|null $stackBottom - * @param bool $oddMatch - * - * @return Delimiter|null - */ - protected function findMatchingOpener(Delimiter $closer, array $openersBottom, Delimiter $stackBottom = null, bool &$oddMatch = false): ?Delimiter - { - $closerChar = $closer->getChar(); - $opener = $closer->getPrevious(); + $openerNode = $opener->getInlineNode(); + $closerNode = $closer->getInlineNode(); + + // Remove number of used delimiters from stack and inline nodes. + $opener->setLength($opener->getLength() - $useDelims); + $closer->setLength($closer->getLength() - $useDelims); - while ($opener !== null && $opener !== $stackBottom && $opener !== $openersBottom[$closerChar]) { - $oddMatch = ($closer->canOpen() || $opener->canClose()) && $closer->getOrigDelims() % 3 !== 0 && ($opener->getOrigDelims() + $closer->getOrigDelims()) % 3 === 0; - if ($opener->getChar() === $closerChar && $opener->canOpen() && !$oddMatch) { - return $opener; + $openerNode->setContent(\substr($openerNode->getContent(), 0, -$useDelims)); + $closerNode->setContent(\substr($closerNode->getContent(), 0, -$useDelims)); + + $this->removeDelimitersBetween($opener, $closer); + // The delimiter processor can re-parent the nodes between opener and closer, + // so make sure they're contiguous already. Exclusive because we want to keep opener/closer themselves. + AdjacentTextMerger::mergeTextNodesBetweenExclusive($openerNode, $closerNode); + $delimiterProcessor->process($openerNode, $closerNode, $useDelims); + + // No delimiter characters left to process, so we can remove delimiter and the now empty node. + if ($opener->getLength() === 0) { + $this->removeDelimiterAndNode($opener); } - $opener = $opener->getPrevious(); + if ($closer->getLength() === 0) { + $next = $closer->getNext(); + $this->removeDelimiterAndNode($closer); + $closer = $next; + } } - return null; + // Remove all delimiters + $this->removeAll($stackBottom); } } diff --git a/vendor/league/commonmark/src/Delimiter/Processor/DelimiterProcessorCollection.php b/vendor/league/commonmark/src/Delimiter/Processor/DelimiterProcessorCollection.php new file mode 100644 index 0000000000..433dcde8f3 --- /dev/null +++ b/vendor/league/commonmark/src/Delimiter/Processor/DelimiterProcessorCollection.php @@ -0,0 +1,73 @@ +<?php + +/* + * This file is part of the league/commonmark package. + * + * (c) Colin O'Dell <colinodell@gmail.com> + * + * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) + * - (c) John MacFarlane + * + * Additional emphasis processing code based on commonmark-java (https://github.com/atlassian/commonmark-java) + * - (c) Atlassian Pty Ltd + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace League\CommonMark\Delimiter\Processor; + +final class DelimiterProcessorCollection implements DelimiterProcessorCollectionInterface +{ + /** @var array<string,DelimiterProcessorInterface>|DelimiterProcessorInterface[] */ + private $processorsByChar = []; + + public function add(DelimiterProcessorInterface $processor) + { + $opening = $processor->getOpeningCharacter(); + $closing = $processor->getClosingCharacter(); + + if ($opening === $closing) { + $old = $this->processorsByChar[$opening] ?? null; + if ($old !== null && $old->getOpeningCharacter() === $old->getClosingCharacter()) { + $this->addStaggeredDelimiterProcessorForChar($opening, $old, $processor); + } else { + $this->addDelimiterProcessorForChar($opening, $processor); + } + } else { + $this->addDelimiterProcessorForChar($opening, $processor); + $this->addDelimiterProcessorForChar($closing, $processor); + } + } + + public function getDelimiterProcessor(string $char): ?DelimiterProcessorInterface + { + return $this->processorsByChar[$char] ?? null; + } + + public function getDelimiterCharacters(): array + { + return array_keys($this->processorsByChar); + } + + private function addDelimiterProcessorForChar(string $delimiterChar, DelimiterProcessorInterface $processor) + { + if (isset($this->processorsByChar[$delimiterChar])) { + throw new \InvalidArgumentException(sprintf('Delim processor for character "%s" already exists', $processor->getOpeningCharacter())); + } + + $this->processorsByChar[$delimiterChar] = $processor; + } + + private function addStaggeredDelimiterProcessorForChar(string $opening, DelimiterProcessorInterface $old, DelimiterProcessorInterface $new): void + { + if ($old instanceof StaggeredDelimiterProcessor) { + $s = $old; + } else { + $s = new StaggeredDelimiterProcessor($opening, $old); + } + + $s->add($new); + $this->processorsByChar[$opening] = $s; + } +} diff --git a/vendor/league/commonmark/src/Delimiter/Processor/DelimiterProcessorCollectionInterface.php b/vendor/league/commonmark/src/Delimiter/Processor/DelimiterProcessorCollectionInterface.php new file mode 100644 index 0000000000..f35e0d16ea --- /dev/null +++ b/vendor/league/commonmark/src/Delimiter/Processor/DelimiterProcessorCollectionInterface.php @@ -0,0 +1,46 @@ +<?php + +/* + * This file is part of the league/commonmark package. + * + * (c) Colin O'Dell <colinodell@gmail.com> + * + * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) + * - (c) John MacFarlane + * + * Additional emphasis processing code based on commonmark-java (https://github.com/atlassian/commonmark-java) + * - (c) Atlassian Pty Ltd + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace League\CommonMark\Delimiter\Processor; + +interface DelimiterProcessorCollectionInterface +{ + /** + * Add the given delim processor to the collection + * + * @param DelimiterProcessorInterface $processor The delim processor to add + * + * @throws \InvalidArgumentException Exception will be thrown if attempting to add multiple processors for the same character + */ + public function add(DelimiterProcessorInterface $processor); + + /** + * Returns the delim processor which handles the given character if one exists + * + * @param string $char + * + * @return DelimiterProcessorInterface|null + */ + public function getDelimiterProcessor(string $char): ?DelimiterProcessorInterface; + + /** + * Returns an array of delimiter characters who have associated processors + * + * @return string[] + */ + public function getDelimiterCharacters(): array; +} diff --git a/vendor/league/commonmark/src/Delimiter/Processor/DelimiterProcessorInterface.php b/vendor/league/commonmark/src/Delimiter/Processor/DelimiterProcessorInterface.php new file mode 100644 index 0000000000..bf2ff80130 --- /dev/null +++ b/vendor/league/commonmark/src/Delimiter/Processor/DelimiterProcessorInterface.php @@ -0,0 +1,84 @@ +<?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 + * + * Additional emphasis processing code based on commonmark-java (https://github.com/atlassian/commonmark-java) + * - (c) Atlassian Pty Ltd + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace League\CommonMark\Delimiter\Processor; + +use League\CommonMark\Delimiter\DelimiterInterface; +use League\CommonMark\Inline\Element\AbstractStringContainer; + +/** + * Interface for a delimiter processor + */ +interface DelimiterProcessorInterface +{ + /** + * Returns the character that marks the beginning of a delimited node. + * + * This must not clash with any other processors being added to the environment. + * + * @return string + */ + public function getOpeningCharacter(): string; + + /** + * Returns the character that marks the ending of a delimited node. + * + * This must not clash with any other processors being added to the environment. + * + * Note that for a symmetric delimiter such as "*", this is the same as the opening. + * + * @return string + */ + public function getClosingCharacter(): string; + + /** + * Minimum number of delimiter characters that are needed to active this. + * + * Must be at least 1. + * + * @return int + */ + public function getMinLength(): int; + + /** + * Determine how many (if any) of the delimiter characters should be used. + * + * This allows implementations to decide how many characters to be used + * based on the properties of the delimiter runs. An implementation can also + * return 0 when it doesn't want to allow this particular combination of + * delimiter runs. + * + * @param DelimiterInterface $opener The opening delimiter run + * @param DelimiterInterface $closer The closing delimiter run + * + * @return int + */ + public function getDelimiterUse(DelimiterInterface $opener, DelimiterInterface $closer): int; + + /** + * Process the matched delimiters, e.g. by wrapping the nodes between opener + * and closer in a new node, or appending a new node after the opener. + * + * Note that removal of the delimiter from the delimiter nodes and detaching + * them is done by the caller. + * + * @param AbstractStringContainer $opener The node that contained the opening delimiter + * @param AbstractStringContainer $closer The node that contained the closing delimiter + * @param int $delimiterUse The number of delimiters that were used + */ + public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse); +} diff --git a/vendor/league/commonmark/src/Delimiter/Processor/EmphasisDelimiterProcessor.php b/vendor/league/commonmark/src/Delimiter/Processor/EmphasisDelimiterProcessor.php new file mode 100644 index 0000000000..dfae1f3268 --- /dev/null +++ b/vendor/league/commonmark/src/Delimiter/Processor/EmphasisDelimiterProcessor.php @@ -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 + * + * Additional emphasis processing code based on commonmark-java (https://github.com/atlassian/commonmark-java) + * - (c) Atlassian Pty Ltd + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace League\CommonMark\Delimiter\Processor; + +use League\CommonMark\Delimiter\DelimiterInterface; +use League\CommonMark\Inline\Element\AbstractStringContainer; +use League\CommonMark\Inline\Element\Emphasis; +use League\CommonMark\Inline\Element\Strong; +use League\CommonMark\Util\ConfigurationAwareInterface; +use League\CommonMark\Util\ConfigurationInterface; + +final class EmphasisDelimiterProcessor implements DelimiterProcessorInterface, ConfigurationAwareInterface +{ + /** @var string */ + private $char; + + /** @var ConfigurationInterface|null */ + private $config; + + /** + * @param string $char The emphasis character to use (typically '*' or '_') + */ + public function __construct(string $char) + { + $this->char = $char; + } + + /** + * {@inheritdoc} + */ + public function getOpeningCharacter(): string + { + return $this->char; + } + + /** + * {@inheritdoc} + */ + public function getClosingCharacter(): string + { + return $this->char; + } + + /** + * {@inheritdoc} + */ + public function getMinLength(): int + { + return 1; + } + + /** + * {@inheritdoc} + */ + public function getDelimiterUse(DelimiterInterface $opener, DelimiterInterface $closer): int + { + // "Multiple of 3" rule for internal delimiter runs + if (($opener->canClose() || $closer->canOpen()) && $closer->getOriginalLength() % 3 !== 0 && ($opener->getOriginalLength() + $closer->getOriginalLength()) % 3 === 0) { + return 0; + } + + // 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)) { + return 2; + } + + return 0; + } + + if ($this->config && $this->config->get('enable_em', true)) { + return 1; + } + + return 0; + } + + /** + * {@inheritdoc} + */ + public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse) + { + if ($delimiterUse === 1) { + $emphasis = new Emphasis(); + } elseif ($delimiterUse === 2) { + $emphasis = new Strong(); + } else { + return; + } + + $next = $opener->next(); + while ($next !== null && $next !== $closer) { + $tmp = $next->next(); + $emphasis->appendChild($next); + $next = $tmp; + } + + $opener->insertAfter($emphasis); + } + + /** + * @param ConfigurationInterface $configuration + */ + public function setConfiguration(ConfigurationInterface $configuration) + { + $this->config = $configuration; + } +} diff --git a/vendor/league/commonmark/src/Delimiter/Processor/StaggeredDelimiterProcessor.php b/vendor/league/commonmark/src/Delimiter/Processor/StaggeredDelimiterProcessor.php new file mode 100644 index 0000000000..5364ca2bf1 --- /dev/null +++ b/vendor/league/commonmark/src/Delimiter/Processor/StaggeredDelimiterProcessor.php @@ -0,0 +1,117 @@ +<?php + +/* + * This file is part of the league/commonmark package. + * + * (c) Colin O'Dell <colinodell@gmail.com> + * + * Additional emphasis processing code based on commonmark-java (https://github.com/atlassian/commonmark-java) + * - (c) Atlassian Pty Ltd + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace League\CommonMark\Delimiter\Processor; + +use League\CommonMark\Delimiter\DelimiterInterface; +use League\CommonMark\Inline\Element\AbstractStringContainer; + +/** + * An implementation of DelimiterProcessorInterface that dispatches all calls to two or more other DelimiterProcessors + * depending on the length of the delimiter run. All child DelimiterProcessors must have different minimum + * lengths. A given delimiter run is dispatched to the child with the largest acceptable minimum length. If no + * child is applicable, the one with the largest minimum length is chosen. + * + * @internal + */ +final class StaggeredDelimiterProcessor implements DelimiterProcessorInterface +{ + private $delimiterChar; + + private $minLength = 0; + + /** @var array<int, DelimiterProcessorInterface>|DelimiterProcessorInterface[] */ + private $processors = []; // keyed by minLength in reverse order + + public function __construct(string $char, DelimiterProcessorInterface $processor) + { + $this->delimiterChar = $char; + $this->add($processor); + } + + /** + * {@inheritdoc} + */ + public function getOpeningCharacter(): string + { + return $this->delimiterChar; + } + + /** + * {@inheritdoc} + */ + public function getClosingCharacter(): string + { + return $this->delimiterChar; + } + + /** + * {@inheritdoc} + */ + public function getMinLength(): int + { + return $this->minLength; + } + + /** + * Adds the given processor to this staggered delimiter processor + * + * @param DelimiterProcessorInterface $processor + */ + public function add(DelimiterProcessorInterface $processor) + { + $len = $processor->getMinLength(); + + if (isset($this->processors[$len])) { + throw new \InvalidArgumentException(sprintf('Cannot add two delimiter processors for char "%s" and minimum length %d', $this->delimiterChar, $len)); + } + + $this->processors[$len] = $processor; + krsort($this->processors); + + $this->minLength = min($this->minLength, $len); + } + + /** + * {@inheritdoc} + */ + public function getDelimiterUse(DelimiterInterface $opener, DelimiterInterface $closer): int + { + return $this->findProcessor($opener->getLength())->getDelimiterUse($opener, $closer); + } + + /** + * {@inheritdoc} + */ + public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse) + { + return $this->findProcessor($delimiterUse)->process($opener, $closer, $delimiterUse); + } + + private function findProcessor(int $len): DelimiterProcessorInterface + { + // Find the "longest" processor which can handle this length + foreach ($this->processors as $processor) { + if ($processor->getMinLength() <= $len) { + return $processor; + } + } + + // Just use the first one in our list + /** @var DelimiterProcessorInterface $first */ + $first = reset($this->processors); + + return $first; + } +} diff --git a/vendor/league/commonmark/src/DocParser.php b/vendor/league/commonmark/src/DocParser.php index 457efee115..45eee94ff2 100644 --- a/vendor/league/commonmark/src/DocParser.php +++ b/vendor/league/commonmark/src/DocParser.php @@ -15,17 +15,18 @@ namespace League\CommonMark; use League\CommonMark\Block\Element\AbstractBlock; +use League\CommonMark\Block\Element\AbstractStringContainerBlock; use League\CommonMark\Block\Element\Document; -use League\CommonMark\Block\Element\InlineContainerInterface; use League\CommonMark\Block\Element\Paragraph; use League\CommonMark\Block\Element\StringContainerInterface; +use League\CommonMark\Event\DocumentParsedEvent; -class DocParser +final class DocParser implements DocParserInterface { /** * @var EnvironmentInterface */ - protected $environment; + private $environment; /** * @var InlineParserEngine @@ -48,14 +49,6 @@ class DocParser } /** - * @return EnvironmentInterface - */ - public function getEnvironment(): EnvironmentInterface - { - return $this->environment; - } - - /** * @param string $input * * @return string[] @@ -81,8 +74,8 @@ class DocParser */ public function parse(string $input): Document { - $context = new Context(new Document(), $this->getEnvironment()); - $context->setEncoding(\mb_detect_encoding($input, 'ASCII,UTF-8', true) ?: 'ISO-8859-1'); + $document = new Document(); + $context = new Context($document, $this->environment); $lines = $this->preProcessInput($input); foreach ($lines as $line) { @@ -97,9 +90,9 @@ class DocParser $this->processInlines($context); - $this->processDocument($context); + $this->environment->dispatch(new DocumentParsedEvent($document)); - return $context->getDocument(); + return $document; } private function incorporateLine(ContextInterface $context) @@ -107,7 +100,7 @@ class DocParser $context->getBlockCloser()->resetTip(); $context->setBlocksParsed(false); - $cursor = new Cursor($context->getLine(), $context->getEncoding()); + $cursor = new Cursor($context->getLine()); $this->resetContainer($context, $cursor); $context->getBlockCloser()->setLastMatchedContainer($context->getContainer()); @@ -139,13 +132,6 @@ class DocParser } } - private function processDocument(ContextInterface $context) - { - foreach ($this->getEnvironment()->getDocumentProcessors() as $documentProcessor) { - $documentProcessor->processDocument($context->getDocument()); - } - } - private function processInlines(ContextInterface $context) { $walker = $context->getDocument()->walker(); @@ -156,7 +142,7 @@ class DocParser } $node = $event->getNode(); - if ($node instanceof InlineContainerInterface) { + if ($node instanceof AbstractStringContainerBlock) { $this->inlineParserEngine->parse($node, $context->getDocument()->getReferenceMap()); } } @@ -208,7 +194,7 @@ class DocParser } } - if (!$parsed || $context->getContainer() instanceof StringContainerInterface || $context->getTip()->getDepth() >= $this->maxNestingLevel) { + if (!$parsed || $context->getContainer() instanceof StringContainerInterface || (($tip = $context->getTip()) && $tip->getDepth() >= $this->maxNestingLevel)) { $context->setBlocksParsed(true); break; } diff --git a/vendor/league/commonmark/src/DocumentProcessorInterface.php b/vendor/league/commonmark/src/DocParserInterface.php index 90f55266cf..f43c93093e 100644 --- a/vendor/league/commonmark/src/DocumentProcessorInterface.php +++ b/vendor/league/commonmark/src/DocParserInterface.php @@ -5,9 +5,6 @@ * * (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. */ @@ -16,12 +13,12 @@ namespace League\CommonMark; use League\CommonMark\Block\Element\Document; -interface DocumentProcessorInterface +interface DocParserInterface { /** - * @param Document $document + * @param string $input * - * @return void + * @return Document */ - public function processDocument(Document $document); + public function parse(string $input): Document; } diff --git a/vendor/league/commonmark/src/ElementRendererInterface.php b/vendor/league/commonmark/src/ElementRendererInterface.php index 46c8a8dd1b..86f28b3f50 100644 --- a/vendor/league/commonmark/src/ElementRendererInterface.php +++ b/vendor/league/commonmark/src/ElementRendererInterface.php @@ -31,6 +31,13 @@ interface ElementRendererInterface public function getOption(string $option, $default = null); /** + * @param AbstractInline $inline + * + * @return string + */ + public function renderInline(AbstractInline $inline): string; + + /** * @param AbstractInline[] $inlines * * @return string diff --git a/vendor/league/commonmark/src/Environment.php b/vendor/league/commonmark/src/Environment.php index 0a8dca3f81..a82609612e 100644 --- a/vendor/league/commonmark/src/Environment.php +++ b/vendor/league/commonmark/src/Environment.php @@ -16,10 +16,12 @@ namespace League\CommonMark; use League\CommonMark\Block\Parser\BlockParserInterface; use League\CommonMark\Block\Renderer\BlockRendererInterface; +use League\CommonMark\Delimiter\Processor\DelimiterProcessorCollection; +use League\CommonMark\Delimiter\Processor\DelimiterProcessorInterface; +use League\CommonMark\Event\AbstractEvent; use League\CommonMark\Extension\CommonMarkCoreExtension; use League\CommonMark\Extension\ExtensionInterface; use League\CommonMark\Inline\Parser\InlineParserInterface; -use League\CommonMark\Inline\Processor\InlineProcessorInterface; use League\CommonMark\Inline\Renderer\InlineRendererInterface; use League\CommonMark\Util\Configuration; use League\CommonMark\Util\ConfigurationAwareInterface; @@ -58,14 +60,9 @@ final class Environment implements EnvironmentInterface, ConfigurableEnvironment private $inlineParsersByCharacter = []; /** - * @var PrioritizedList<DocumentProcessorInterface> + * @var DelimiterProcessorCollection */ - private $documentProcessors; - - /** - * @var PrioritizedList<InlineProcessorInterface> - */ - private $inlineProcessors; + private $delimiterProcessors; /** * @var array<string, PrioritizedList<BlockRendererInterface>> @@ -78,6 +75,11 @@ final class Environment implements EnvironmentInterface, ConfigurableEnvironment private $inlineRenderersByClass = []; /** + * @var array<string, PrioritizedList<callable>> + */ + private $listeners = []; + + /** * @var Configuration */ private $config; @@ -93,8 +95,7 @@ final class Environment implements EnvironmentInterface, ConfigurableEnvironment $this->blockParsers = new PrioritizedList(); $this->inlineParsers = new PrioritizedList(); - $this->documentProcessors = new PrioritizedList(); - $this->inlineProcessors = new PrioritizedList(); + $this->delimiterProcessors = new DelimiterProcessorCollection(); } /** @@ -104,7 +105,7 @@ final class Environment implements EnvironmentInterface, ConfigurableEnvironment { $this->assertUninitialized('Failed to modify configuration.'); - $this->config->mergeConfig($config); + $this->config->merge($config); } /** @@ -114,7 +115,7 @@ final class Environment implements EnvironmentInterface, ConfigurableEnvironment { $this->assertUninitialized('Failed to modify configuration.'); - $this->config->setConfig($config); + $this->config->replace($config); } /** @@ -122,7 +123,7 @@ final class Environment implements EnvironmentInterface, ConfigurableEnvironment */ public function getConfig($key = null, $default = null) { - return $this->config->getConfig($key, $default); + return $this->config->get($key, $default); } /** @@ -162,24 +163,10 @@ final class Environment implements EnvironmentInterface, ConfigurableEnvironment /** * {@inheritdoc} */ - public function addInlineProcessor(InlineProcessorInterface $processor, int $priority = 0): ConfigurableEnvironmentInterface - { - $this->assertUninitialized('Failed to add inline processor.'); - - $this->inlineProcessors->add($processor, $priority); - $this->injectEnvironmentAndConfigurationIfNeeded($processor); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function addDocumentProcessor(DocumentProcessorInterface $processor, int $priority = 0): ConfigurableEnvironmentInterface + public function addDelimiterProcessor(DelimiterProcessorInterface $processor): ConfigurableEnvironmentInterface { - $this->assertUninitialized('Failed to add document processor.'); - - $this->documentProcessors->add($processor, $priority); + $this->assertUninitialized('Failed to add delimiter processor.'); + $this->delimiterProcessors->add($processor); $this->injectEnvironmentAndConfigurationIfNeeded($processor); return $this; @@ -246,21 +233,11 @@ final class Environment implements EnvironmentInterface, ConfigurableEnvironment /** * {@inheritdoc} */ - public function getInlineProcessors(): iterable - { - $this->initializeExtensions(); - - return $this->inlineProcessors->getIterator(); - } - - /** - * {@inheritdoc} - */ - public function getDocumentProcessors(): iterable + public function getDelimiterProcessors(): DelimiterProcessorCollection { $this->initializeExtensions(); - return $this->documentProcessors->getIterator(); + return $this->delimiterProcessors; } /** @@ -364,7 +341,6 @@ final class Environment implements EnvironmentInterface, ConfigurableEnvironment 'inner_separator' => "\n", 'soft_break' => "\n", ], - 'safe' => false, // deprecated option 'html_input' => self::HTML_INPUT_ALLOW, 'allow_unsafe_links' => true, 'max_nesting_level' => INF, @@ -381,9 +357,46 @@ final class Environment implements EnvironmentInterface, ConfigurableEnvironment return $this->inlineParserCharacterRegex; } + /** + * {@inheritdoc} + */ + public function addEventListener(string $eventClass, callable $listener, int $priority = 0): ConfigurableEnvironmentInterface + { + $this->assertUninitialized('Failed to add event listener.'); + + if (!isset($this->listeners[$eventClass])) { + $this->listeners[$eventClass] = new PrioritizedList(); + } + + $this->listeners[$eventClass]->add($listener, $priority); + + return $this; + } + + /** + * {@inheritdoc} + */ + public function dispatch(AbstractEvent $event): void + { + $this->initializeExtensions(); + + $type = get_class($event); + + foreach ($this->listeners[$type] ?? [] as $listener) { + if ($event->isPropagationStopped()) { + return; + } + + $listener($event); + } + } + private function buildInlineParserCharacterRegex() { - $chars = \array_keys($this->inlineParsersByCharacter); + $chars = \array_unique(\array_merge( + \array_keys($this->inlineParsersByCharacter), + $this->delimiterProcessors->getDelimiterCharacters() + )); if (empty($chars)) { // If no special inline characters exist then parse the whole line diff --git a/vendor/league/commonmark/src/EnvironmentInterface.php b/vendor/league/commonmark/src/EnvironmentInterface.php index 5f1c5af121..c0f53fcfa1 100644 --- a/vendor/league/commonmark/src/EnvironmentInterface.php +++ b/vendor/league/commonmark/src/EnvironmentInterface.php @@ -13,8 +13,9 @@ namespace League\CommonMark; use League\CommonMark\Block\Parser\BlockParserInterface; use League\CommonMark\Block\Renderer\BlockRendererInterface; +use League\CommonMark\Delimiter\Processor\DelimiterProcessorCollection; +use League\CommonMark\Event\AbstractEvent; use League\CommonMark\Inline\Parser\InlineParserInterface; -use League\CommonMark\Inline\Processor\InlineProcessorInterface; use League\CommonMark\Inline\Renderer\InlineRendererInterface; interface EnvironmentInterface @@ -44,14 +45,9 @@ interface EnvironmentInterface public function getInlineParsersForCharacter(string $character): iterable; /** - * @return iterable<InlineProcessorInterface> + * @return DelimiterProcessorCollection */ - public function getInlineProcessors(): iterable; - - /** - * @return iterable<DocumentProcessorInterface> - */ - public function getDocumentProcessors(): iterable; + public function getDelimiterProcessors(): DelimiterProcessorCollection; /** * @param string $blockClass @@ -75,4 +71,13 @@ interface EnvironmentInterface * @return string */ public function getInlineParserCharacterRegex(): string; + + /** + * Dispatches the given event to listeners + * + * @param AbstractEvent $event + * + * @return void + */ + public function dispatch(AbstractEvent $event): void; } diff --git a/vendor/league/commonmark/src/Event/AbstractEvent.php b/vendor/league/commonmark/src/Event/AbstractEvent.php new file mode 100644 index 0000000000..b2c04ffb0e --- /dev/null +++ b/vendor/league/commonmark/src/Event/AbstractEvent.php @@ -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 Symfony EventDispatcher "Event" contract + * - (c) 2018-2019 Fabien Potencier + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace League\CommonMark\Event; + +/** + * Base class for classes containing event data. + * + * This class contains no event data. It is used by events that do not pass + * state information to an event handler when an event is raised. + * + * You can call the method stopPropagation() to abort the execution of + * further listeners in your event listener. + */ +abstract class AbstractEvent +{ + private $propagationStopped = false; + + /** + * Returns whether further event listeners should be triggered. + */ + final public function isPropagationStopped(): bool + { + return $this->propagationStopped; + } + + /** + * Stops the propagation of the event to further event listeners. + * + * If multiple event listeners are connected to the same event, no + * further event listener will be triggered once any trigger calls + * stopPropagation(). + */ + final public function stopPropagation(): void + { + $this->propagationStopped = true; + } +} diff --git a/vendor/league/commonmark/src/Event/DocumentParsedEvent.php b/vendor/league/commonmark/src/Event/DocumentParsedEvent.php new file mode 100644 index 0000000000..e002e21c2c --- /dev/null +++ b/vendor/league/commonmark/src/Event/DocumentParsedEvent.php @@ -0,0 +1,39 @@ +<?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\Event; + +use League\CommonMark\Block\Element\Document; + +/** + * Event dispatched when the document has been fully parsed + */ +final class DocumentParsedEvent extends AbstractEvent +{ + /** @var Document */ + private $document; + + /** + * @param Document $document + */ + public function __construct(Document $document) + { + $this->document = $document; + } + + /** + * @return Document + */ + public function getDocument(): Document + { + return $this->document; + } +} diff --git a/vendor/league/commonmark/src/Extension/CommonMarkCoreExtension.php b/vendor/league/commonmark/src/Extension/CommonMarkCoreExtension.php index 3c3f7c11c4..903e8991a0 100644 --- a/vendor/league/commonmark/src/Extension/CommonMarkCoreExtension.php +++ b/vendor/league/commonmark/src/Extension/CommonMarkCoreExtension.php @@ -18,9 +18,9 @@ use League\CommonMark\Block\Element as BlockElement; use League\CommonMark\Block\Parser as BlockParser; use League\CommonMark\Block\Renderer as BlockRenderer; use League\CommonMark\ConfigurableEnvironmentInterface; +use League\CommonMark\Delimiter\Processor\EmphasisDelimiterProcessor; use League\CommonMark\Inline\Element as InlineElement; use League\CommonMark\Inline\Parser as InlineParser; -use League\CommonMark\Inline\Processor as InlineProcessor; use League\CommonMark\Inline\Renderer as InlineRenderer; final class CommonMarkCoreExtension implements ExtensionInterface @@ -42,15 +42,12 @@ final class CommonMarkCoreExtension implements ExtensionInterface ->addInlineParser(new InlineParser\BacktickParser(), 150) ->addInlineParser(new InlineParser\EscapableParser(), 80) ->addInlineParser(new InlineParser\EntityParser(), 70) - ->addInlineParser(new InlineParser\EmphasisParser(), 60) ->addInlineParser(new InlineParser\AutolinkParser(), 50) ->addInlineParser(new InlineParser\HtmlInlineParser(), 40) ->addInlineParser(new InlineParser\CloseBracketParser(), 30) ->addInlineParser(new InlineParser\OpenBracketParser(), 20) ->addInlineParser(new InlineParser\BangParser(), 10) - ->addInlineProcessor(new InlineProcessor\EmphasisProcessor(), 0) - ->addBlockRenderer(BlockElement\BlockQuote::class, new BlockRenderer\BlockQuoteRenderer(), 0) ->addBlockRenderer(BlockElement\Document::class, new BlockRenderer\DocumentRenderer(), 0) ->addBlockRenderer(BlockElement\FencedCode::class, new BlockRenderer\FencedCodeRenderer(), 0) @@ -71,5 +68,13 @@ final class CommonMarkCoreExtension implements ExtensionInterface ->addInlineRenderer(InlineElement\Strong::class, new InlineRenderer\StrongRenderer(), 0) ->addInlineRenderer(InlineElement\Text::class, new InlineRenderer\TextRenderer(), 0) ; + + if ($environment->getConfig('use_asterisk', true)) { + $environment->addDelimiterProcessor(new EmphasisDelimiterProcessor('*')); + } + + if ($environment->getConfig('use_underscore', true)) { + $environment->addDelimiterProcessor(new EmphasisDelimiterProcessor('_')); + } } } diff --git a/vendor/league/commonmark/src/HtmlElement.php b/vendor/league/commonmark/src/HtmlElement.php index c099bb44be..415d65b833 100644 --- a/vendor/league/commonmark/src/HtmlElement.php +++ b/vendor/league/commonmark/src/HtmlElement.php @@ -1,5 +1,17 @@ <?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; use League\CommonMark\Util\Xml; diff --git a/vendor/league/commonmark/src/HtmlRenderer.php b/vendor/league/commonmark/src/HtmlRenderer.php index aba9877061..97339ea396 100644 --- a/vendor/league/commonmark/src/HtmlRenderer.php +++ b/vendor/league/commonmark/src/HtmlRenderer.php @@ -22,7 +22,7 @@ use League\CommonMark\Inline\Renderer\InlineRendererInterface; /** * Renders a parsed AST to HTML */ -class HtmlRenderer implements ElementRendererInterface +final class HtmlRenderer implements ElementRendererInterface { /** * @var EnvironmentInterface @@ -55,7 +55,7 @@ class HtmlRenderer implements ElementRendererInterface * * @return string */ - protected function renderInline(AbstractInline $inline): string + public function renderInline(AbstractInline $inline): string { $renderers = $this->environment->getInlineRenderersForClass(get_class($inline)); diff --git a/vendor/league/commonmark/src/Inline/AdjacentTextMerger.php b/vendor/league/commonmark/src/Inline/AdjacentTextMerger.php new file mode 100644 index 0000000000..da28c3990e --- /dev/null +++ b/vendor/league/commonmark/src/Inline/AdjacentTextMerger.php @@ -0,0 +1,91 @@ +<?php + +/* + * This file is part of the league/commonmark package. + * + * (c) Colin O'Dell <colinodell@gmail.com> + * + * Additional emphasis processing code based on commonmark-java (https://github.com/atlassian/commonmark-java) + * - (c) Atlassian Pty Ltd + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace League\CommonMark\Inline; + +use League\CommonMark\Inline\Element\Text; +use League\CommonMark\Node\Node; + +/** + * @internal + */ +final class AdjacentTextMerger +{ + public static function mergeChildNodes(Node $node) + { + // No children or just one child node, no need for merging + if ($node->firstChild() === $node->lastChild() || $node->firstChild() === null || $node->lastChild() === null) { + return; + } + + self::mergeTextNodesInclusive($node->firstChild(), $node->lastChild()); + } + + public static function mergeTextNodesBetweenExclusive(Node $fromNode, Node $toNode) + { + // No nodes between them + if ($fromNode === $toNode || $fromNode->next() === $toNode || $fromNode->next() === null || $toNode->previous() === null) { + return; + } + + self::mergeTextNodesInclusive($fromNode->next(), $toNode->previous()); + } + + private static function mergeTextNodesInclusive(Node $fromNode, Node $toNode) + { + $first = null; + $last = null; + + $node = $fromNode; + while ($node !== null) { + if ($node instanceof Text) { + if ($first === null) { + $first = $node; + } + $last = $node; + } else { + self::mergeIfNeeded($first, $last); + $first = null; + $last = null; + } + if ($node === $toNode) { + break; + } + $node = $node->next(); + } + + self::mergeIfNeeded($first, $last); + } + + private static function mergeIfNeeded(?Text $first, ?Text $last) + { + if ($first === null || $last === null || $first === $last) { + // No merging needed + return; + } + + $s = $first->getContent(); + + $node = $first->next(); + $stop = $last->next(); + while ($node !== $stop && $node instanceof Text) { + $s .= $node->getContent(); + $unlink = $node; + $node = $node->next(); + $unlink->detach(); + } + + $first->setContent($s); + } +} diff --git a/vendor/league/commonmark/src/Inline/AdjoiningTextCollapser.php b/vendor/league/commonmark/src/Inline/AdjoiningTextCollapser.php deleted file mode 100644 index 312940548b..0000000000 --- a/vendor/league/commonmark/src/Inline/AdjoiningTextCollapser.php +++ /dev/null @@ -1,43 +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\Inline; - -use League\CommonMark\Inline\Element\Text; -use League\CommonMark\Node\Node; - -/** - * @internal - */ -final class AdjoiningTextCollapser -{ - /** - * @param Node $container - * - * @internal - */ - public static function collapseTextNodes(Node $container) - { - $walker = $container->walker(); - while (($event = $walker->next()) !== null) { - if ($event->isEntering()) { - $node = $event->getNode(); - $next = $node->next(); - if ($node instanceof Text && $next instanceof Text) { - $node->append($next->getContent()); - $next->detach(); - // Re-start the next `while` iteration at the same spot as before - $walker->resumeAt($node, true); - } - } - } - } -} diff --git a/vendor/league/commonmark/src/Inline/Element/AbstractInline.php b/vendor/league/commonmark/src/Inline/Element/AbstractInline.php index 2406148dfe..c597f37b30 100644 --- a/vendor/league/commonmark/src/Inline/Element/AbstractInline.php +++ b/vendor/league/commonmark/src/Inline/Element/AbstractInline.php @@ -16,6 +16,9 @@ namespace League\CommonMark\Inline\Element; use League\CommonMark\Node\Node; +/** + * @method children() AbstractInline[] + */ abstract class AbstractInline extends Node { /** diff --git a/vendor/league/commonmark/src/Inline/Element/AbstractWebResource.php b/vendor/league/commonmark/src/Inline/Element/AbstractWebResource.php index b39044fa74..ed1eb94015 100644 --- a/vendor/league/commonmark/src/Inline/Element/AbstractWebResource.php +++ b/vendor/league/commonmark/src/Inline/Element/AbstractWebResource.php @@ -14,7 +14,7 @@ namespace League\CommonMark\Inline\Element; -abstract class AbstractWebResource extends AbstractInlineContainer +abstract class AbstractWebResource extends AbstractInline { /** * @var string @@ -45,4 +45,12 @@ abstract class AbstractWebResource extends AbstractInlineContainer return $this; } + + /** + * {@inheritdoc} + */ + public function isContainer(): bool + { + return true; + } } diff --git a/vendor/league/commonmark/src/Inline/Element/Emphasis.php b/vendor/league/commonmark/src/Inline/Element/Emphasis.php index 046b760392..50dbff5f1e 100644 --- a/vendor/league/commonmark/src/Inline/Element/Emphasis.php +++ b/vendor/league/commonmark/src/Inline/Element/Emphasis.php @@ -14,6 +14,13 @@ namespace League\CommonMark\Inline\Element; -class Emphasis extends AbstractInlineContainer +class Emphasis extends AbstractInline { + /** + * {@inheritdoc} + */ + public function isContainer(): bool + { + return true; + } } diff --git a/vendor/league/commonmark/src/Inline/Element/Strong.php b/vendor/league/commonmark/src/Inline/Element/Strong.php index f519c3d8d5..3ff3226a18 100644 --- a/vendor/league/commonmark/src/Inline/Element/Strong.php +++ b/vendor/league/commonmark/src/Inline/Element/Strong.php @@ -14,6 +14,13 @@ namespace League\CommonMark\Inline\Element; -class Strong extends AbstractInlineContainer +class Strong extends AbstractInline { + /** + * {@inheritdoc} + */ + public function isContainer(): bool + { + return true; + } } diff --git a/vendor/league/commonmark/src/Inline/Parser/AutolinkParser.php b/vendor/league/commonmark/src/Inline/Parser/AutolinkParser.php index b61dc963f0..2d35e43743 100644 --- a/vendor/league/commonmark/src/Inline/Parser/AutolinkParser.php +++ b/vendor/league/commonmark/src/Inline/Parser/AutolinkParser.php @@ -18,7 +18,7 @@ use League\CommonMark\Inline\Element\Link; use League\CommonMark\InlineParserContext; use League\CommonMark\Util\UrlEncoder; -class AutolinkParser implements InlineParserInterface +final class AutolinkParser implements InlineParserInterface { const EMAIL_REGEX = '/^<([a-zA-Z0-9.!#$%&\'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)>/'; const OTHER_LINK_REGEX = '/^<[A-Za-z][A-Za-z0-9.+-]{1,31}:[^<>\x00-\x20]*>/i'; diff --git a/vendor/league/commonmark/src/Inline/Parser/BacktickParser.php b/vendor/league/commonmark/src/Inline/Parser/BacktickParser.php index f74e5413ed..8c9ab52a02 100644 --- a/vendor/league/commonmark/src/Inline/Parser/BacktickParser.php +++ b/vendor/league/commonmark/src/Inline/Parser/BacktickParser.php @@ -18,7 +18,7 @@ use League\CommonMark\Inline\Element\Code; use League\CommonMark\Inline\Element\Text; use League\CommonMark\InlineParserContext; -class BacktickParser implements InlineParserInterface +final class BacktickParser implements InlineParserInterface { /** * @return string[] diff --git a/vendor/league/commonmark/src/Inline/Parser/BangParser.php b/vendor/league/commonmark/src/Inline/Parser/BangParser.php index 59740263d5..f5d72cabc9 100644 --- a/vendor/league/commonmark/src/Inline/Parser/BangParser.php +++ b/vendor/league/commonmark/src/Inline/Parser/BangParser.php @@ -18,7 +18,7 @@ use League\CommonMark\Delimiter\Delimiter; use League\CommonMark\Inline\Element\Text; use League\CommonMark\InlineParserContext; -class BangParser implements InlineParserInterface +final class BangParser implements InlineParserInterface { /** * @return string[] diff --git a/vendor/league/commonmark/src/Inline/Parser/CloseBracketParser.php b/vendor/league/commonmark/src/Inline/Parser/CloseBracketParser.php index 71ca2e8ddb..2a3065de09 100644 --- a/vendor/league/commonmark/src/Inline/Parser/CloseBracketParser.php +++ b/vendor/league/commonmark/src/Inline/Parser/CloseBracketParser.php @@ -15,25 +15,25 @@ namespace League\CommonMark\Inline\Parser; use League\CommonMark\Cursor; -use League\CommonMark\Delimiter\Delimiter; -use League\CommonMark\Delimiter\DelimiterStack; +use League\CommonMark\Delimiter\DelimiterInterface; use League\CommonMark\EnvironmentAwareInterface; use League\CommonMark\EnvironmentInterface; +use League\CommonMark\Inline\AdjacentTextMerger; use League\CommonMark\Inline\Element\AbstractWebResource; use League\CommonMark\Inline\Element\Image; use League\CommonMark\Inline\Element\Link; use League\CommonMark\InlineParserContext; -use League\CommonMark\Reference\Reference; -use League\CommonMark\Reference\ReferenceMap; +use League\CommonMark\Reference\ReferenceInterface; +use League\CommonMark\Reference\ReferenceMapInterface; use League\CommonMark\Util\LinkParserHelper; use League\CommonMark\Util\RegexHelper; -class CloseBracketParser implements InlineParserInterface, EnvironmentAwareInterface +final class CloseBracketParser implements InlineParserInterface, EnvironmentAwareInterface { /** * @var EnvironmentInterface */ - protected $environment; + private $environment; /** * @return string[] @@ -87,14 +87,14 @@ class CloseBracketParser implements InlineParserInterface, EnvironmentAwareInter $inline->appendChild($label); } + // Process delimiters such as emphasis inside link/image $delimiterStack = $inlineContext->getDelimiterStack(); $stackBottom = $opener->getPrevious(); - foreach ($this->environment->getInlineProcessors() as $inlineProcessor) { - $inlineProcessor->processInlines($delimiterStack, $stackBottom); - } - if ($delimiterStack instanceof DelimiterStack) { - $delimiterStack->removeAll($stackBottom); - } + $delimiterStack->processDelimiters($stackBottom, $this->environment->getDelimiterProcessors()); + $delimiterStack->removeAll($stackBottom); + + // Merge any adjacent Text nodes together + AdjacentTextMerger::mergeChildNodes($inline); // processEmphasis will remove this and later delimiters. // Now, for a link, we also remove earlier link openers (no links in links) @@ -114,14 +114,14 @@ class CloseBracketParser implements InlineParserInterface, EnvironmentAwareInter } /** - * @param Cursor $cursor - * @param ReferenceMap $referenceMap - * @param Delimiter $opener - * @param int $startPos + * @param Cursor $cursor + * @param ReferenceMapInterface $referenceMap + * @param DelimiterInterface $opener + * @param int $startPos * * @return array|bool */ - protected function tryParseLink(Cursor $cursor, ReferenceMap $referenceMap, Delimiter $opener, int $startPos) + private function tryParseLink(Cursor $cursor, ReferenceMapInterface $referenceMap, DelimiterInterface $opener, int $startPos) { // Check to see if we have a link/image // Inline link? @@ -141,7 +141,7 @@ class CloseBracketParser implements InlineParserInterface, EnvironmentAwareInter * * @return array|bool */ - protected function tryParseInlineLinkAndTitle(Cursor $cursor) + private function tryParseInlineLinkAndTitle(Cursor $cursor) { if ($cursor->getCharacter() !== '(') { return false; @@ -177,15 +177,19 @@ class CloseBracketParser implements InlineParserInterface, EnvironmentAwareInter } /** - * @param Cursor $cursor - * @param ReferenceMap $referenceMap - * @param Delimiter $opener - * @param int $startPos + * @param Cursor $cursor + * @param ReferenceMapInterface $referenceMap + * @param DelimiterInterface $opener + * @param int $startPos * - * @return Reference|null + * @return ReferenceInterface|null */ - protected function tryParseReference(Cursor $cursor, ReferenceMap $referenceMap, Delimiter $opener, int $startPos): ?Reference + private function tryParseReference(Cursor $cursor, ReferenceMapInterface $referenceMap, DelimiterInterface $opener, int $startPos): ?ReferenceInterface { + if ($opener->getIndex() === null) { + return null; + } + $savePos = $cursor->saveState(); $beforeLabel = $cursor->getPosition(); $n = LinkParserHelper::parseLinkLabel($cursor); @@ -211,7 +215,7 @@ class CloseBracketParser implements InlineParserInterface, EnvironmentAwareInter * * @return AbstractWebResource */ - protected function createInline(string $url, string $title, bool $isImage) + private function createInline(string $url, string $title, bool $isImage) { if ($isImage) { return new Image($url, null, $title); diff --git a/vendor/league/commonmark/src/Inline/Parser/EmphasisParser.php b/vendor/league/commonmark/src/Inline/Parser/EmphasisParser.php deleted file mode 100644 index f58022b869..0000000000 --- a/vendor/league/commonmark/src/Inline/Parser/EmphasisParser.php +++ /dev/null @@ -1,147 +0,0 @@ -<?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\Inline\Parser; - -use League\CommonMark\Delimiter\Delimiter; -use League\CommonMark\EnvironmentAwareInterface; -use League\CommonMark\EnvironmentInterface; -use League\CommonMark\Inline\Element\Text; -use League\CommonMark\InlineParserContext; -use League\CommonMark\Util\Configuration; -use League\CommonMark\Util\RegexHelper; - -class EmphasisParser implements InlineParserInterface, EnvironmentAwareInterface -{ - protected $config; - - public function __construct(array $newConfig = []) - { - $this->config = new Configuration([ - 'use_asterisk' => true, - 'use_underscore' => true, - 'enable_em' => true, - 'enable_strong' => true, - ]); - $this->config->mergeConfig($newConfig); - } - - public function setEnvironment(EnvironmentInterface $environment) - { - $this->config->mergeConfig($environment->getConfig()); - } - - /** - * @return string[] - */ - public function getCharacters(): array - { - if (!$this->config->getConfig('enable_em') && !$this->config->getConfig('enable_strong')) { - return []; - } - - $chars = []; - if ($this->config->getConfig('use_asterisk')) { - $chars[] = '*'; - } - if ($this->config->getConfig('use_underscore')) { - $chars[] = '_'; - } - - return $chars; - } - - /** - * @param InlineParserContext $inlineContext - * - * @return bool - */ - public function parse(InlineParserContext $inlineContext): bool - { - $character = $inlineContext->getCursor()->getCharacter(); - if (!\in_array($character, $this->getCharacters())) { - return false; - } - - $numDelims = 0; - - $cursor = $inlineContext->getCursor(); - $charBefore = $cursor->peek(-1); - if ($charBefore === null) { - $charBefore = "\n"; - } - - while ($cursor->peek($numDelims) === $character) { - ++$numDelims; - } - - if ($numDelims === 0) { - return false; - } - - // Skip single delims if emphasis is disabled - if ($numDelims === 1 && !$this->config->getConfig('enable_em')) { - return false; - } - - $cursor->advanceBy($numDelims); - - $charAfter = $cursor->getCharacter(); - if ($charAfter === null) { - $charAfter = "\n"; - } - - list($canOpen, $canClose) = $this->determineCanOpenOrClose($charBefore, $charAfter, $character); - - $node = new Text($cursor->getPreviousText(), [ - 'delim' => true, - 'emphasis_config' => $this->config, - ]); - $inlineContext->getContainer()->appendChild($node); - - // Add entry to stack to this opener - $delimiter = new Delimiter($character, $numDelims, $node, $canOpen, $canClose); - $inlineContext->getDelimiterStack()->push($delimiter); - - return true; - } - - /** - * @param string $charBefore - * @param string $charAfter - * @param string $character - * - * @return bool[] - */ - private function determineCanOpenOrClose(string $charBefore, string $charAfter, string $character) - { - $afterIsWhitespace = \preg_match(RegexHelper::REGEX_UNICODE_WHITESPACE_CHAR, $charAfter); - $afterIsPunctuation = \preg_match(RegexHelper::REGEX_PUNCTUATION, $charAfter); - $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); - - if ($character === '_') { - $canOpen = $leftFlanking && (!$rightFlanking || $beforeIsPunctuation); - $canClose = $rightFlanking && (!$leftFlanking || $afterIsPunctuation); - } else { - $canOpen = $leftFlanking; - $canClose = $rightFlanking; - } - - return [$canOpen, $canClose]; - } -} diff --git a/vendor/league/commonmark/src/Inline/Parser/EntityParser.php b/vendor/league/commonmark/src/Inline/Parser/EntityParser.php index 83a207f7f8..772642380c 100644 --- a/vendor/league/commonmark/src/Inline/Parser/EntityParser.php +++ b/vendor/league/commonmark/src/Inline/Parser/EntityParser.php @@ -19,7 +19,7 @@ use League\CommonMark\InlineParserContext; use League\CommonMark\Util\Html5Entities; use League\CommonMark\Util\RegexHelper; -class EntityParser implements InlineParserInterface +final class EntityParser implements InlineParserInterface { /** * @return string[] diff --git a/vendor/league/commonmark/src/Inline/Parser/EscapableParser.php b/vendor/league/commonmark/src/Inline/Parser/EscapableParser.php index d96400ab77..6bbaf435dd 100644 --- a/vendor/league/commonmark/src/Inline/Parser/EscapableParser.php +++ b/vendor/league/commonmark/src/Inline/Parser/EscapableParser.php @@ -19,7 +19,7 @@ use League\CommonMark\Inline\Element\Text; use League\CommonMark\InlineParserContext; use League\CommonMark\Util\RegexHelper; -class EscapableParser implements InlineParserInterface +final class EscapableParser implements InlineParserInterface { /** * @return string[] diff --git a/vendor/league/commonmark/src/Inline/Parser/HtmlInlineParser.php b/vendor/league/commonmark/src/Inline/Parser/HtmlInlineParser.php index 297f088842..8f0650ec8a 100644 --- a/vendor/league/commonmark/src/Inline/Parser/HtmlInlineParser.php +++ b/vendor/league/commonmark/src/Inline/Parser/HtmlInlineParser.php @@ -18,7 +18,7 @@ use League\CommonMark\Inline\Element\HtmlInline; use League\CommonMark\InlineParserContext; use League\CommonMark\Util\RegexHelper; -class HtmlInlineParser implements InlineParserInterface +final class HtmlInlineParser implements InlineParserInterface { /** * @return string[] diff --git a/vendor/league/commonmark/src/Inline/Parser/NewlineParser.php b/vendor/league/commonmark/src/Inline/Parser/NewlineParser.php index 1ca8c01f52..6ac4077733 100644 --- a/vendor/league/commonmark/src/Inline/Parser/NewlineParser.php +++ b/vendor/league/commonmark/src/Inline/Parser/NewlineParser.php @@ -18,7 +18,7 @@ use League\CommonMark\Inline\Element\Newline; use League\CommonMark\Inline\Element\Text; use League\CommonMark\InlineParserContext; -class NewlineParser implements InlineParserInterface +final class NewlineParser implements InlineParserInterface { /** * @return string[] diff --git a/vendor/league/commonmark/src/Inline/Parser/OpenBracketParser.php b/vendor/league/commonmark/src/Inline/Parser/OpenBracketParser.php index 81c453d918..d11edc3039 100644 --- a/vendor/league/commonmark/src/Inline/Parser/OpenBracketParser.php +++ b/vendor/league/commonmark/src/Inline/Parser/OpenBracketParser.php @@ -18,7 +18,7 @@ use League\CommonMark\Delimiter\Delimiter; use League\CommonMark\Inline\Element\Text; use League\CommonMark\InlineParserContext; -class OpenBracketParser implements InlineParserInterface +final class OpenBracketParser implements InlineParserInterface { /** * @return string[] diff --git a/vendor/league/commonmark/src/Inline/Processor/EmphasisProcessor.php b/vendor/league/commonmark/src/Inline/Processor/EmphasisProcessor.php deleted file mode 100644 index 1bc96162ec..0000000000 --- a/vendor/league/commonmark/src/Inline/Processor/EmphasisProcessor.php +++ /dev/null @@ -1,81 +0,0 @@ -<?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\Inline\Processor; - -use League\CommonMark\Delimiter\Delimiter; -use League\CommonMark\Delimiter\DelimiterStack; -use League\CommonMark\Inline\Element\Emphasis; -use League\CommonMark\Inline\Element\Strong; -use League\CommonMark\Inline\Element\Text; - -class EmphasisProcessor implements InlineProcessorInterface -{ - public function processInlines(DelimiterStack $delimiterStack, Delimiter $stackBottom = null) - { - $callback = function (Delimiter $opener, Delimiter $closer, DelimiterStack $stack) { - // Calculate actual number of delimiters used from this closer - $useDelims = ($closer->getNumDelims() >= 2 && $opener->getNumDelims() >= 2) ? 2 : 1; - /** @var Text $openerInline */ - $openerInline = $opener->getInlineNode(); - /** @var Text $closerInline */ - $closerInline = $closer->getInlineNode(); - - // Remove used delimiters from stack elts and inlines - $opener->setNumDelims($opener->getNumDelims() - $useDelims); - $closer->setNumDelims($closer->getNumDelims() - $useDelims); - $openerInline->setContent(\substr($openerInline->getContent(), 0, -$useDelims)); - $closerInline->setContent(\substr($closerInline->getContent(), 0, -$useDelims)); - - // Build contents for new emph element - if ($useDelims === 1 && $openerInline->data['emphasis_config']->getConfig('enable_em')) { - $emph = new Emphasis(); - } elseif ($useDelims > 1 && $openerInline->data['emphasis_config']->getConfig('enable_strong')) { - $emph = new Strong(); - } else { - return $closer->getNext(); - } - - $openerInline->insertAfter($emph); - while (($node = $emph->next()) !== $closerInline) { - $emph->appendChild($node); - } - - // Remove elts btw opener and closer in delimiters stack - $tempStack = $closer->getPrevious(); - while ($tempStack !== null && $tempStack !== $opener) { - $nextStack = $tempStack->getPrevious(); - $stack->removeDelimiter($tempStack); - $tempStack = $nextStack; - } - // If opener has 0 delims, remove it and the inline - if ($opener->getNumDelims() === 0) { - $openerInline->detach(); - $stack->removeDelimiter($opener); - } - if ($closer->getNumDelims() === 0) { - $closerInline->detach(); - $tempStack = $closer->getNext(); - $stack->removeDelimiter($closer); - - return $tempStack; - } - - return $closer; - }; - - // Process the emphasis characters - $delimiterStack->iterateByCharacters(['_', '*'], $callback, $stackBottom); - } -} diff --git a/vendor/league/commonmark/src/Inline/Processor/InlineProcessorInterface.php b/vendor/league/commonmark/src/Inline/Processor/InlineProcessorInterface.php deleted file mode 100644 index b1a6041799..0000000000 --- a/vendor/league/commonmark/src/Inline/Processor/InlineProcessorInterface.php +++ /dev/null @@ -1,29 +0,0 @@ -<?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\Inline\Processor; - -use League\CommonMark\Delimiter\Delimiter; -use League\CommonMark\Delimiter\DelimiterStack; - -interface InlineProcessorInterface -{ - /** - * @param DelimiterStack $delimiterStack - * @param Delimiter $stackBottom - * - * @return void - */ - public function processInlines(DelimiterStack $delimiterStack, Delimiter $stackBottom = null); -} diff --git a/vendor/league/commonmark/src/Inline/Renderer/CodeRenderer.php b/vendor/league/commonmark/src/Inline/Renderer/CodeRenderer.php index d629b16d6f..63fa095b47 100644 --- a/vendor/league/commonmark/src/Inline/Renderer/CodeRenderer.php +++ b/vendor/league/commonmark/src/Inline/Renderer/CodeRenderer.php @@ -20,7 +20,7 @@ use League\CommonMark\Inline\Element\AbstractInline; use League\CommonMark\Inline\Element\Code; use League\CommonMark\Util\Xml; -class CodeRenderer implements InlineRendererInterface +final class CodeRenderer implements InlineRendererInterface { /** * @param Code $inline diff --git a/vendor/league/commonmark/src/Inline/Renderer/EmphasisRenderer.php b/vendor/league/commonmark/src/Inline/Renderer/EmphasisRenderer.php index ac06590a66..d2df5dfd81 100644 --- a/vendor/league/commonmark/src/Inline/Renderer/EmphasisRenderer.php +++ b/vendor/league/commonmark/src/Inline/Renderer/EmphasisRenderer.php @@ -19,7 +19,7 @@ use League\CommonMark\HtmlElement; use League\CommonMark\Inline\Element\AbstractInline; use League\CommonMark\Inline\Element\Emphasis; -class EmphasisRenderer implements InlineRendererInterface +final class EmphasisRenderer implements InlineRendererInterface { /** * @param Emphasis $inline diff --git a/vendor/league/commonmark/src/Inline/Renderer/HtmlInlineRenderer.php b/vendor/league/commonmark/src/Inline/Renderer/HtmlInlineRenderer.php index 720a8c6c19..2dff18f045 100644 --- a/vendor/league/commonmark/src/Inline/Renderer/HtmlInlineRenderer.php +++ b/vendor/league/commonmark/src/Inline/Renderer/HtmlInlineRenderer.php @@ -18,13 +18,13 @@ use League\CommonMark\ElementRendererInterface; use League\CommonMark\EnvironmentInterface; use League\CommonMark\Inline\Element\AbstractInline; use League\CommonMark\Inline\Element\HtmlInline; -use League\CommonMark\Util\Configuration; use League\CommonMark\Util\ConfigurationAwareInterface; +use League\CommonMark\Util\ConfigurationInterface; -class HtmlInlineRenderer implements InlineRendererInterface, ConfigurationAwareInterface +final class HtmlInlineRenderer implements InlineRendererInterface, ConfigurationAwareInterface { /** - * @var Configuration + * @var ConfigurationInterface */ protected $config; @@ -40,16 +40,11 @@ class HtmlInlineRenderer implements InlineRendererInterface, ConfigurationAwareI throw new \InvalidArgumentException('Incompatible inline type: ' . \get_class($inline)); } - // Kept for BC reasons - if ($this->config->getConfig('safe') === true) { + if ($this->config->get('html_input') === EnvironmentInterface::HTML_INPUT_STRIP) { return ''; } - if ($this->config->getConfig('html_input') === EnvironmentInterface::HTML_INPUT_STRIP) { - return ''; - } - - if ($this->config->getConfig('html_input') === EnvironmentInterface::HTML_INPUT_ESCAPE) { + if ($this->config->get('html_input') === EnvironmentInterface::HTML_INPUT_ESCAPE) { return htmlspecialchars($inline->getContent(), ENT_NOQUOTES); } @@ -57,9 +52,9 @@ class HtmlInlineRenderer implements InlineRendererInterface, ConfigurationAwareI } /** - * @param Configuration $configuration + * @param ConfigurationInterface $configuration */ - public function setConfiguration(Configuration $configuration) + public function setConfiguration(ConfigurationInterface $configuration) { $this->config = $configuration; } diff --git a/vendor/league/commonmark/src/Inline/Renderer/ImageRenderer.php b/vendor/league/commonmark/src/Inline/Renderer/ImageRenderer.php index 77fd8918ea..e43a0a5d25 100644 --- a/vendor/league/commonmark/src/Inline/Renderer/ImageRenderer.php +++ b/vendor/league/commonmark/src/Inline/Renderer/ImageRenderer.php @@ -18,14 +18,14 @@ use League\CommonMark\ElementRendererInterface; use League\CommonMark\HtmlElement; use League\CommonMark\Inline\Element\AbstractInline; use League\CommonMark\Inline\Element\Image; -use League\CommonMark\Util\Configuration; use League\CommonMark\Util\ConfigurationAwareInterface; +use League\CommonMark\Util\ConfigurationInterface; use League\CommonMark\Util\RegexHelper; -class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterface +final class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterface { /** - * @var Configuration + * @var ConfigurationInterface */ protected $config; @@ -43,7 +43,7 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf $attrs = $inline->getData('attributes', []); - $forbidUnsafeLinks = $this->config->getConfig('safe') || !$this->config->getConfig('allow_unsafe_links'); + $forbidUnsafeLinks = !$this->config->get('allow_unsafe_links'); if ($forbidUnsafeLinks && RegexHelper::isLinkPotentiallyUnsafe($inline->getUrl())) { $attrs['src'] = ''; } else { @@ -62,9 +62,9 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf } /** - * @param Configuration $configuration + * @param ConfigurationInterface $configuration */ - public function setConfiguration(Configuration $configuration) + public function setConfiguration(ConfigurationInterface $configuration) { $this->config = $configuration; } diff --git a/vendor/league/commonmark/src/Inline/Renderer/LinkRenderer.php b/vendor/league/commonmark/src/Inline/Renderer/LinkRenderer.php index 7ad85152c5..c83125e689 100644 --- a/vendor/league/commonmark/src/Inline/Renderer/LinkRenderer.php +++ b/vendor/league/commonmark/src/Inline/Renderer/LinkRenderer.php @@ -18,14 +18,14 @@ use League\CommonMark\ElementRendererInterface; use League\CommonMark\HtmlElement; use League\CommonMark\Inline\Element\AbstractInline; use League\CommonMark\Inline\Element\Link; -use League\CommonMark\Util\Configuration; use League\CommonMark\Util\ConfigurationAwareInterface; +use League\CommonMark\Util\ConfigurationInterface; use League\CommonMark\Util\RegexHelper; -class LinkRenderer implements InlineRendererInterface, ConfigurationAwareInterface +final class LinkRenderer implements InlineRendererInterface, ConfigurationAwareInterface { /** - * @var Configuration + * @var ConfigurationInterface */ protected $config; @@ -43,7 +43,7 @@ class LinkRenderer implements InlineRendererInterface, ConfigurationAwareInterfa $attrs = $inline->getData('attributes', []); - $forbidUnsafeLinks = $this->config->getConfig('safe') || !$this->config->getConfig('allow_unsafe_links'); + $forbidUnsafeLinks = !$this->config->get('allow_unsafe_links'); if (!($forbidUnsafeLinks && RegexHelper::isLinkPotentiallyUnsafe($inline->getUrl()))) { $attrs['href'] = $inline->getUrl(); } @@ -60,9 +60,9 @@ class LinkRenderer implements InlineRendererInterface, ConfigurationAwareInterfa } /** - * @param Configuration $configuration + * @param ConfigurationInterface $configuration */ - public function setConfiguration(Configuration $configuration) + public function setConfiguration(ConfigurationInterface $configuration) { $this->config = $configuration; } diff --git a/vendor/league/commonmark/src/Inline/Renderer/NewlineRenderer.php b/vendor/league/commonmark/src/Inline/Renderer/NewlineRenderer.php index 334e0e2b1d..2314b22cea 100644 --- a/vendor/league/commonmark/src/Inline/Renderer/NewlineRenderer.php +++ b/vendor/league/commonmark/src/Inline/Renderer/NewlineRenderer.php @@ -19,7 +19,7 @@ use League\CommonMark\HtmlElement; use League\CommonMark\Inline\Element\AbstractInline; use League\CommonMark\Inline\Element\Newline; -class NewlineRenderer implements InlineRendererInterface +final class NewlineRenderer implements InlineRendererInterface { /** * @param Newline $inline diff --git a/vendor/league/commonmark/src/Inline/Renderer/StrongRenderer.php b/vendor/league/commonmark/src/Inline/Renderer/StrongRenderer.php index 6aaa3848bc..1862433027 100644 --- a/vendor/league/commonmark/src/Inline/Renderer/StrongRenderer.php +++ b/vendor/league/commonmark/src/Inline/Renderer/StrongRenderer.php @@ -19,7 +19,7 @@ use League\CommonMark\HtmlElement; use League\CommonMark\Inline\Element\AbstractInline; use League\CommonMark\Inline\Element\Strong; -class StrongRenderer implements InlineRendererInterface +final class StrongRenderer implements InlineRendererInterface { /** * @param Strong $inline diff --git a/vendor/league/commonmark/src/Inline/Renderer/TextRenderer.php b/vendor/league/commonmark/src/Inline/Renderer/TextRenderer.php index b009ee8e2c..fd7bb9bca7 100644 --- a/vendor/league/commonmark/src/Inline/Renderer/TextRenderer.php +++ b/vendor/league/commonmark/src/Inline/Renderer/TextRenderer.php @@ -19,7 +19,7 @@ use League\CommonMark\Inline\Element\AbstractInline; use League\CommonMark\Inline\Element\Text; use League\CommonMark\Util\Xml; -class TextRenderer implements InlineRendererInterface +final class TextRenderer implements InlineRendererInterface { /** * @param Text $inline diff --git a/vendor/league/commonmark/src/InlineParserContext.php b/vendor/league/commonmark/src/InlineParserContext.php index ef14a6dfda..d4e58f9ea9 100644 --- a/vendor/league/commonmark/src/InlineParserContext.php +++ b/vendor/league/commonmark/src/InlineParserContext.php @@ -17,7 +17,7 @@ namespace League\CommonMark; use League\CommonMark\Block\Element\AbstractBlock; use League\CommonMark\Block\Element\AbstractStringContainerBlock; use League\CommonMark\Delimiter\DelimiterStack; -use League\CommonMark\Reference\ReferenceMap; +use League\CommonMark\Reference\ReferenceMapInterface; class InlineParserContext { @@ -26,7 +26,7 @@ class InlineParserContext private $cursor; private $delimiterStack; - public function __construct(AbstractStringContainerBlock $container, ReferenceMap $referenceMap) + public function __construct(AbstractStringContainerBlock $container, ReferenceMapInterface $referenceMap) { $this->referenceMap = $referenceMap; $this->container = $container; @@ -43,9 +43,9 @@ class InlineParserContext } /** - * @return ReferenceMap + * @return ReferenceMapInterface */ - public function getReferenceMap(): ReferenceMap + public function getReferenceMap(): ReferenceMapInterface { return $this->referenceMap; } diff --git a/vendor/league/commonmark/src/InlineParserEngine.php b/vendor/league/commonmark/src/InlineParserEngine.php index e92e158076..29de8e23d8 100644 --- a/vendor/league/commonmark/src/InlineParserEngine.php +++ b/vendor/league/commonmark/src/InlineParserEngine.php @@ -14,12 +14,19 @@ namespace League\CommonMark; -use League\CommonMark\Inline\AdjoiningTextCollapser; +use League\CommonMark\Block\Element\AbstractStringContainerBlock; +use League\CommonMark\Delimiter\Delimiter; +use League\CommonMark\Delimiter\Processor\DelimiterProcessorInterface; +use League\CommonMark\Inline\AdjacentTextMerger; use League\CommonMark\Inline\Element\Text; use League\CommonMark\Node\Node; -use League\CommonMark\Reference\ReferenceMap; +use League\CommonMark\Reference\ReferenceMapInterface; +use League\CommonMark\Util\RegexHelper; -class InlineParserEngine +/** + * @internal + */ +final class InlineParserEngine { protected $environment; @@ -29,10 +36,10 @@ class InlineParserEngine } /** - * @param Node $container - * @param ReferenceMap $referenceMap + * @param AbstractStringContainerBlock $container + * @param ReferenceMapInterface $referenceMap */ - public function parse(Node $container, ReferenceMap $referenceMap) + public function parse(AbstractStringContainerBlock $container, ReferenceMapInterface $referenceMap) { $inlineParserContext = new InlineParserContext($container, $referenceMap); while (($character = $inlineParserContext->getCursor()->getCharacter()) !== null) { @@ -43,7 +50,7 @@ class InlineParserEngine $this->processInlines($inlineParserContext); - AdjoiningTextCollapser::collapseTextNodes($container); + AdjacentTextMerger::mergeChildNodes($container); } /** @@ -52,7 +59,7 @@ class InlineParserEngine * * @return bool Whether we successfully parsed a character at that position */ - protected function parseCharacter(string $character, InlineParserContext $inlineParserContext): bool + private function parseCharacter(string $character, InlineParserContext $inlineParserContext): bool { foreach ($this->environment->getInlineParsersForCharacter($character) as $parser) { if ($parser->parse($inlineParserContext)) { @@ -60,19 +67,60 @@ class InlineParserEngine } } + if ($delimiterProcessor = $this->environment->getDelimiterProcessors()->getDelimiterProcessor($character)) { + return $this->parseDelimiters($delimiterProcessor, $inlineParserContext); + } + return false; } + private function parseDelimiters(DelimiterProcessorInterface $delimiterProcessor, InlineParserContext $inlineContext): bool + { + $character = $inlineContext->getCursor()->getCharacter(); + $numDelims = 0; + + $cursor = $inlineContext->getCursor(); + $charBefore = $cursor->peek(-1); + if ($charBefore === null) { + $charBefore = "\n"; + } + + while ($cursor->peek($numDelims) === $character) { + ++$numDelims; + } + + if ($numDelims < $delimiterProcessor->getMinLength()) { + return false; + } + + $cursor->advanceBy($numDelims); + + $charAfter = $cursor->getCharacter(); + if ($charAfter === null) { + $charAfter = "\n"; + } + + list($canOpen, $canClose) = self::determineCanOpenOrClose($charBefore, $charAfter, $character, $delimiterProcessor); + + $node = new Text($cursor->getPreviousText(), [ + 'delim' => true, + ]); + $inlineContext->getContainer()->appendChild($node); + + // Add entry to stack to this opener + $delimiter = new Delimiter($character, $numDelims, $node, $canOpen, $canClose); + $inlineContext->getDelimiterStack()->push($delimiter); + + return true; + } + /** * @param InlineParserContext $inlineParserContext */ - protected function processInlines(InlineParserContext $inlineParserContext) + private function processInlines(InlineParserContext $inlineParserContext) { $delimiterStack = $inlineParserContext->getDelimiterStack(); - - foreach ($this->environment->getInlineProcessors() as $inlineProcessor) { - $inlineProcessor->processInlines($delimiterStack); - } + $delimiterStack->processDelimiters(null, $this->environment->getDelimiterProcessors()); // Remove all delimiters $delimiterStack->removeAll(); @@ -101,4 +149,33 @@ class InlineParserEngine $container->appendChild(new Text($text)); } } + + /** + * @param string $charBefore + * @param string $charAfter + * @param string $character + * @param DelimiterProcessorInterface $delimiterProcessor + * + * @return bool[] + */ + private static function determineCanOpenOrClose(string $charBefore, string $charAfter, string $character, DelimiterProcessorInterface $delimiterProcessor) + { + $afterIsWhitespace = \preg_match(RegexHelper::REGEX_UNICODE_WHITESPACE_CHAR, $charAfter); + $afterIsPunctuation = \preg_match(RegexHelper::REGEX_PUNCTUATION, $charAfter); + $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); + + if ($character === '_') { + $canOpen = $leftFlanking && (!$rightFlanking || $beforeIsPunctuation); + $canClose = $rightFlanking && (!$leftFlanking || $afterIsPunctuation); + } else { + $canOpen = $leftFlanking && $character === $delimiterProcessor->getOpeningCharacter(); + $canClose = $rightFlanking && $character === $delimiterProcessor->getClosingCharacter(); + } + + return [$canOpen, $canClose]; + } } diff --git a/vendor/league/commonmark/src/Node/Node.php b/vendor/league/commonmark/src/Node/Node.php index 17f373ccca..46df3a6540 100644 --- a/vendor/league/commonmark/src/Node/Node.php +++ b/vendor/league/commonmark/src/Node/Node.php @@ -1,5 +1,17 @@ <?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\Node; abstract class Node @@ -85,7 +97,7 @@ abstract class Node $this->next = $sibling; $sibling->setParent($this->parent); - if (!$sibling->next) { + if (!$sibling->next && $sibling->parent) { $sibling->parent->lastChild = $sibling; } } @@ -108,7 +120,7 @@ abstract class Node $this->previous = $sibling; $sibling->setParent($this->parent); - if (!$sibling->previous) { + if (!$sibling->previous && $sibling->parent) { $sibling->parent->firstChild = $sibling; } } diff --git a/vendor/league/commonmark/src/Node/NodeWalker.php b/vendor/league/commonmark/src/Node/NodeWalker.php index 0d5e2b1872..6be7193b94 100644 --- a/vendor/league/commonmark/src/Node/NodeWalker.php +++ b/vendor/league/commonmark/src/Node/NodeWalker.php @@ -1,8 +1,20 @@ <?php +/* + * This file is part of the league/commonmark package. + * + * (c) Colin O'Dell <colinodell@gmail.com> + * + * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) + * - (c) John MacFarlane + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace League\CommonMark\Node; -class NodeWalker +final class NodeWalker { /** * @var Node diff --git a/vendor/league/commonmark/src/Node/NodeWalkerEvent.php b/vendor/league/commonmark/src/Node/NodeWalkerEvent.php index aee2c86b82..541f61ad84 100644 --- a/vendor/league/commonmark/src/Node/NodeWalkerEvent.php +++ b/vendor/league/commonmark/src/Node/NodeWalkerEvent.php @@ -1,5 +1,17 @@ <?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\Node; final class NodeWalkerEvent @@ -18,7 +30,7 @@ final class NodeWalkerEvent * @param Node $node * @param bool $isEntering */ - public function __construct(Node $node = null, $isEntering = true) + public function __construct(Node $node, $isEntering = true) { $this->node = $node; $this->isEntering = $isEntering; diff --git a/vendor/league/commonmark/src/Reference/Reference.php b/vendor/league/commonmark/src/Reference/Reference.php index 819a80a56a..f734ce4854 100644 --- a/vendor/league/commonmark/src/Reference/Reference.php +++ b/vendor/league/commonmark/src/Reference/Reference.php @@ -14,10 +14,7 @@ namespace League\CommonMark\Reference; -/** - * Link reference - */ -class Reference +final class Reference implements ReferenceInterface { /** * @var string @@ -35,6 +32,16 @@ class Reference protected $title; /** + * @var array + * + * 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'], + ]; + + /** * Constructor * * @param string $label @@ -49,7 +56,7 @@ class Reference } /** - * @return string + * {@inheritdoc} */ public function getLabel(): string { @@ -57,7 +64,7 @@ class Reference } /** - * @return string + * {@inheritdoc} */ public function getDestination(): string { @@ -65,7 +72,7 @@ class Reference } /** - * @return string + * {@inheritdoc} */ public function getTitle(): string { @@ -85,8 +92,15 @@ 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)); + + 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_strtoupper($string, 'UTF-8'); + return \mb_convert_case($string, \MB_CASE_FOLD, 'UTF-8'); } } diff --git a/vendor/league/commonmark/src/Inline/Element/AbstractInlineContainer.php b/vendor/league/commonmark/src/Reference/ReferenceInterface.php index a80bd8981e..351c6f6746 100644 --- a/vendor/league/commonmark/src/Inline/Element/AbstractInlineContainer.php +++ b/vendor/league/commonmark/src/Reference/ReferenceInterface.php @@ -12,15 +12,25 @@ * file that was distributed with this source code. */ -namespace League\CommonMark\Inline\Element; +namespace League\CommonMark\Reference; -abstract class AbstractInlineContainer extends AbstractInline +/** + * Link reference + */ +interface ReferenceInterface { /** - * @return bool + * @return string + */ + public function getLabel(): string; + + /** + * @return string + */ + public function getDestination(): string; + + /** + * @return string */ - public function isContainer(): bool - { - return true; - } + public function getTitle(): string; } diff --git a/vendor/league/commonmark/src/Reference/ReferenceMap.php b/vendor/league/commonmark/src/Reference/ReferenceMap.php index 97f878f9fe..1af59d74e1 100644 --- a/vendor/league/commonmark/src/Reference/ReferenceMap.php +++ b/vendor/league/commonmark/src/Reference/ReferenceMap.php @@ -17,30 +17,24 @@ namespace League\CommonMark\Reference; /** * A collection of references, indexed by label */ -class ReferenceMap +final class ReferenceMap implements ReferenceMapInterface { /** - * @var Reference[] + * @var ReferenceInterface[] */ protected $references = []; /** - * @param Reference $reference - * - * @return $this + * {@inheritdoc} */ - public function addReference(Reference $reference) + public function addReference(ReferenceInterface $reference): void { $key = Reference::normalizeReference($reference->getLabel()); $this->references[$key] = $reference; - - return $this; } /** - * @param string $label - * - * @return bool + * {@inheritdoc} */ public function contains(string $label): bool { @@ -50,11 +44,9 @@ class ReferenceMap } /** - * @param string $label - * - * @return Reference|null + * {@inheritdoc} */ - public function getReference(string $label): ?Reference + public function getReference(string $label): ?ReferenceInterface { $label = Reference::normalizeReference($label); @@ -66,9 +58,7 @@ class ReferenceMap } /** - * Lists all registered references. - * - * @return Reference[] + * {@inheritdoc} */ public function listReferences(): iterable { diff --git a/vendor/league/commonmark/src/Reference/ReferenceMapInterface.php b/vendor/league/commonmark/src/Reference/ReferenceMapInterface.php new file mode 100644 index 0000000000..69b6d5c89e --- /dev/null +++ b/vendor/league/commonmark/src/Reference/ReferenceMapInterface.php @@ -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; +} diff --git a/vendor/league/commonmark/src/ReferenceParser.php b/vendor/league/commonmark/src/Reference/ReferenceParser.php index 5c0bc8a0dd..c9bea6b571 100644 --- a/vendor/league/commonmark/src/ReferenceParser.php +++ b/vendor/league/commonmark/src/Reference/ReferenceParser.php @@ -12,20 +12,19 @@ * file that was distributed with this source code. */ -namespace League\CommonMark; +namespace League\CommonMark\Reference; -use League\CommonMark\Reference\Reference; -use League\CommonMark\Reference\ReferenceMap; +use League\CommonMark\Cursor; use League\CommonMark\Util\LinkParserHelper; -class ReferenceParser +final class ReferenceParser { /** - * @var ReferenceMap + * @var ReferenceMapInterface */ - protected $referenceMap; + private $referenceMap; - public function __construct(ReferenceMap $referenceMap) + public function __construct(ReferenceMapInterface $referenceMap) { $this->referenceMap = $referenceMap; } diff --git a/vendor/league/commonmark/src/UnmatchedBlockCloser.php b/vendor/league/commonmark/src/UnmatchedBlockCloser.php index eab47cda2c..d495c9bba3 100644 --- a/vendor/league/commonmark/src/UnmatchedBlockCloser.php +++ b/vendor/league/commonmark/src/UnmatchedBlockCloser.php @@ -16,6 +16,9 @@ namespace League\CommonMark; use League\CommonMark\Block\Element\AbstractBlock; +/** + * @internal + */ class UnmatchedBlockCloser { /** @@ -65,6 +68,10 @@ class UnmatchedBlockCloser public function resetTip() { + if ($this->context->getTip() === null) { + throw new \RuntimeException('No tip to reset to'); + } + $this->oldTip = $this->context->getTip(); } diff --git a/vendor/league/commonmark/src/Util/ArrayCollection.php b/vendor/league/commonmark/src/Util/ArrayCollection.php index 3b96eaa50e..cb71911ff2 100644 --- a/vendor/league/commonmark/src/Util/ArrayCollection.php +++ b/vendor/league/commonmark/src/Util/ArrayCollection.php @@ -15,6 +15,8 @@ namespace League\CommonMark\Util; * Array collection * * Provides a wrapper around a standard PHP array. + * + * @internal */ class ArrayCollection implements \IteratorAggregate, \Countable, \ArrayAccess { diff --git a/vendor/league/commonmark/src/Util/Configuration.php b/vendor/league/commonmark/src/Util/Configuration.php index 26f676b091..f97c86cb66 100644 --- a/vendor/league/commonmark/src/Util/Configuration.php +++ b/vendor/league/commonmark/src/Util/Configuration.php @@ -14,9 +14,9 @@ namespace League\CommonMark\Util; -class Configuration +final class Configuration implements ConfigurationInterface { - protected $config; + private $config; /** * @param array $config @@ -27,28 +27,25 @@ class Configuration } /** - * @param array $config + * {@inheritdoc} */ - public function mergeConfig(array $config = []) + public function merge(array $config = []) { $this->config = \array_replace_recursive($this->config, $config); } /** - * @param array $config + * {@inheritdoc} */ - public function setConfig(array $config = []) + public function replace(array $config = []) { $this->config = $config; } /** - * @param string|null $key - * @param mixed $default - * - * @return mixed + * {@inheritdoc} */ - public function getConfig(?string $key = null, $default = null) + public function get(?string $key = null, $default = null) { if ($key === null) { return $this->config; @@ -67,12 +64,25 @@ class Configuration } /** + * {@inheritdoc} + */ + public function set(string $key, $value = null) + { + // accept a/b/c as ['a']['b']['c'] + if (\strpos($key, '/')) { + $this->setByPath($key, $value); + } + + $this->config[$key] = $value; + } + + /** * @param string $keyPath * @param string|null $default * - * @return mixed + * @return mixed|null */ - protected function getConfigByPath(string $keyPath, $default = null) + private function getConfigByPath(string $keyPath, $default = null) { $keyArr = \explode('/', $keyPath); $data = $this->config; @@ -86,4 +96,27 @@ class Configuration return $data; } + + /** + * @param string $keyPath + * @param string|null $value + */ + private function setByPath(string $keyPath, $value = null) + { + $keyArr = \explode('/', $keyPath); + $pointer = &$this->config; + while (($k = array_shift($keyArr)) !== null) { + if (!\is_array($pointer)) { + $pointer = []; + } + + if (!isset($pointer[$k])) { + $pointer[$k] = null; + } + + $pointer = &$pointer[$k]; + } + + $pointer = $value; + } } diff --git a/vendor/league/commonmark/src/Util/ConfigurationAwareInterface.php b/vendor/league/commonmark/src/Util/ConfigurationAwareInterface.php index a51fdaba9c..0f1d444d01 100644 --- a/vendor/league/commonmark/src/Util/ConfigurationAwareInterface.php +++ b/vendor/league/commonmark/src/Util/ConfigurationAwareInterface.php @@ -1,5 +1,14 @@ <?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\Util; /** @@ -8,7 +17,7 @@ namespace League\CommonMark\Util; interface ConfigurationAwareInterface { /** - * @param Configuration $configuration + * @param ConfigurationInterface $configuration */ - public function setConfiguration(Configuration $configuration); + public function setConfiguration(ConfigurationInterface $configuration); } diff --git a/vendor/league/commonmark/src/Util/ConfigurationInterface.php b/vendor/league/commonmark/src/Util/ConfigurationInterface.php new file mode 100644 index 0000000000..8e07a083d5 --- /dev/null +++ b/vendor/league/commonmark/src/Util/ConfigurationInterface.php @@ -0,0 +1,51 @@ +<?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\Util; + +interface ConfigurationInterface +{ + /** + * Merge an existing array into the current configuration + * + * @param array $config + */ + public function merge(array $config = []); + + /** + * Replace the entire array with something else + * + * @param array $config + */ + public function replace(array $config = []); + + /** + * Return the configuration value at the given key, or $default if no such config exists + * + * The key can be a string or a slash-delimited path to a nested value + * + * @param string|null $key + * @param mixed|null $default + * + * @return mixed|null + */ + public function get(?string $key = null, $default = null); + + /** + * Set the configuration value at the given key + * + * The key can be a string or a slash-delimited path to a nested value + * + * @param string $key + * @param mixed|null $value + */ + public function set(string $key, $value = null); +} diff --git a/vendor/league/commonmark/src/Util/PrioritizedList.php b/vendor/league/commonmark/src/Util/PrioritizedList.php index 83be39dc01..dea69e90c4 100644 --- a/vendor/league/commonmark/src/Util/PrioritizedList.php +++ b/vendor/league/commonmark/src/Util/PrioritizedList.php @@ -14,6 +14,9 @@ namespace League\CommonMark\Util; +/** + * @internal + */ final class PrioritizedList implements \IteratorAggregate { private $list = []; diff --git a/vendor/league/commonmark/src/Util/RegexHelper.php b/vendor/league/commonmark/src/Util/RegexHelper.php index a4703bd075..01ef1195b4 100644 --- a/vendor/league/commonmark/src/Util/RegexHelper.php +++ b/vendor/league/commonmark/src/Util/RegexHelper.php @@ -21,87 +21,6 @@ use League\CommonMark\Block\Element\HtmlBlock; */ 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; - // Partial regular expressions (wrap with `/` on each side before use) const PARTIAL_ENTITY = '&(?:#x[a-f0-9]{1,6}|#[0-9]{1,7}|[a-z][a-z0-9]{1,31});'; const PARTIAL_ESCAPABLE = '[!"#$%&\'()*+,.\/:;<=>?@[\\\\\]^_`{|}~-]'; @@ -136,12 +55,6 @@ final class RegexHelper '|' . '\'(' . 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'; @@ -239,9 +152,11 @@ final class RegexHelper /** * @param int $type HTML block type * - * @return string|null + * @return string + * + * @internal */ - public static function getHtmlBlockOpenRegex(int $type): ?string + public static function getHtmlBlockOpenRegex(int $type): string { switch ($type) { case HtmlBlock::TYPE_1_CODE_CONTAINER: @@ -260,15 +175,17 @@ final class RegexHelper return '/^(?:' . self::PARTIAL_OPENTAG . '|' . self::PARTIAL_CLOSETAG . ')\\s*$/i'; } - return null; + throw new \InvalidArgumentException('Invalid HTML block type'); } /** * @param int $type HTML block type * - * @return string|null + * @return string + * + * @internal */ - public static function getHtmlBlockCloseRegex(int $type): ?string + public static function getHtmlBlockCloseRegex(int $type): string { switch ($type) { case HtmlBlock::TYPE_1_CODE_CONTAINER: @@ -283,7 +200,7 @@ final class RegexHelper return '/\]\]>/'; } - return null; + throw new \InvalidArgumentException('Invalid HTML block type'); } /** |
