Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) princi

## [Unreleased][unreleased]

### Changed
- Promoted the `delim` status on `Text` nodes to a first-class property (`$isDelimiter`) instead of storing it in the `$data` array (#963).
- This improves performance in the inline parser engine.
- **Breaking Change:** The `$isDelimiter` property on `Text` nodes is now public. The `isDelimiter()` and `setDelimiter()` methods have been removed. Accessing this status via `$text->data['delim']` is no longer supported. You must now access the public `$text->isDelimiter` property directly.

## [2.8.0] - 2025-11-26

### Added
Expand Down
5 changes: 2 additions & 3 deletions src/Delimiter/DelimiterParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ public function parse(InlineParserContext $inlineContext): bool
return true;
}

$node = new Text(\str_repeat($character, $numDelims), [
'delim' => true,
]);
$node = new Text(\str_repeat($character, $numDelims));
$node->isDelimiter = true;
$inlineContext->getContainer()->appendChild($node);

// Add entry to stack to this opener
Expand Down
3 changes: 2 additions & 1 deletion src/Extension/CommonMark/Parser/Inline/BangParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function parse(InlineParserContext $inlineContext): bool
$cursor = $inlineContext->getCursor();
$cursor->advanceBy(2);

$node = new Text('![', ['delim' => true]);
$node = new Text('![');
$node->isDelimiter = true;
$inlineContext->getContainer()->appendChild($node);

// Add entry to stack for this opener
Expand Down
3 changes: 2 additions & 1 deletion src/Extension/CommonMark/Parser/Inline/OpenBracketParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public function getMatchDefinition(): InlineParserMatch
public function parse(InlineParserContext $inlineContext): bool
{
$inlineContext->getCursor()->advanceBy(1);
$node = new Text('[', ['delim' => true]);
$node = new Text('[');
$node->isDelimiter = true;
$inlineContext->getContainer()->appendChild($node);

// Add entry to stack for this opener
Expand Down
2 changes: 1 addition & 1 deletion src/Extension/SmartPunct/QuoteParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function parse(InlineParserContext $inlineContext): bool
$canOpen = $leftFlanking && ! $rightFlanking;
$canClose = $rightFlanking;

$node = new Quote($char, ['delim' => true]);
$node = new Quote($char);
$inlineContext->getContainer()->appendChild($node);

// Add entry to stack to this opener
Expand Down
11 changes: 11 additions & 0 deletions src/Node/Inline/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@

final class Text extends AbstractStringContainer
{
public bool $isDelimiter = false;

/**
* @param string $contents The text contents
* @param array<string, mixed> $data Arbitrary data
*/
public function __construct(string $contents = '', array $data = [])
{
parent::__construct($contents, $data);
}

public function append(string $literal): void
{
$this->literal .= $literal;
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/InlineParserEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function parse(string $contents, AbstractBlock $block): void
private function addPlainText(string $text, AbstractBlock $container): void
{
$lastInline = $container->lastChild();
if ($lastInline instanceof Text && ! $lastInline->data->has('delim')) {
if ($lastInline instanceof Text && ! $lastInline->isDelimiter) {
$lastInline->append($text);
} else {
$container->appendChild(new Text($text));
Expand Down