Skip to content

Commit 7cd65bf

Browse files
authored
Merge pull request #79 from weaverryan/figure-test-case
Adding a failing test case for bad figure behavior
2 parents 368ef5a + b53b712 commit 7cd65bf

File tree

7 files changed

+59
-13
lines changed

7 files changed

+59
-13
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"require": {
1717
"ext-json": "*",
1818
"ext-curl": "*",
19-
"doctrine/rst-parser": "0.3.x-dev",
19+
"doctrine/rst-parser": "0.4.x-dev",
2020
"scrivo/highlight.php": "^9.12.0",
2121
"symfony/filesystem": "^5.2",
2222
"symfony/finder": "^5.2",

composer.lock

+10-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Directive/AbstractAdmonitionDirective.php

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public function __construct(string $name, string $text)
2929

3030
final public function processSub(Parser $parser, ?Node $document, string $variable, string $data, array $options): ?Node
3131
{
32+
if (null === $document) {
33+
throw new \RuntimeException('Content expected, none found.');
34+
}
35+
3236
$wrapperDiv = $parser->renderTemplate(
3337
'directives/admonition.html.twig',
3438
[

tests/IntegrationTest.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,13 @@ public function testParseUnitBlock(string $blockName)
103103
$expectedCrawler = new Crawler($expectedHtml);
104104
$indenter = $this->createIndenter();
105105

106+
$expected = trim($expectedCrawler->filter('body')->html());
107+
// you can add notes to a test file via <!-- REMOVE the notes here -->
108+
// we remove them here for comparing
109+
$expected = preg_replace('/<\!\-\- REMOVE(.)+\-\->/', '', $expected);
110+
106111
$this->assertSame(
107-
$indenter->indent(trim($expectedCrawler->filter('body')->html())),
112+
$indenter->indent($expected),
108113
$indenter->indent(trim($actualCrawler->filter('body')->html()))
109114
);
110115
}
@@ -123,6 +128,10 @@ public function parserUnitBlockProvider()
123128
'blockName' => 'nodes/list',
124129
];
125130

131+
yield 'figure' => [
132+
'blockName' => 'nodes/figure',
133+
];
134+
126135
yield 'caution' => [
127136
'blockName' => 'directives/caution',
128137
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
</head>
6+
<body>
7+
8+
<figure>
9+
<!-- REMOVE: src is empty just because the test doesn't utilize the full stack, with CopyImagesListener -->
10+
<img src="" alt="Symfony Logo" width="200px" />
11+
</figure>
12+
<p>I am a paragraph AFTER the figure. I should not be included as the
13+
caption for the above figure.</p>
14+
15+
<figure>
16+
<img src="" />
17+
18+
<figcaption><p>But I am a caption <em>for</em> the figure above.</p></figcaption>
19+
</figure>
20+
21+
</body>
22+
</html>

tests/fixtures/expected/toctree/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ <h1 id="toctree"><a class="headerlink" href="#toctree" title="Permalink to this
1212
<div class="toctree-wrapper"><ul class="toctree toctree-level-1 toctree-length-1"><li><a href="file.html">Title</a><ul class="toctree toctree-level-2 toctree-length-1"><li><a href="file.html#sub-title">Sub title</a></li></ul></li></ul></div>
1313
<div class="toctree-wrapper"><ul class="toctree toctree-level-1 toctree-length-1"><li><a href="file.html">Title</a></li></ul></div>
1414
<div class="toctree-wrapper"><ul class="toctree toctree-level-1 toctree-length-1"><li><a href="directory/another_file.html">Another file</a></li></ul></div>
15-
<div class="toctree-wrapper"><ul class="toctree toctree-level-1 toctree-length-3"><li><a href="index.html#toctree">Toctree</a></li><li><a href="directory/another_file.html">Another file</a></li><li><a href="file.html">Title</a><ul class="toctree toctree-level-2 toctree-length-1"><li><a href="file.html#sub-title">Sub title</a></li></ul></li></ul></div>
16-
<div class="toctree-wrapper"><ul class="toctree toctree-level-1 toctree-length-3"><li><a href="file.html">Title</a><ul class="toctree toctree-level-2 toctree-length-1"><li><a href="file.html#sub-title">Sub title</a></li></ul></li><li><a href="index.html#toctree">Toctree</a></li><li><a href="directory/another_file.html">Another file</a></li></ul></div>
15+
<div class="toctree-wrapper"><ul class="toctree toctree-level-1 toctree-length-2"><li><a href="directory/another_file.html">Another file</a></li><li><a href="file.html">Title</a><ul class="toctree toctree-level-2 toctree-length-1"><li><a href="file.html#sub-title">Sub title</a></li></ul></li></ul></div>
16+
<div class="toctree-wrapper"><ul class="toctree toctree-level-1 toctree-length-2"><li><a href="file.html">Title</a><ul class="toctree toctree-level-2 toctree-length-1"><li><a href="file.html#sub-title">Sub title</a></li></ul></li><li><a href="directory/another_file.html">Another file</a></li></ul></div>
1717

1818
</div>
1919

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.. figure:: images/logo.png
2+
:alt: Symfony Logo
3+
:width: 200px
4+
5+
I am a paragraph AFTER the figure. I should not be included as the
6+
caption for the above figure.
7+
8+
.. figure:: images/logo.png
9+
10+
But I am a caption *for* the figure above.

0 commit comments

Comments
 (0)