diff --git a/src/Components/BacktrackingInline.php b/src/Components/BacktrackingInline.php new file mode 100644 index 0000000..6be142d --- /dev/null +++ b/src/Components/BacktrackingInline.php @@ -0,0 +1,16 @@ +?@[\]^_`{|}~'; diff --git a/src/Components/Inlines/HardBreak.php b/src/Components/Inlines/HardBreak.php index a652e33..232feab 100644 --- a/src/Components/Inlines/HardBreak.php +++ b/src/Components/Inlines/HardBreak.php @@ -3,13 +3,14 @@ namespace Erusev\Parsedown\Components\Inlines; use Erusev\Parsedown\AST\StateRenderable; +use Erusev\Parsedown\Components\BacktrackingInline; use Erusev\Parsedown\Components\Inline; use Erusev\Parsedown\Html\Renderables\Element; use Erusev\Parsedown\Html\Renderables\Text; use Erusev\Parsedown\Parsing\Excerpt; use Erusev\Parsedown\State; -final class HardBreak implements Inline +final class HardBreak implements BacktrackingInline { use WidthTrait; diff --git a/src/Components/Inlines/Image.php b/src/Components/Inlines/Image.php index c629915..1f1d7eb 100644 --- a/src/Components/Inlines/Image.php +++ b/src/Components/Inlines/Image.php @@ -16,7 +16,7 @@ use Erusev\Parsedown\State; /** @psalm-type _Metadata=array{href: string, title?: string} */ final class Image implements Inline { - use WidthTrait, DefaultBeginPosition; + use WidthTrait; /** @var Link */ private $Link; diff --git a/src/Components/Inlines/Link.php b/src/Components/Inlines/Link.php index 368116c..e6a4c99 100644 --- a/src/Components/Inlines/Link.php +++ b/src/Components/Inlines/Link.php @@ -18,7 +18,7 @@ use Erusev\Parsedown\State; /** @psalm-type _Metadata=array{href: string, title?: string} */ final class Link implements Inline { - use WidthTrait, DefaultBeginPosition; + use WidthTrait; /** @var string */ private $label; diff --git a/src/Components/Inlines/Markup.php b/src/Components/Inlines/Markup.php index d2dd8bd..27c8704 100644 --- a/src/Components/Inlines/Markup.php +++ b/src/Components/Inlines/Markup.php @@ -13,7 +13,7 @@ use Erusev\Parsedown\State; final class Markup implements Inline { - use WidthTrait, DefaultBeginPosition; + use WidthTrait; const HTML_ATT_REGEX = '[a-zA-Z_:][\w:.-]*+(?:\s*+=\s*+(?:[^"\'=<>`\s]+|"[^"]*+"|\'[^\']*+\'))?+'; diff --git a/src/Components/Inlines/PlainText.php b/src/Components/Inlines/PlainText.php index 7a766b3..51ab482 100644 --- a/src/Components/Inlines/PlainText.php +++ b/src/Components/Inlines/PlainText.php @@ -10,7 +10,7 @@ use Erusev\Parsedown\State; final class PlainText implements Inline { - use WidthTrait, DefaultBeginPosition; + use WidthTrait; /** @var string */ private $text; diff --git a/src/Components/Inlines/SoftBreak.php b/src/Components/Inlines/SoftBreak.php index ccacd45..cdd34ef 100644 --- a/src/Components/Inlines/SoftBreak.php +++ b/src/Components/Inlines/SoftBreak.php @@ -4,6 +4,7 @@ namespace Erusev\Parsedown\Components\Inlines; use Erusev\Parsedown\AST\Handler; use Erusev\Parsedown\AST\StateRenderable; +use Erusev\Parsedown\Components\BacktrackingInline; use Erusev\Parsedown\Components\Inline; use Erusev\Parsedown\Configurables\Breaks; use Erusev\Parsedown\Html\Renderables\Container; @@ -12,7 +13,7 @@ use Erusev\Parsedown\Html\Renderables\Text; use Erusev\Parsedown\Parsing\Excerpt; use Erusev\Parsedown\State; -final class SoftBreak implements Inline +final class SoftBreak implements BacktrackingInline { use WidthTrait; diff --git a/src/Components/Inlines/SpecialCharacter.php b/src/Components/Inlines/SpecialCharacter.php index 7d7202f..605a697 100644 --- a/src/Components/Inlines/SpecialCharacter.php +++ b/src/Components/Inlines/SpecialCharacter.php @@ -11,7 +11,7 @@ use Erusev\Parsedown\State; final class SpecialCharacter implements Inline { - use WidthTrait, DefaultBeginPosition; + use WidthTrait; /** @var string */ private $charCodeHtml; diff --git a/src/Components/Inlines/Strikethrough.php b/src/Components/Inlines/Strikethrough.php index 3ddff03..984b878 100644 --- a/src/Components/Inlines/Strikethrough.php +++ b/src/Components/Inlines/Strikethrough.php @@ -13,7 +13,7 @@ use Erusev\Parsedown\State; final class Strikethrough implements Inline { - use WidthTrait, DefaultBeginPosition; + use WidthTrait; /** @var string */ private $text; diff --git a/src/Components/Inlines/Url.php b/src/Components/Inlines/Url.php index 0e630ff..666a117 100644 --- a/src/Components/Inlines/Url.php +++ b/src/Components/Inlines/Url.php @@ -3,13 +3,14 @@ namespace Erusev\Parsedown\Components\Inlines; use Erusev\Parsedown\AST\StateRenderable; +use Erusev\Parsedown\Components\BacktrackingInline; use Erusev\Parsedown\Components\Inline; use Erusev\Parsedown\Html\Renderables\Element; use Erusev\Parsedown\Html\Renderables\Text; use Erusev\Parsedown\Parsing\Excerpt; use Erusev\Parsedown\State; -final class Url implements Inline +final class Url implements BacktrackingInline { use WidthTrait; diff --git a/src/Components/Inlines/UrlTag.php b/src/Components/Inlines/UrlTag.php index 4994f4a..1a072fc 100644 --- a/src/Components/Inlines/UrlTag.php +++ b/src/Components/Inlines/UrlTag.php @@ -11,7 +11,7 @@ use Erusev\Parsedown\State; final class UrlTag implements Inline { - use WidthTrait, DefaultBeginPosition; + use WidthTrait; /** @var string */ private $url; diff --git a/src/Parsedown.php b/src/Parsedown.php index 59cc02c..8454edc 100644 --- a/src/Parsedown.php +++ b/src/Parsedown.php @@ -4,6 +4,7 @@ namespace Erusev\Parsedown; use Erusev\Parsedown\AST\StateRenderable; use Erusev\Parsedown\Components\AcquisitioningBlock; +use Erusev\Parsedown\Components\BacktrackingInline; use Erusev\Parsedown\Components\Block; use Erusev\Parsedown\Components\Blocks\Paragraph; use Erusev\Parsedown\Components\ContinuableBlock; @@ -202,7 +203,13 @@ final class Parsedown } $markerPosition = $Excerpt->offset(); - $startPosition = $Inline->modifyStartPositionTo(); + + /** @var int|null */ + $startPosition = null; + + if ($Inline instanceof BacktrackingInline) { + $startPosition = $Inline->modifyStartPositionTo(); + } if (! isset($startPosition)) { $startPosition = $markerPosition;