diff --git a/composer.json b/composer.json index e8b4fd4..98314db 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "require": { "ext-json": "*", "ext-curl": "*", - "doctrine/rst-parser": "0.3.x-dev", + "doctrine/rst-parser": "0.4.x-dev", "scrivo/highlight.php": "^9.12.0", "symfony/filesystem": "^5.2", "symfony/finder": "^5.2", diff --git a/composer.lock b/composer.lock index 14cabce..5e1a162 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6d6c30105c41457eb65862b1a6684d01", + "content-hash": "2739ab0cffd3ad3caba1283d0b2e09e2", "packages": [ { "name": "doctrine/event-manager", @@ -102,16 +102,16 @@ }, { "name": "doctrine/rst-parser", - "version": "0.3.x-dev", + "version": "0.4.x-dev", "source": { "type": "git", "url": "https://github.com/doctrine/rst-parser.git", - "reference": "9f9887b282307c7cc8ff92a2c98aec39346696d9" + "reference": "e5e7cbe60957f30924d2b51e1ce284f3ddd0a868" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/rst-parser/zipball/9f9887b282307c7cc8ff92a2c98aec39346696d9", - "reference": "9f9887b282307c7cc8ff92a2c98aec39346696d9", + "url": "https://api.github.com/repos/doctrine/rst-parser/zipball/e5e7cbe60957f30924d2b51e1ce284f3ddd0a868", + "reference": "e5e7cbe60957f30924d2b51e1ce284f3ddd0a868", "shasum": "" }, "require": { @@ -128,9 +128,10 @@ "phpstan/phpstan-deprecation-rules": "^0.12", "phpstan/phpstan-phpunit": "^0.12", "phpstan/phpstan-strict-rules": "^0.12", - "phpunit/phpunit": "^7.5 || ^8.0 || ^9.0" + "phpunit/phpunit": "^7.5 || ^8.0 || ^9.0", + "symfony/css-selector": "4.4 || ^5.2", + "symfony/dom-crawler": "4.4 || ^5.2" }, - "default-branch": true, "type": "library", "autoload": { "psr-4": { @@ -165,9 +166,9 @@ ], "support": { "issues": "https://github.com/doctrine/rst-parser/issues", - "source": "https://github.com/doctrine/rst-parser/tree/0.3.1" + "source": "https://github.com/doctrine/rst-parser/tree/0.4.x" }, - "time": "2021-03-15T18:19:47+00:00" + "time": "2021-03-22T20:21:31+00:00" }, { "name": "psr/container", diff --git a/src/Directive/AbstractAdmonitionDirective.php b/src/Directive/AbstractAdmonitionDirective.php index d7eab1d..cdc366d 100644 --- a/src/Directive/AbstractAdmonitionDirective.php +++ b/src/Directive/AbstractAdmonitionDirective.php @@ -29,6 +29,10 @@ public function __construct(string $name, string $text) final public function processSub(Parser $parser, ?Node $document, string $variable, string $data, array $options): ?Node { + if (null === $document) { + throw new \RuntimeException('Content expected, none found.'); + } + $wrapperDiv = $parser->renderTemplate( 'directives/admonition.html.twig', [ diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 28b3b71..31fe408 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -103,8 +103,13 @@ public function testParseUnitBlock(string $blockName) $expectedCrawler = new Crawler($expectedHtml); $indenter = $this->createIndenter(); + $expected = trim($expectedCrawler->filter('body')->html()); + // you can add notes to a test file via + // we remove them here for comparing + $expected = preg_replace('/<\!\-\- REMOVE(.)+\-\->/', '', $expected); + $this->assertSame( - $indenter->indent(trim($expectedCrawler->filter('body')->html())), + $indenter->indent($expected), $indenter->indent(trim($actualCrawler->filter('body')->html())) ); } @@ -123,6 +128,10 @@ public function parserUnitBlockProvider() 'blockName' => 'nodes/list', ]; + yield 'figure' => [ + 'blockName' => 'nodes/figure', + ]; + yield 'caution' => [ 'blockName' => 'directives/caution', ]; diff --git a/tests/fixtures/expected/blocks/nodes/figure.html b/tests/fixtures/expected/blocks/nodes/figure.html new file mode 100644 index 0000000..32ccfbb --- /dev/null +++ b/tests/fixtures/expected/blocks/nodes/figure.html @@ -0,0 +1,22 @@ + + + + + + + +
+ + Symfony Logo +
+

I am a paragraph AFTER the figure. I should not be included as the +caption for the above figure.

+ +
+ + +

But I am a caption for the figure above.

+
+ + + diff --git a/tests/fixtures/expected/toctree/index.html b/tests/fixtures/expected/toctree/index.html index 0ff6fdc..68b4a2f 100644 --- a/tests/fixtures/expected/toctree/index.html +++ b/tests/fixtures/expected/toctree/index.html @@ -12,8 +12,8 @@

-
-
+
+
diff --git a/tests/fixtures/source/blocks/nodes/figure.rst b/tests/fixtures/source/blocks/nodes/figure.rst new file mode 100644 index 0000000..db55b2c --- /dev/null +++ b/tests/fixtures/source/blocks/nodes/figure.rst @@ -0,0 +1,10 @@ +.. figure:: images/logo.png + :alt: Symfony Logo + :width: 200px + +I am a paragraph AFTER the figure. I should not be included as the +caption for the above figure. + +.. figure:: images/logo.png + + But I am a caption *for* the figure above.