diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bc16178d..f85af4b3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -20,7 +20,7 @@ jobs: uses: shivammathur/setup-php@v2 with: coverage: none - php-version: 7.4 + php-version: 8.3 tools: composer:v2 ini-values: date.timezone=UTC @@ -37,7 +37,7 @@ jobs: # add here only the PHP versions and OS used in GitHub CI (for tests) # and on the symfony.com server (where the Symfony Docs are built) operating-system: ['ubuntu-latest'] - php-version: ['7.4', '8.3'] + php-version: ['8.3', '8.4'] steps: - name: 'Checkout code' diff --git a/composer.json b/composer.json index dde5a060..8e66adac 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } }, "require": { - "php": ">=7.4", + "php": ">=8.3", "ext-json": "*", "ext-curl": "*", "doctrine/rst-parser": "^0.5", diff --git a/src/Reference/MethodReference.php b/src/Reference/MethodReference.php index 632aaa26..b068f334 100644 --- a/src/Reference/MethodReference.php +++ b/src/Reference/MethodReference.php @@ -30,20 +30,19 @@ public function getName(): string public function resolve(Environment $environment, string $data): ResolvedReference { - $className = explode('::', $data)[0]; - $className = str_replace('\\\\', '\\', $className); - - if (!u($data)->containsAny('::')) { + $data = u($data); + if (!$data->containsAny('::')) { throw new \RuntimeException(sprintf('Malformed method reference "%s" in file "%s"', $data, $environment->getCurrentFileName())); } - $methodName = explode('::', $data)[1]; + [$className, $methodName] = $data->split('::', 2); + $className = $className->replace('\\\\', '\\'); $scrollTextFragment = sprintf('#:~:text=%s', rawurlencode('function '.$methodName)); return new ResolvedReference( $environment->getCurrentFileName(), $methodName.'()', - sprintf('%s/%s.php%s', $this->symfonyRepositoryUrl, str_replace('\\', '/', $className), $scrollTextFragment), + sprintf('%s/%s.php%s', $this->symfonyRepositoryUrl, $className->replace('\\', '/'), $scrollTextFragment), [], [ 'title' => sprintf('%s::%s()', $className, $methodName), diff --git a/src/Reference/PhpClassReference.php b/src/Reference/PhpClassReference.php index 4e104e17..fbaabe44 100644 --- a/src/Reference/PhpClassReference.php +++ b/src/Reference/PhpClassReference.php @@ -12,6 +12,7 @@ use Doctrine\RST\Environment; use Doctrine\RST\References\Reference; use Doctrine\RST\References\ResolvedReference; +use function Symfony\Component\String\u; class PhpClassReference extends Reference { @@ -29,13 +30,15 @@ public function getName(): string public function resolve(Environment $environment, string $data): ResolvedReference { + $className = u($data)->replace('\\\\', '\\'); + return new ResolvedReference( $environment->getCurrentFileName(), - $data, - sprintf('%s/class.%s.php', $this->phpDocUrl, strtolower($data)), + $className->afterLast('\\'), + sprintf('%s/class.%s.php', $this->phpDocUrl, $className->replace('\\', '-')->lower()), [], [ - 'title' => $data, + 'title' => $className, ] ); } diff --git a/src/Reference/PhpMethodReference.php b/src/Reference/PhpMethodReference.php index ac537440..9a85a918 100644 --- a/src/Reference/PhpMethodReference.php +++ b/src/Reference/PhpMethodReference.php @@ -12,6 +12,7 @@ use Doctrine\RST\Environment; use Doctrine\RST\References\Reference; use Doctrine\RST\References\ResolvedReference; +use function Symfony\Component\String\u; class PhpMethodReference extends Reference { @@ -29,15 +30,21 @@ public function getName(): string public function resolve(Environment $environment, string $data): ResolvedReference { - [$class, $method] = explode('::', $data, 2); + $data = u($data); + if (!$data->containsAny('::')) { + throw new \RuntimeException(sprintf('Malformed method reference "%s" in file "%s"', $data, $environment->getCurrentFileName())); + } + + [$className, $methodName] = $data->split('::', 2); + $className = $className->replace('\\\\', '\\'); return new ResolvedReference( $environment->getCurrentFileName(), - $data.'()', - sprintf('%s/%s.%s.php', $this->phpDocUrl, strtolower($class), strtolower($method)), + $methodName.'()', + sprintf('%s/%s.%s.php', $this->phpDocUrl, $className->replace('\\', '-')->lower(), $methodName->lower()), [], [ - 'title' => $class, + 'title' => sprintf('%s::%s()', $className, $methodName), ] ); } diff --git a/src/Renderers/SpanNodeRenderer.php b/src/Renderers/SpanNodeRenderer.php index 927c3fa5..e1e77755 100644 --- a/src/Renderers/SpanNodeRenderer.php +++ b/src/Renderers/SpanNodeRenderer.php @@ -32,7 +32,7 @@ public function __construct( SpanNode $span, BaseSpanNodeRenderer $decoratedSpanNodeRenderer, ?UrlChecker $urlChecker = null, - string $symfonyVersion = null + ?string $symfonyVersion = null ) { parent::__construct($environment, $span); diff --git a/src/SymfonyHTMLFormat.php b/src/SymfonyHTMLFormat.php index 9c17ca94..16ea957d 100644 --- a/src/SymfonyHTMLFormat.php +++ b/src/SymfonyHTMLFormat.php @@ -29,7 +29,7 @@ final class SymfonyHTMLFormat implements Format private $urlChecker; private $symfonyVersion; - public function __construct(TemplateRenderer $templateRenderer, Format $HTMLFormat, ?UrlChecker $urlChecker = null, string $symfonyVersion = null) + public function __construct(TemplateRenderer $templateRenderer, Format $HTMLFormat, ?UrlChecker $urlChecker = null, ?string $symfonyVersion = null) { $this->templateRenderer = $templateRenderer; $this->htmlFormat = $HTMLFormat; diff --git a/src/Templates/default/html/image.html.twig b/src/Templates/default/html/image.html.twig index f7ff3ffe..14f090e6 100644 --- a/src/Templates/default/html/image.html.twig +++ b/src/Templates/default/html/image.html.twig @@ -2,7 +2,7 @@ Overridden so we can control the path to the image based on our copying logic. See CopyImagesListener. #} -{% set wrap_image_with_browser = 'with-browser' in imageNode.options.class ?? '' %} +{% set wrap_image_with_browser = 'with-browser' in (imageNode.options.class ?? '') %} {% if wrap_image_with_browser %}
{% endif %} {% if wrap_image_with_browser %}
{% endif %} diff --git a/src/Templates/highlight.php/php.json b/src/Templates/highlight.php/php.json index 6f699706..0db2cb8d 100644 --- a/src/Templates/highlight.php/php.json +++ b/src/Templates/highlight.php/php.json @@ -204,7 +204,15 @@ "_": "variable" }, { - "$ref": "#contains.10.contains.3.contains.2", + "$ref": "#contains.3", + "_": "comment" + }, + { + "$ref": "#contains.4", + "_": "comment" + }, + { + "$ref": "#contains.5", "_": "comment" }, { @@ -258,19 +266,8 @@ "_": "variable" }, { - "className": "comment", - "begin": "/\\*", - "end": "\\*/", - "contains": [ - { - "$ref": "#contains.2.contains.0" - }, - { - "className": "doctag", - "begin": "(?:TODO|FIXME|NOTE|BUG|XXX):", - "relevance": 0 - } - ] + "$ref": "#contains.5", + "_": "comment" }, { "className": "string", diff --git a/src/Templates/highlight.php/twig.json b/src/Templates/highlight.php/twig.json index b961028c..ceb675dc 100644 --- a/src/Templates/highlight.php/twig.json +++ b/src/Templates/highlight.php/twig.json @@ -25,6 +25,12 @@ "begin": "\\{%", "end": "%}", "contains": [ + { + "className": "comment", + "begin": "#", + "end": "$", + "endsWithParent": true + }, { "className": "name", "begin": "\\w+", @@ -32,6 +38,9 @@ "starts": { "endsWithParent": true, "contains": [ + { + "$ref": "#contains.1.contains.0" + }, { "begin": "\\|[A-Za-z_]+:?", "keywords": "abs batch capitalize column convert_encoding date date_modify default escape filter first format inky_to_html inline_css join json_encode keys last length lower map markdown merge nl2br number_format raw reduce replace reverse round slice sort spaceless split striptags title trim upper url_encode", @@ -53,7 +62,7 @@ ] }, { - "$ref": "#contains.1.contains.0.starts.contains.0.contains.0" + "$ref": "#contains.1.contains.1.starts.contains.1.contains.0" } ], "relevance": 0 @@ -68,10 +77,13 @@ "contains": [ "self", { - "$ref": "#contains.1.contains.0.starts.contains.0" + "$ref": "#contains.1.contains.0" + }, + { + "$ref": "#contains.1.contains.1.starts.contains.1" }, { - "$ref": "#contains.1.contains.0.starts.contains.0.contains.0" + "$ref": "#contains.1.contains.1.starts.contains.1.contains.0" } ] } diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 30453348..07f37338 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -298,6 +298,10 @@ public function parserUnitBlockProvider() 'blockName' => 'code-blocks/php-attributes', ]; + yield 'code-block-php-nested-comments' => [ + 'blockName' => 'code-blocks/php-nested-comments', + ]; + yield 'code-block-text' => [ 'blockName' => 'code-blocks/text', ]; diff --git a/tests/fixtures/expected/blocks/code-blocks/php-nested-comments.html b/tests/fixtures/expected/blocks/code-blocks/php-nested-comments.html new file mode 100644 index 00000000..e1f7078f --- /dev/null +++ b/tests/fixtures/expected/blocks/code-blocks/php-nested-comments.html @@ -0,0 +1,72 @@ +

You can do that by adding a "stamp" to your message:

+
+
+
1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+
+            
+                use
+                Symfony
+                \
+                Component
+                \
+                Messenger
+                \
+                MessageBusInterface
+                ;
+                use
+                Symfony
+                \
+                Component
+                \
+                Messenger
+                \
+                Stamp
+                \
+                DelayStamp
+                ;
+                public
+                
+                    function
+                    index
+                    
+                        (MessageBusInterface
+                        
+                            $
+                            bus
+                        
+                        )
+                    
+                
+                {
+                
+                    $
+                    bus
+                
+                ->
+                dispatch
+                (
+                new
+                SmsNotification
+                (
+                '...'
+                ), [
+                // wait 5 seconds before processing
+                new
+                DelayStamp
+                (
+                5000
+                ), ]);
+}
+            
+        
+
+
diff --git a/tests/fixtures/expected/blocks/code-blocks/twig.html b/tests/fixtures/expected/blocks/code-blocks/twig.html index fab139d4..83c841cf 100644 --- a/tests/fixtures/expected/blocks/code-blocks/twig.html +++ b/tests/fixtures/expected/blocks/code-blocks/twig.html @@ -1,6 +1,30 @@ -
+
-
1
-
{# some code #}
+
1
+2
+3
+4
+5
+6
+7
+8
+9
+
+            
+                {# some code #}
+                
+                
+                    {%
+                        set some_var = 'some value' # some inline comment
+                    %}
+                
+                
+                {{
+                    # another inline comment
+                    'Lorem Ipsum'|uppercase
+                    # final inline comment
+                }}
+            
+        
diff --git a/tests/fixtures/expected/blocks/references/php-class.html b/tests/fixtures/expected/blocks/references/php-class.html index 271b968c..a91b1fd2 100644 --- a/tests/fixtures/expected/blocks/references/php-class.html +++ b/tests/fixtures/expected/blocks/references/php-class.html @@ -1 +1,2 @@

ArrayAccess

+

Number

diff --git a/tests/fixtures/expected/blocks/references/php-method.html b/tests/fixtures/expected/blocks/references/php-method.html index e86c5717..59323ada 100644 --- a/tests/fixtures/expected/blocks/references/php-method.html +++ b/tests/fixtures/expected/blocks/references/php-method.html @@ -1 +1,2 @@ -

Locale::getDefault()

+

getDefault()

+

add()

diff --git a/tests/fixtures/expected/main/datetime.html b/tests/fixtures/expected/main/datetime.html index f36ddc33..d6892fa9 100644 --- a/tests/fixtures/expected/main/datetime.html +++ b/tests/fixtures/expected/main/datetime.html @@ -79,7 +79,7 @@

methods: doRequest(). Or a namespace: Constraints. Or a PHP function: parse_ini_file. -Or a PHP method! Locale::getDefault().

+Or a PHP method! getDefault().

diff --git a/tests/fixtures/source/blocks/code-blocks/php-nested-comments.rst b/tests/fixtures/source/blocks/code-blocks/php-nested-comments.rst new file mode 100644 index 00000000..ea8dc0f4 --- /dev/null +++ b/tests/fixtures/source/blocks/code-blocks/php-nested-comments.rst @@ -0,0 +1,12 @@ +You can do that by adding a "stamp" to your message:: + + use Symfony\Component\Messenger\MessageBusInterface; + use Symfony\Component\Messenger\Stamp\DelayStamp; + + public function index(MessageBusInterface $bus) + { + $bus->dispatch(new SmsNotification('...'), [ + // wait 5 seconds before processing + new DelayStamp(5000), + ]); + } diff --git a/tests/fixtures/source/blocks/code-blocks/twig.rst b/tests/fixtures/source/blocks/code-blocks/twig.rst index 01d06851..229041d1 100644 --- a/tests/fixtures/source/blocks/code-blocks/twig.rst +++ b/tests/fixtures/source/blocks/code-blocks/twig.rst @@ -1,3 +1,11 @@ - .. code-block:: twig + {# some code #} + {% + set some_var = 'some value' # some inline comment + %} + {{ + # another inline comment + 'Lorem Ipsum'|uppercase + # final inline comment + }} diff --git a/tests/fixtures/source/blocks/references/php-class.rst b/tests/fixtures/source/blocks/references/php-class.rst index 5708c647..284a9018 100644 --- a/tests/fixtures/source/blocks/references/php-class.rst +++ b/tests/fixtures/source/blocks/references/php-class.rst @@ -1,2 +1,4 @@ :phpclass:`ArrayAccess` + +:phpclass:`BcMath\\Number` diff --git a/tests/fixtures/source/blocks/references/php-method.rst b/tests/fixtures/source/blocks/references/php-method.rst index 11705cd5..26d782d5 100644 --- a/tests/fixtures/source/blocks/references/php-method.rst +++ b/tests/fixtures/source/blocks/references/php-method.rst @@ -1,2 +1,4 @@ :phpmethod:`Locale::getDefault` + +:phpmethod:`BcMath\\Number::add`