2.0.0-beta1
Pre-release
Pre-release
See https://commonmark.thephpleague.com/2.0/upgrading/ for detailed information on upgrading to version 2.0.
Added
- Added three new extensions:
FrontMatterExtension(see documentation)DescriptionListExtension(see documentation)DefaultAttributesExtension(see documentation)
- Added new
XmlRendererto simplify AST debugging (see documentation) (#431) - Added the ability to configure disallowed raw HTML tags (#507)
- Added the ability for Mentions to use multiple characters for their symbol (#514, #550)
- Added the ability to delegate event dispatching to PSR-14 compliant event dispatcher libraries
- Added new configuration options:
- Added
heading_permalink/min_heading_levelandheading_permalink/max_heading_leveloptions to control which headings get permalinks (#519) - Added
heading_permalink/fragment_prefixto allow customizing the URL fragment prefix (#602) - Added
footnote/backref_symboloption for customizing backreference link appearance (#522) - Added
slug_normalizer/max_lengthoption to control the maximum length of generated URL slugs - Added
slug_normalizer/uniqueoption to control whether unique slugs should be generated per-document or per-environment
- Added
- Added purity markers throughout the codebase (verified with Psalm)
- Added
Queryclass to simplify Node traversal when looking to take action on certain Nodes - Added new
HtmlFilterandStringContainerHelperutility classes - Added new
AbstractBlockContinueParserclass to simplify the creation of custom block parsers - Added several new classes and interfaces:
BlockContinueBlockContinueParserInterfaceBlockContinueParserWithInlinesInterfaceBlockStartBlockStartParserInterfaceChildNodeRendererInterfaceConfigurableExtensionInterfaceCursorStateDashParser(extracted fromPunctuationParser)DelimiterParserDocumentBlockParserDocumentPreRenderEventDocumentRenderedEventEllipsesParser(extracted fromPunctuationParser)ExpressionInterfaceFallbackNodeXmlRendererInlineParserEngineInterfaceInlineParserMatchMarkdownParserStateMarkdownParserStateInterfaceMarkdownRendererInterfaceQueryRawMarkupContainerInterfaceReferenceableInterfaceRenderedContentRenderedContentInterfaceReplaceUnpairedQuotesListenerSpecReaderTableOfContentsRendererUniqueSlugNormalizerUniqueSlugNormalizerInterfaceXmlRendererXmlNodeRendererInterface
- Added several new methods:
Cursor::getCurrentCharacter()Environment::createDefaultConfiguration()Environment::setEventDispatcher()EnvironmentInterface::getExtensions()EnvironmentInterface::getInlineParsers()EnvironmentInterface::getSlugNormalizer()FencedCode::setInfo()Heading::setLevel()HtmlRenderer::renderDocument()InlineParserContext::getFullMatch()InlineParserContext::getFullMatchLength()InlineParserContext::getMatches()InlineParserContext::getSubMatches()LinkParserHelper::parsePartialLinkLabel()LinkParserHelper::parsePartialLinkTitle()Node::assertInstanceOf()RegexHelper::isLetter()StringContainerInterface::setLiteral()TableCell::getType()TableCell::setType()TableCell::getAlign()TableCell::setAlign()
Changed
- Changed the converter return type
CommonMarkConverter::convertToHtml()now returns an instance ofRenderedContentInterface. This can be cast to a string for backward compatibility with 1.x.
- Table of Contents items are no longer wrapped with
<p>tags (#613) - Heading Permalinks now link to element IDs instead of using
nameattributes (#602) - Heading Permalink IDs and URL fragments now have a
contentprefix by default (#602) - Changes to configuration options:
enable_emhas been renamed tocommonmark/enable_emenable_stronghas been renamed tocommonmark/enable_stronguse_asteriskhas been renamed tocommonmark/use_asteriskuse_underscorehas been renamed tocommonmark/use_underscoreunordered_list_markershas been renamed tocommonmark/unordered_list_markersmentions/*/symbolhas been renamed tomentions/*/prefixmentions/*/regexhas been renamed tomentions/*/patternand requires partial regular expressions (without delimiters or flags)max_nesting_levelnow defaults toPHP_INT_MAXand no longer supports floatsheading_permalink/slug_normalizerhas been renamed toslug_normalizer/instance
- Event dispatching is now fully PSR-14 compliant
- Moved and renamed several classes - see the full list here
- The
HeadingPermalinkExtensionandFootnoteExtensionwere modified to ensure they never produce a slug which conflicts with slugs created by the other extension SlugNormalizer::normalizer()now supports optional prefixes and max length options passed in via the$contextargument- The
AbstractBlock::$dataandAbstractInline::$dataarrays were replaced with aDataarray-like object on the baseNodeclass - Implemented a new approach to block parsing. This was a massive change, so here are the highlights:
- Functionality previously found in block parsers and node elements has moved to block parser factories and block parsers, respectively (more details)
ConfigurableEnvironmentInterface::addBlockParser()is nowEnvironmentBuilderInterface::addBlockParserFactory()ReferenceParserwas re-implemented and works completely different than before- The paragraph parser no longer needs to be added manually to the environment
- Implemented a new approach to inline parsing where parsers can now specify longer strings or regular expressions they want to parse (instead of just single characters):
InlineParserInterface::getCharacters()is nowgetMatchDefinition()and returns an instance ofInlineParserMatchInlineParserContext::__construct()now requires the contents to be provided as aCursorinstead of astring
- Implemented delimiter parsing as a special type of inline parser (via the new
DelimiterParserclass) - Changed block and inline rendering to use common methods and interfaces
BlockRendererInterfaceandInlineRendererInterfacewere replaced byNodeRendererInterfacewith slightly different parameters. All core renderers now implement this interface.ConfigurableEnvironmentInterface::addBlockRenderer()andaddInlineRenderer()were combined intoEnvironmentBuilderInterface::addRenderer()EnvironmentInterface::getBlockRenderersForClass()andgetInlineRenderersForClass()are now justgetRenderersForClass()
- Completely refactored the Configuration implementation
- All configuration-specific classes have been moved into a new
league/configpackage with a new namespace Configurationobjects must now be configured with a schema and all options must match that schema - arbitrary keys are no longer permittedConfiguration::__construct()no longer accepts the default configuration values - useConfiguration::merge()insteadConfigurationInterfacenow only contains aget(string $key); this method no longer allows arbitrary default values to be returned if the option is missingConfigurableEnvironmentInterfacewas renamed toEnvironmentBuilderInterfaceExtensionInterface::register()now requires anEnvironmentBuilderInterfaceparam instead ofConfigurableEnvironmentInterface
- All configuration-specific classes have been moved into a new
- Added missing return types to virtually every class and interface method
- Re-implemented the GFM Autolink extension using the new inline parser approach instead of document processors
EmailAutolinkProcessoris nowEmailAutolinkParserUrlAutolinkProcessoris nowUrlAutolinkParser
HtmlElementcan now properly handle array (i.e.class) and boolean (i.e.checked) attribute valuesHtmlElementautomatically flattens any attributes with array values into space-separated strings, removing duplicate entries- Combined separate classes/interfaces into one:
DisallowedRawHtmlRendererreplacesDisallowedRawHtmlBlockRendererandDisallowedRawHtmlInlineRendererNodeRendererInterfacereplacesBlockRendererInterfaceandInlineRendererInterface
- Renamed the following methods:
EnvironmentandConfigurableEnvironmentInterface:addBlockParser()is nowaddBlockStartParser()
ReferenceMapandReferenceMapInterface:addReference()is nowadd()getReference()is nowget()listReferences()is nowgetIterator()
- Various node (block/inline) classes:
getContent()is nowgetLiteral()setContent()is nowsetLiteral()
- Moved and renamed the following constants:
EnvironmentInterface::HTML_INPUT_ALLOWis nowHtmlFilter::ALLOWEnvironmentInterface::HTML_INPUT_ESCAPEis nowHtmlFilter::ESCAPEEnvironmentInterface::HTML_INPUT_STRIPis nowHtmlFilter::STRIPTableCell::TYPE_HEADis nowTableCell::TYPE_HEADERTableCell::TYPE_BODYis nowTableCell::TYPE_DATA
- Changed the visibility of the following properties:
AttributesInline::$attributesis nowprivateAttributesInline::$blockis nowprivateTableCell::$alignis nowprivateTableCell::$typeis nowprivateTableSection::$typeis nowprivate
- Several methods which previously returned
$thisnow returnvoidDelimiter::setPrevious()Node::replaceChildren()Context::setTip()Context::setContainer()Context::setBlocksParsed()AbstractStringContainer::setContent()AbstractWebResource::setUrl()
- Several classes are now marked
final:ArrayCollectionEmphasisFencedCodeHeadingHtmlBlockHtmlElementHtmlInlineIndentedCodeNewlineStrikethroughStrongText
Headingnodes no longer directly contain a copy of their inner textStringContainerInterfacecan now be used for inlines, not just blocksArrayCollectiononly supports integer keysHtmlElementnow implementsStringableCursor::saveState()andCursor::restoreState()now useCursorStateobjects instead of arraysNodeWalker::next()now enters, traverses any children, and leaves all elements which may have children (basically all blocks plus any inlines with children). Previously, it only did this for elements explicitly marked as "containers".InvalidOptionExceptionwas removed- Anything with a
getReference(): ReferenceInterfacemethod now implementsReferencableInterface - The
SmartPunctextension now replaces all unpairedQuoteelements withTextelements towards the end of parsing, making theQuoteRendererunnecessary - Several changes made to the Footnote extension:
- Footnote identifiers can no longer contain spaces
- Anonymous footnotes can now span subsequent lines
- Footnotes can now contain multiple lines of content, including sub-blocks, by indenting them
- Footnote event listeners now have numbered priorities (but still execute in the same order)
- Footnotes must now be separated from previous content by a blank line
- The line numbers (keys) returned via
MarkdownInput::getLines()now start at 1 instead of 0 DelimiterProcessorCollectionInterfacenow extendsCountableRegexHelper::PARTIAL_constants must always be used in case-insensitive contextsHeadingPermalinkProcessorno longer accepts text normalizers via the constructor - these must be provided via configuration instead- Blocks which can't contain inlines will no longer be asked to render inlines
AnonymousFootnoteRefParserandHeadingPermalinkProcessornow implementEnvironmentAwareInterfaceinstead ofConfigurationAwareInterface- The second argument to
TextNormalizerInterface::normalize()must now be an array - The
titleattribute forLinkandImagenodes is now stored using a dedicated property instead of stashing it in$data ListData::$delimiternow returns eitherListBlock::DELIM_PERIODorListBlock::DELIM_PARENinstead of the literal delimiter
Fixed
- Fixed parsing of footnotes without content
- Fixed rendering of orphaned footnotes and footnote refs
- Fixed some URL autolinks breaking too early (#492)
- Fixed
AbstractStringContainernot actually beingabstract
Removed
- Removed support for PHP 7.1, 7.2, and 7.3 (#625, #671)
- Removed all previously-deprecated functionality:
- Removed the ability to pass custom
Environmentinstances into theCommonMarkConverterandGithubFlavoredMarkdownConverterconstructors - Removed the
Converterclass andConverterInterface - Removed the
bin/commonmarkscript - Removed the
Html5Entitiesutility class - Removed the
InlineMentionParser(useMentionParserinstead) - Removed
DefaultSlugGeneratorandSlugGeneratorInterfacefrom theExtension/HeadingPermalink/Slugsub-namespace (use the new ones under./SlugGeneratorinstead) - Removed the following
ArrayCollectionmethods:add()set()get()remove()isEmpty()contains()indexOf()containsKey()replaceWith()removeGaps()
- Removed the
ConfigurableEnvironmentInterface::setConfig()method - Removed the
ListBlock::TYPE_UNORDEREDconstant - Removed the
CommonMarkConverter::VERSIONconstant - Removed the
HeadingPermalinkRenderer::DEFAULT_INNER_CONTENTSconstant - Removed the
heading_permalink/inner_contentsconfiguration option
- Removed the ability to pass custom
- Removed now-unused classes:
AbstractStringContainerBlockBlockRendererInterfaceContextContextInterfaceConverterConverterInterfaceInlineRendererInterfacePunctuationParser(was split into two classes:DashParserandEllipsesParser)QuoteRendererUnmatchedBlockCloser
- Removed the following methods, properties, and constants:
AbstractBlock::$openAbstractBlock::$lastLineBlankAbstractBlock::isContainer()AbstractBlock::canContain()AbstractBlock::isCode()AbstractBlock::matchesNextLine()AbstractBlock::endsWithBlankLine()AbstractBlock::setLastLineBlank()AbstractBlock::shouldLastLineBeBlank()AbstractBlock::isOpen()AbstractBlock::finalize()AbstractBlock::getData()AbstractInline::getData()ConfigurableEnvironmentInterface::addBlockParser()ConfigurableEnvironmentInterface::mergeConfig()Delimiter::setCanClose()EnvironmentInterface::getConfig()EnvironmentInterface::getInlineParsersForCharacter()EnvironmentInterface::getInlineParserCharacterRegex()HtmlRenderer::renderBlock()HtmlRenderer::renderBlocks()HtmlRenderer::renderInline()HtmlRenderer::renderInlines()Node::isContainer()RegexHelper::matchAll()(use the newmatchFirst()method instead)RegexHelper::REGEX_WHITESPACE
- Removed the second
$contentsargument from theHeadingconstructor
Deprecated
The following things have been deprecated and will not be supported in v3.0:
Environment::mergeConfig()(set configuration before instantiation instead)Environment::createCommonMarkEnvironment()andEnvironment::createGFMEnvironment()- Alternative 1: Use
CommonMarkConverterorGithubFlavoredMarkdownConverterif you don't need to customize the environment - Alternative 2: Instantiate a new
Environmentand add the necessary extensions yourself
- Alternative 1: Use