Skip to content

Commit f9686be

Browse files
committed
Fix admonition class handling
1 parent 793b1da commit f9686be

7 files changed

Lines changed: 23 additions & 10 deletions

File tree

packages/guides-restructured-text/src/RestructuredText/Compiler/Passes/DirectiveProcessPass.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323
use phpDocumentor\Guides\RestructuredText\Parser\Directive;
2424
use Psr\Log\LoggerInterface;
2525

26+
use function array_merge;
2627
use function strtolower;
2728

28-
use const PHP_INT_MAX;
29-
3029
/** @implements NodeTransformer<DirectiveNode> */
3130
final class DirectiveProcessPass implements ReverseNodeTransformer
3231
{
@@ -64,7 +63,7 @@ public function leaveNode(Node $node, CompilerContext $compilerContext): Node|nu
6463
return null;
6564
}
6665

67-
$newNode->setClasses($node->getClasses());
66+
$newNode->setClasses(array_merge($newNode->getClasses(), $node->getClasses()));
6867

6968
return $newNode;
7069
}

packages/guides-restructured-text/src/RestructuredText/Directives/AbstractAdmonitionDirective.php

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

1414
namespace phpDocumentor\Guides\RestructuredText\Directives;
1515

16-
use Doctrine\Deprecations\Deprecation;
1716
use phpDocumentor\Guides\Nodes\AdmonitionNode;
1817
use phpDocumentor\Guides\Nodes\CollectionNode;
1918
use phpDocumentor\Guides\Nodes\Node;
@@ -56,11 +55,15 @@ public function createNode(DirectiveNode $directiveNode): Node|null
5655
array_unshift($children, new ParagraphNode([$directiveNode->getDirective()->getDataNode()]));
5756
}
5857

59-
return new AdmonitionNode(
58+
$node = new AdmonitionNode(
6059
$directiveNode->getDirective()->getName(),
6160
null,
6261
$this->text,
6362
$children,
6463
);
64+
65+
$node->setClasses([$directiveNode->getDirective()->getOptionString('class')]);
66+
67+
return $node;
6568
}
6669
}

packages/guides-restructured-text/src/RestructuredText/Directives/AbstractVersionChangeDirective.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace phpDocumentor\Guides\RestructuredText\Directives;
1515

1616
use Doctrine\Deprecations\Deprecation;
17+
use LogicException;
1718
use phpDocumentor\Guides\Nodes\CollectionNode;
1819
use phpDocumentor\Guides\Nodes\Node;
1920
use phpDocumentor\Guides\RestructuredText\Nodes\DirectiveNode;
@@ -22,6 +23,8 @@
2223
use phpDocumentor\Guides\RestructuredText\Parser\Directive;
2324
use phpDocumentor\Guides\RestructuredText\Parser\Productions\Rule;
2425

26+
use function sprintf;
27+
2528
/** @see https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-versionadded */
2629
abstract class AbstractVersionChangeDirective extends SubDirective
2730
{
@@ -51,7 +54,7 @@ public function getName(): string
5154
{
5255
try {
5356
return parent::getName();
54-
} catch (\LogicException) {
57+
} catch (LogicException) {
5558
Deprecation::trigger(
5659
'phpdocumentor/guides-restructured-text',
5760
'TODO: link',

packages/guides-restructured-text/src/RestructuredText/Directives/BreadcrumbDirective.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
use phpDocumentor\Guides\Nodes\BreadCrumbNode;
1717
use phpDocumentor\Guides\Nodes\Node;
1818
use phpDocumentor\Guides\RestructuredText\Nodes\DirectiveNode;
19-
use phpDocumentor\Guides\RestructuredText\Parser\BlockContext;
20-
use phpDocumentor\Guides\RestructuredText\Parser\Directive;
2119

2220
/**
2321
* The "breadcrumb" directive displays a breadcrumb of the current. It does not exist in Sphinx or the

packages/guides-restructured-text/src/RestructuredText/Parser/Directive.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
use phpDocumentor\Guides\Nodes\InlineCompoundNode;
1717

18+
use function strtolower;
19+
1820
/**
1921
* Represents the data contained in an arbitrary directive
2022
*

packages/guides/src/Compiler/ReverseNodeTransformer.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
declare(strict_types=1);
44

5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link https://phpdoc.org
12+
*/
13+
514
namespace phpDocumentor\Guides\Compiler;
615

716
/**
@@ -11,5 +20,4 @@
1120
*/
1221
interface ReverseNodeTransformer extends NodeTransformer
1322
{
14-
1523
}

packages/guides/src/Nodes/AbstractNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function setClasses(array $classes): void
7777
// strip trailing hyphens
7878
$value = (string) preg_replace('/-$/', '', $value);
7979
});
80-
$this->classes = array_unique($classes);
80+
$this->classes = array_filter(array_unique($classes), static function (string $value): bool { return $value !== ''; });
8181
}
8282

8383
public function getClassesString(): string

0 commit comments

Comments
 (0)