Skip to content

Use doctrine/rst-parser 0.6 #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed

Conversation

wouterj
Copy link
Contributor

@wouterj wouterj commented Jan 15, 2023

TYPO3 documention team member @linawolf is doing lots of great work over on the doctrine/rst-parser to (a) fix bugs in the current parser and (b) move some of the features that we wrote in this library over to the parser.

This PR is just a draft to see if these changes broke something for us. I'm planning on also removing some of the features implemented on the parser in this PR before 0.6 is stable (e.g. most admonition directives are now integrated in rst-parser).

  • Removed all directives that are now implemented in the RST Parser
  • Removed the kernel in favor of a BuilderFactory. The Kernel no longer serves a purpose with the introduction of the SymfonyDirectiveFactory.
  • Refactored our custom references to text roles, which new in RST Parser 0.6 and much closer to the official reStructuredText specification.

@wouterj wouterj marked this pull request as draft January 15, 2023 12:43
@linawolf
Copy link

Happy to see this

@wouterj
Copy link
Contributor Author

wouterj commented Jan 15, 2023

I must admit that I'm surprised by the green builds here, as the test suite breaks (in weird ways) locally 😄

PHPunit output locally
PHPUnit 9.5.28 by Sebastian Bergmann and contributors.

Warning:       Your XML configuration validates against a deprecated schema.
Suggestion:    Migrate your XML configuration using "--migrate-configuration"!

Testing 
...S....F.F.FF.FFFF.....F....................................     61 / 61 (100%)

Time: 00:00.570, Memory: 24.00 MB

There were 9 failures:

1) SymfonyDocsBuilder\Tests\IntegrationTest::testParseUnitBlock with data set "literal" ('nodes/literal')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
                     \Contracts
                     <wbr>
                         \Controller
-                        <wbr>\CrudControllerInterface</wbr>
-                    </wbr>
-                </wbr>
-            </wbr>
-        </wbr>
-    </code>
-    ,
+                        <wbr>
+                            \CrudControllerInterface
+                        </code>
+                        ,
 but you can also extend from the <code translate="no" class="notranslate">AbstractCrudController</code> class.
-</p>'
+                    </p>'

/home/wouter/projects/github.com/symfony-tools/docs-builder/tests/IntegrationTest.php:121

2) SymfonyDocsBuilder\Tests\IntegrationTest::testParseUnitBlock with data set "figure" ('nodes/figure')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
 '<figure>
-    <img src="" alt="Symfony Logo" width="200px">
+    <img src alt="Symfony Logo" width="200px">
 </figure>
 <p>I am a paragraph AFTER the figure. I should not be included as the
 caption for the above figure.</p>
 <figure>
-    <img src="">
+    <img src>
     <figcaption>
         <p>But I am a caption <em>for</em> the figure above.</p>
     </figcaption>
@@ @@
 </figure>
 <p>Some images use a special CSS class to wrap a fake browser around them:</p>
 <div class="with-browser">
-    <img src="" alt="A typical exception page in the development environment" align="center" class="some-class with-browser another-class">
+    <img src alt="A typical exception page in the development environment" align="center" class="some-class with-browser another-class">
 </div>
 <p>And RST figures use a different syntax to define their custom CSS classes:</p>
 <figure class="with-browser foo">
-    <img src="" alt="/" align="center">
+    <img src alt="/" align="center">
 </figure>'

/home/wouter/projects/github.com/symfony-tools/docs-builder/tests/IntegrationTest.php:121

3) SymfonyDocsBuilder\Tests\IntegrationTest::testParseUnitBlock with data set "caution" ('directives/caution')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
 '<div class="admonition admonition-caution ">
     <p class="admonition-title">
-        <svg xmlns="http://www.w3.org/2000/svg" fill="none" width="24" height="24" viewbox="0 0 24 24" stroke="currentColor">
-            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
-        </svg>
-        <span>Caution</span>
-    </p>
-    <p>Using too many sidebars or caution directives can be distracting!</p>
-</div>'
+        <svg fill="none" width="24" height="24" viewBox="0 0 24 24" stroke="currentColor">
+            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
+            </svg>
+            <span>Caution</span>
+        </p>
+        <p>Using too many sidebars or caution directives can be distracting!</p>
+    </div>'

/home/wouter/projects/github.com/symfony-tools/docs-builder/tests/IntegrationTest.php:121

4) SymfonyDocsBuilder\Tests\IntegrationTest::testParseUnitBlock with data set "note" ('directives/note')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
 '<div class="admonition admonition-note ">
     <p class="admonition-title">
-        <svg xmlns="http://www.w3.org/2000/svg" fill="none" width="24" height="24" viewbox="0 0 24 24" stroke="currentColor">
-            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path>
-        </svg>
-        <span>Note</span>
-    </p>
-    <p>Sometimes we add notes. But not too often because they interrupt the flow.</p>
-</div>'
+        <svg fill="none" width="24" height="24" viewBox="0 0 24 24" stroke="currentColor">
+            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
+            </svg>
+            <span>Note</span>
+        </p>
+        <p>Sometimes we add notes. But not too often because they interrupt the flow.</p>
+    </div>'

/home/wouter/projects/github.com/symfony-tools/docs-builder/tests/IntegrationTest.php:121

5) SymfonyDocsBuilder\Tests\IntegrationTest::testParseUnitBlock with data set "note-code-block-nested" ('directives/note-code-block-nested')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
 '<div class="admonition admonition-note ">
     <p class="admonition-title">
-        <svg xmlns="http://www.w3.org/2000/svg" fill="none" width="24" height="24" viewbox="0 0 24 24" stroke="currentColor">
-            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path>
-        </svg>
-        <span>Note</span>
-    </p>
-    <p>test</p>
-    <div translate="no" data-loc="1" class="notranslate codeblock codeblock-length-sm codeblock-php">
-        <div class="codeblock-scroll">
-            <pre class="codeblock-lines">1</pre>
-            <pre class="codeblock-code">
-                <code>
-                    <span class="hljs-comment">// code</span>
-                </code>
-            </pre>
+        <svg fill="none" width="24" height="24" viewBox="0 0 24 24" stroke="currentColor">
+            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
+            </svg>
+            <span>Note</span>
+        </p>
+        <p>test</p>
+        <div translate="no" data-loc="1" class="notranslate codeblock codeblock-length-sm codeblock-php">
+            <div class="codeblock-scroll">
+                <pre class="codeblock-lines">1</pre>
+                <pre class="codeblock-code">
+                    <code>
+                        <span class="hljs-comment">// code</span>
+                    </code>
+                </pre>
+            </div>
         </div>
-    </div>
-</div>'
+    </div>'

/home/wouter/projects/github.com/symfony-tools/docs-builder/tests/IntegrationTest.php:121

6) SymfonyDocsBuilder\Tests\IntegrationTest::testParseUnitBlock with data set "screencast" ('directives/screencast')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
 '<div class="admonition admonition-screencast ">
     <p class="admonition-title">
-        <svg xmlns="http://www.w3.org/2000/svg" fill="none" width="24" height="24" viewbox="0 0 24 24" stroke="currentColor">
-            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"></path>
-        </svg>
-        <span>Screencast</span>
-    </p>
-    <p>Do you prefer video tutorials? Check out the
+        <svg fill="none" width="24" height="24" viewBox="0 0 24 24" stroke="currentColor">
+            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z" />
+            </svg>
+            <span>Screencast</span>
+        </p>
+        <p>Do you prefer video tutorials? Check out the
 <a href="https://symfonycasts.com/screencast/symfony" class="reference external" rel="external noopener noreferrer" target="_blank">Stellar Development with Symfony</a>
 screencast series.</p>
-</div>
-<div class="admonition admonition-screencast ">
-    <p class="admonition-title">
-        <svg xmlns="http://www.w3.org/2000/svg" fill="none" width="24" height="24" viewbox="0 0 24 24" stroke="currentColor">
-            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"></path>
-        </svg>
-        <span>Screencast</span>
-    </p>
-    <p>Do you prefer video tutorials? Check out the
+    </div>
+    <div class="admonition admonition-screencast ">
+        <p class="admonition-title">
+            <svg fill="none" width="24" height="24" viewBox="0 0 24 24" stroke="currentColor">
+                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z" />
+                </svg>
+                <span>Screencast</span>
+            </p>
+            <p>Do you prefer video tutorials? Check out the
 <a href="https://symfonycasts.com/screencast/symfony" class="reference external" rel="external noopener noreferrer" target="_blank">Stellar Development with Symfony</a>
 screencast series.</p>
-</div>'
+        </div>'

/home/wouter/projects/github.com/symfony-tools/docs-builder/tests/IntegrationTest.php:121

7) SymfonyDocsBuilder\Tests\IntegrationTest::testParseUnitBlock with data set "seealso" ('directives/seealso')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
 '<div class="admonition admonition-seealso ">
     <p class="admonition-title">
-        <svg xmlns="http://www.w3.org/2000/svg" fill="none" width="24" height="24" viewbox="0 0 24 24" stroke="currentColor">
-            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"></path>
-        </svg>
-        <span>See also</span>
-    </p>
-    <p>Also check out the homepage</p>
-</div>'
+        <svg fill="none" width="24" height="24" viewBox="0 0 24 24" stroke="currentColor">
+            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1" />
+            </svg>
+            <span>See also</span>
+        </p>
+        <p>Also check out the homepage</p>
+    </div>'

/home/wouter/projects/github.com/symfony-tools/docs-builder/tests/IntegrationTest.php:121

8) SymfonyDocsBuilder\Tests\IntegrationTest::testParseUnitBlock with data set "tip" ('directives/tip')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
 '<div class="admonition admonition-tip ">
     <p class="admonition-title">
-        <svg xmlns="http://www.w3.org/2000/svg" fill="none" width="24" height="24" viewbox="0 0 24 24" stroke="currentColor">
-            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z"></path>
-        </svg>
-        <span>Tip</span>
-    </p>
-    <p>This is a little tip about something! We an also talk about specific</p>
-</div>'
+        <svg fill="none" width="24" height="24" viewBox="0 0 24 24" stroke="currentColor">
+            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z" />
+            </svg>
+            <span>Tip</span>
+        </p>
+        <p>This is a little tip about something! We an also talk about specific</p>
+    </div>'

/home/wouter/projects/github.com/symfony-tools/docs-builder/tests/IntegrationTest.php:121

9) SymfonyDocsBuilder\Tests\IntegrationTest::testParseUnitBlock with data set "configuration-block" ('directives/configuration-block')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
             <span>PHP</span>
         </li>
     </ul>
-    <div class="configuration-codeblock" data-language="yaml" style="">
+    <div class="configuration-codeblock" data-language="yaml" style>
         <div translate="no" data-loc="1" class="notranslate codeblock codeblock-length-sm codeblock-yaml">
             <div class="codeblock-scroll">
                 <pre class="codeblock-lines">1</pre>

/home/wouter/projects/github.com/symfony-tools/docs-builder/tests/IntegrationTest.php:121

FAILURES!
Tests: 61, Assertions: 135, Failures: 9, Skipped: 1.

@wouterj
Copy link
Contributor Author

wouterj commented Jan 15, 2023

Ooh nevermind, this apparently has something to do with PHP 8.1: #147

@javiereguiluz
Copy link
Collaborator

@wouterj if you have some time for this, let's try to change this from draft to a real PR. It looks OK and it would fix the current failing tests in PHP 8.2. Thanks a lot!

@linawolf
Copy link

@javiereguiluz I still have one major breaking change for v. 0.6 pending before we can release and only do Bugfixes thereafter. If you and or@wouterj could review that would be helpful. I would not suggest to use v 0.6 in productive before that or is merged.

@wouterj
Copy link
Contributor Author

wouterj commented Mar 5, 2023

After the changes in 0.6 in the past 2 months, there is quite some more work to do on this library in order to be compatible. I've done the first big part of the work, with 14 failing tests left (in some cases, the tests are wrong, in others our implementation and for some I believe there might be a bug on rst-parser).

@wouterj
Copy link
Contributor Author

wouterj commented Mar 9, 2023

This PR is now nearly ready. Lots of code removed and two regressions left in RST Parser (doctrine/rst-parser#265 & doctrine/rst-parser#266).

@wouterj wouterj marked this pull request as ready for review March 9, 2023 12:46
Copy link
Collaborator

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed this and it looks correct to me. I love how many code we can remove thanks to the directives added upstream.

You also kept all the directives/roles specific for Symfony Docs, so I think we're good.

By the way, in symfony.com we build docs like this:

$buildConfig = (new BuildConfig())
    ->setContentDir($buildDir)
    ->setOutputDir($tempBuildDir)
    // ...

$result = $this->docBuilder->build($buildConfig);

Can you see any possible changes that we might need to do because of this PR? Thanks!

@wouterj
Copy link
Contributor Author

wouterj commented Mar 9, 2023

Can you see any possible changes that we might need to do because of this PR? Thanks!

No, the public APIs of those 2 classes you show in the example (DocBuilder and BuildConfig) have not changed.

You might want to check templates/themes though. Does symfony.com use the theme provided in this repository, or does it have custom Twig templates? If it's the latter, those might need some updates

@javiereguiluz
Copy link
Collaborator

Thanks for verifying this. No, we don't use custom templates because we rely on the default theme. Thanks!

@wouterj wouterj closed this Sep 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants