Skip to content

Commit 97dfc49

Browse files
authored
Merge pull request #1163 from phpDocumentor/backport/1.x/pr-1162
[1.x] Merge pull request #1162 from phpDocumentor/nested-inline-nodes
2 parents 349e87b + ca78413 commit 97dfc49

35 files changed

+270
-67
lines changed

packages/guides-markdown/src/Markdown/Parsers/InlineParsers/AbstractInlineParser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
use League\CommonMark\Node\NodeWalker;
1818
use phpDocumentor\Guides\Markdown\ParserInterface;
1919
use phpDocumentor\Guides\MarkupLanguageParser;
20-
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
20+
use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
2121

2222
/**
23-
* @template TValue as InlineNode
23+
* @template TValue as InlineNodeInterface
2424
* @implements ParserInterface<TValue>
2525
*/
2626
abstract class AbstractInlineParser implements ParserInterface
2727
{
28-
abstract public function parse(MarkupLanguageParser $parser, NodeWalker $walker, CommonMarkNode $current): InlineNode;
28+
abstract public function parse(MarkupLanguageParser $parser, NodeWalker $walker, CommonMarkNode $current): InlineNodeInterface;
2929
}

packages/guides-markdown/src/Markdown/Parsers/InlineParsers/AbstractInlineTextDecoratorParser.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
use League\CommonMark\Node\NodeWalkerEvent;
1919
use phpDocumentor\Guides\MarkupLanguageParser;
2020
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
21+
use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
2122
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
2223
use Psr\Log\LoggerInterface;
2324
use RuntimeException;
2425

2526
use function count;
2627
use function sprintf;
27-
use function var_export;
2828

2929
/**
30-
* @template TValue as InlineNode
30+
* @template TValue as InlineNodeInterface
3131
* @extends AbstractInlineParser<TValue>
3232
*/
3333
abstract class AbstractInlineTextDecoratorParser extends AbstractInlineParser
@@ -40,7 +40,7 @@ public function __construct(
4040
}
4141

4242
/** @return TValue */
43-
public function parse(MarkupLanguageParser $parser, NodeWalker $walker, CommonMarkNode $current): InlineNode
43+
public function parse(MarkupLanguageParser $parser, NodeWalker $walker, CommonMarkNode $current): InlineNodeInterface
4444
{
4545
$content = [];
4646

@@ -66,12 +66,10 @@ public function parse(MarkupLanguageParser $parser, NodeWalker $walker, CommonMa
6666

6767
if ($this->supportsCommonMarkNode($commonMarkNode)) {
6868
if (count($content) === 1 && $content[0] instanceof PlainTextInlineNode) {
69-
return $this->createInlineNode($commonMarkNode, $content[0]->getValue());
69+
return $this->createInlineNode($commonMarkNode, $content[0]->getValue(), $content);
7070
}
7171

72-
$this->logger->warning(sprintf('%s CONTEXT: Content of emphasis could not be interpreted: %s', $this->getType(), var_export($content, true)));
73-
74-
return $this->createInlineNode($commonMarkNode, null);
72+
return $this->createInlineNode($commonMarkNode, null, $content);
7573
}
7674

7775
$this->logger->warning(sprintf('%s context does not allow a %s node', $this->getType(), $commonMarkNode::class));
@@ -83,7 +81,7 @@ public function parse(MarkupLanguageParser $parser, NodeWalker $walker, CommonMa
8381
abstract protected function getType(): string;
8482

8583
/** @return TValue */
86-
abstract protected function createInlineNode(CommonMarkNode $commonMarkNode, string|null $content): InlineNode;
84+
abstract protected function createInlineNode(CommonMarkNode $commonMarkNode, string|null $content): InlineNodeInterface;
8785

8886
abstract protected function supportsCommonMarkNode(CommonMarkNode $commonMarkNode): bool;
8987

packages/guides-markdown/src/Markdown/Parsers/InlineParsers/EmphasisParser.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use League\CommonMark\Node\Node as CommonMarkNode;
1818
use phpDocumentor\Guides\Nodes\Inline\EmphasisInlineNode;
1919
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
20+
use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
2021
use Psr\Log\LoggerInterface;
2122

2223
/** @extends AbstractInlineTextDecoratorParser<EmphasisInlineNode> */
@@ -35,9 +36,10 @@ protected function getType(): string
3536
return 'Emphasis';
3637
}
3738

38-
protected function createInlineNode(CommonMarkNode $commonMarkNode, string|null $content): InlineNode
39+
/** @param InlineNodeInterface[] $children */
40+
protected function createInlineNode(CommonMarkNode $commonMarkNode, string|null $content, array $children = []): InlineNodeInterface
3941
{
40-
return new EmphasisInlineNode($content ?? '');
42+
return new EmphasisInlineNode($content ?? '', $children);
4143
}
4244

4345
protected function supportsCommonMarkNode(CommonMarkNode $commonMarkNode): bool

packages/guides-markdown/src/Markdown/Parsers/InlineParsers/InlineCodeParser.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
use League\CommonMark\Node\NodeWalker;
1919
use League\CommonMark\Node\NodeWalkerEvent;
2020
use phpDocumentor\Guides\MarkupLanguageParser;
21+
use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
2122
use phpDocumentor\Guides\Nodes\Inline\LiteralInlineNode;
2223

2324
use function assert;
2425

2526
/** @extends AbstractInlineParser<LiteralInlineNode> */
2627
final class InlineCodeParser extends AbstractInlineParser
2728
{
28-
public function parse(MarkupLanguageParser $parser, NodeWalker $walker, CommonMarkNode $current): LiteralInlineNode
29+
public function parse(MarkupLanguageParser $parser, NodeWalker $walker, CommonMarkNode $current): InlineNodeInterface
2930
{
3031
assert($current instanceof Code);
3132

packages/guides-markdown/src/Markdown/Parsers/InlineParsers/InlineImageParser.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use League\CommonMark\Node\Node as CommonMarkNode;
1818
use phpDocumentor\Guides\Nodes\Inline\ImageInlineNode;
1919
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
20+
use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
2021
use Psr\Log\LoggerInterface;
2122

2223
use function assert;
@@ -38,7 +39,7 @@ protected function getType(): string
3839
return 'Image';
3940
}
4041

41-
protected function createInlineNode(CommonMarkNode $commonMarkNode, string|null $content): InlineNode
42+
protected function createInlineNode(CommonMarkNode $commonMarkNode, string|null $content): InlineNodeInterface
4243
{
4344
assert($commonMarkNode instanceof Image);
4445

packages/guides-markdown/src/Markdown/Parsers/InlineParsers/LinkParser.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use League\CommonMark\Node\Node as CommonMarkNode;
1818
use phpDocumentor\Guides\Nodes\Inline\HyperLinkNode;
1919
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
20+
use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
2021
use Psr\Log\LoggerInterface;
2122

2223
use function assert;
@@ -42,7 +43,8 @@ protected function getType(): string
4243
return 'Link';
4344
}
4445

45-
protected function createInlineNode(CommonMarkNode $commonMarkNode, string|null $content): InlineNode
46+
/** @param InlineNodeInterface[] $children */
47+
protected function createInlineNode(CommonMarkNode $commonMarkNode, string|null $content, array $children = []): InlineNodeInterface
4648
{
4749
assert($commonMarkNode instanceof Link);
4850

@@ -52,7 +54,7 @@ protected function createInlineNode(CommonMarkNode $commonMarkNode, string|null
5254
$url = substr($url, 0, -3);
5355
}
5456

55-
return new HyperLinkNode($content, $url);
57+
return new HyperLinkNode($content, $url, $children);
5658
}
5759

5860
protected function supportsCommonMarkNode(CommonMarkNode $commonMarkNode): bool

packages/guides-markdown/src/Markdown/Parsers/InlineParsers/NewLineParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use League\CommonMark\Node\NodeWalker;
1919
use League\CommonMark\Node\NodeWalkerEvent;
2020
use phpDocumentor\Guides\MarkupLanguageParser;
21-
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
21+
use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
2222
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
2323

2424
/** @extends AbstractInlineParser<PlainTextInlineNode> */
@@ -28,7 +28,7 @@ public function __construct()
2828
{
2929
}
3030

31-
public function parse(MarkupLanguageParser $parser, NodeWalker $walker, CommonMarkNode $current): InlineNode
31+
public function parse(MarkupLanguageParser $parser, NodeWalker $walker, CommonMarkNode $current): InlineNodeInterface
3232
{
3333
return new PlainTextInlineNode(' ');
3434
}

packages/guides-markdown/src/Markdown/Parsers/InlineParsers/StrongParser.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use League\CommonMark\Extension\CommonMark\Node\Inline\Strong;
1717
use League\CommonMark\Node\Node as CommonMarkNode;
1818
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
19+
use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
1920
use phpDocumentor\Guides\Nodes\Inline\StrongInlineNode;
2021
use Psr\Log\LoggerInterface;
2122

@@ -35,9 +36,10 @@ protected function getType(): string
3536
return 'StrongDecorator';
3637
}
3738

38-
protected function createInlineNode(CommonMarkNode $commonMarkNode, string|null $content): InlineNode
39+
/** @param InlineNodeInterface[] $children */
40+
protected function createInlineNode(CommonMarkNode $commonMarkNode, string|null $content, array $children = []): InlineNodeInterface
3941
{
40-
return new StrongInlineNode($content ?? '');
42+
return new StrongInlineNode($content ?? '', $children);
4143
}
4244

4345
protected function supportsCommonMarkNode(CommonMarkNode $commonMarkNode): bool

packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/DefaultTextRoleRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace phpDocumentor\Guides\RestructuredText\Parser\Productions\InlineRules;
1515

16-
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
16+
use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
1717
use phpDocumentor\Guides\RestructuredText\Parser\BlockContext;
1818
use phpDocumentor\Guides\RestructuredText\Parser\InlineLexer;
1919

@@ -27,7 +27,7 @@ public function applies(InlineLexer $lexer): bool
2727
return $lexer->token?->type === InlineLexer::BACKTICK;
2828
}
2929

30-
public function apply(BlockContext $blockContext, InlineLexer $lexer): InlineNode|null
30+
public function apply(BlockContext $blockContext, InlineLexer $lexer): InlineNodeInterface|null
3131
{
3232
$text = '';
3333

packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/EmphasisRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace phpDocumentor\Guides\RestructuredText\Parser\Productions\InlineRules;
1515

1616
use phpDocumentor\Guides\Nodes\Inline\EmphasisInlineNode;
17-
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
17+
use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
1818
use phpDocumentor\Guides\RestructuredText\Parser\BlockContext;
1919
use phpDocumentor\Guides\RestructuredText\Parser\InlineLexer;
2020

@@ -28,7 +28,7 @@ public function applies(InlineLexer $lexer): bool
2828
return $lexer->token?->type === InlineLexer::EMPHASIS_DELIMITER;
2929
}
3030

31-
public function apply(BlockContext $blockContext, InlineLexer $lexer): InlineNode|null
31+
public function apply(BlockContext $blockContext, InlineLexer $lexer): InlineNodeInterface|null
3232
{
3333
$text = '';
3434

0 commit comments

Comments
 (0)