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/CodeNodeRenderer.php b/src/Renderers/CodeNodeRenderer.php index cfa46a11..d5e771ee 100644 --- a/src/Renderers/CodeNodeRenderer.php +++ b/src/Renderers/CodeNodeRenderer.php @@ -70,9 +70,6 @@ public function render(): string $highLighter = new Highlighter(); $highlightedCode = $highLighter->highlight($languageMapping, $code)->value; - - // this allows to highlight the $ in PHP variable names - $highlightedCode = str_replace('$', '$', $highlightedCode); } if ('terminal' === $language) { @@ -124,6 +121,7 @@ private function configureHighlighter() if (false === self::$isHighlighterConfigured) { Highlighter::registerLanguage('php', __DIR__.'/../Templates/highlight.php/php.json', true); Highlighter::registerLanguage('twig', __DIR__.'/../Templates/highlight.php/twig.json', true); + Highlighter::registerLanguage('yaml', __DIR__.'/../Templates/highlight.php/yaml.json', true); } self::$isHighlighterConfigured = true; diff --git a/src/Renderers/SpanNodeRenderer.php b/src/Renderers/SpanNodeRenderer.php index 65598bd2..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); @@ -42,6 +42,24 @@ public function __construct( $this->symfonyVersion = $symfonyVersion; } + public function render(): string + { + // Work around "~" being parsed as non-breaking space by rst-parser, + // while this is not part of the specification. + $spanValue = $this->span->getValue(); + + if (str_contains($spanValue, '__TILDE__')) { + throw new \Exception('Cannot render content containing the text "__TILDE__" as it is used as a special placeholder in the build.'); + } + + $spanValue = str_replace('~', '__TILDE__', $spanValue); + $this->span->setValue($spanValue); + + $rendered = parent::render(); + + return str_replace('__TILDE__', '~', $rendered); + } + /** @inheritDoc */ public function link(?string $url, string $title, array $attributes = []): string { 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/figure.html.twig b/src/Templates/default/html/figure.html.twig index e1786c07..5836788a 100644 --- a/src/Templates/default/html/figure.html.twig +++ b/src/Templates/default/html/figure.html.twig @@ -1,12 +1,7 @@ {# Overridden to fix lack of figclass support (class attribute on +
{{ figureNode.image.render()|raw }} {% if figureNode.document %} @@ -17,4 +12,3 @@ Overridden to fix lack of figclass support (class attribute on -{% endapply %} 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/default/html/link.html.twig b/src/Templates/default/html/link.html.twig index 8b9ca5ba..7c82a66e 100644 --- a/src/Templates/default/html/link.html.twig +++ b/src/Templates/default/html/link.html.twig @@ -1,5 +1,3 @@ -{% apply spaceless %} {% set domElement = attributes.domElement|default %} {% set class = (attributes.class|default ? attributes.class ~ ' ' : '') ~ 'reference ' ~ (('://' in url) ? 'external' : 'internal') %} key != 'domElement' and key != 'class') %} {{ key }}="{{ value }}"{% endfor %}>{% if domElement %}<{{ domElement }}>{% endif %}{{ title|raw }}{% if domElement %}{% endif %} -{% endapply %} diff --git a/src/Templates/default/html/toc-level.html.twig b/src/Templates/default/html/toc-level.html.twig index 1bdaef8d..8c3eb348 100644 --- a/src/Templates/default/html/toc-level.html.twig +++ b/src/Templates/default/html/toc-level.html.twig @@ -1,7 +1,5 @@ -{% apply spaceless %} -
    - {% for tocItem in tocItems %} - {% include "toc-item.html.twig" with { toc_deep_level: 1 } %} - {% endfor %} -
-{% endapply %} +
    + {% for tocItem in tocItems %} + {% include "toc-item.html.twig" with { toc_deep_level: 1 } %} + {% endfor %} +
diff --git a/src/Templates/default/html/toc.html.twig b/src/Templates/default/html/toc.html.twig index 55b87372..8b9c8836 100644 --- a/src/Templates/default/html/toc.html.twig +++ b/src/Templates/default/html/toc.html.twig @@ -1,6 +1,4 @@ -{% apply spaceless %} - {% set toc_options = toc_options(tocItems) %} -
- {% include "toc-level.html.twig" %} -
-{% endapply %} +{% set toc_options = toc_options(tocItems) %} +
+ {% include "toc-level.html.twig" %} +
diff --git a/src/Templates/highlight.php/php.json b/src/Templates/highlight.php/php.json index 3f127b81..0db2cb8d 100644 --- a/src/Templates/highlight.php/php.json +++ b/src/Templates/highlight.php/php.json @@ -8,20 +8,34 @@ "php7" ], "case_insensitive": true, - "keywords": "and include_once list abstract global private echo interface as static endswitch array null if endwhile or const for endforeach self var while isset public protected exit foreach throw elseif include __FILE__ empty require_once do xor return parent clone use __CLASS__ __LINE__ else break print eval new catch __METHOD__ case exception default die require __FUNCTION__ enddeclare final try match switch continue endfor endif declare unset true false goto instanceof insteadof __DIR__ __NAMESPACE__ yield finally", + "keywords": "PHP_VERSION PHP_MAJOR_VERSION PHP_MINOR_VERSION PHP_RELEASE_VERSION PHP_VERSION_ID PHP_EXTRA_VERSION ZEND_THREAD_SAFE ZEND_DEBUG_BUILD PHP_ZTS PHP_DEBUG PHP_MAXPATHLEN PHP_OS PHP_OS_FAMILY PHP_SAPI PHP_EOL PHP_INT_MAX PHP_INT_MIN PHP_INT_SIZE PHP_FLOAT_DIG PHP_FLOAT_EPSILON PHP_FLOAT_MIN PHP_FLOAT_MAX DEFAULT_INCLUDE_PATH PEAR_INSTALL_DIR PEAR_EXTENSION_DIR PHP_EXTENSION_DIR PHP_PREFIX PHP_BINDIR PHP_BINARY PHP_MANDIR PHP_LIBDIR PHP_DATADIR PHP_SYSCONFDIR PHP_LOCALSTATEDIR PHP_CONFIG_FILE_PATH PHP_CONFIG_FILE_SCAN_DIR PHP_SHLIB_SUFFIX PHP_FD_SETSIZE E_ERROR E_WARNING E_PARSE E_NOTICE E_CORE_ERROR E_CORE_WARNING E_COMPILE_ERROR E_COMPILE_WARNING E_USER_ERROR E_USER_WARNING E_USER_NOTICE E_RECOVERABLE_ERROR E_DEPRECATED E_USER_DEPRECATED E_ALL E_STRICT __COMPILER_HALT_OFFSET__ PHP_WINDOWS_EVENT_CTRL_C PHP_WINDOWS_EVENT_CTRL_BREAK PHP_CLI_PROCESS_TITLE STDERR STDIN STDOUT __CLASS__ __DIR__ __FILE__ __FUNCTION__ __LINE__ __METHOD__ __NAMESPACE__ __TRAIT__ die echo exit include include_once print require require_once abstract and as binary break case catch class clone const continue declare default do double else elseif empty enddeclare endfor endforeach endif endswitch endwhile enum eval extends final finally for foreach from global goto if implements instanceof insteadof interface isset list match|0 new or parent private protected public readonly return switch throw trait try unset use var void while xor yield array bool boolean callable float int integer iterable mixed never numeric object real string resource self static false FALSE null NULL true TRUE", "contains": [ { - "className": "php-attribute", - "begin": "#\\[\\s*(\\\\?[A-Z][A-Za-z0-9_\\x7f-\\xff]+|\\\\?[A-Z]+(?=[A-Z][a-z0-9_\\x7f-\\xff])){1,}(?![A-Za-z0-9])(?![$])", + "className": "meta", + "begin": "#\\[\\s*(\\\\?[A-Z][A-Za-z0-9_\\x7f-\\xff]+)+\\]" + }, + { + "begin": "#\\[\\s*(\\\\?[A-Z][A-Za-z0-9_\\x7f-\\xff]+)+(?![A-Za-z0-9])(?![$])", "end": "]", + "returnBegin": true, "contains": [ + { + "className": "meta", + "begin": "#\\[\\s*(\\\\?[A-Z][A-Za-z0-9_\\x7f-\\xff]+)+(?![A-Za-z0-9])(?![$])" + }, { "begin": "\\(", "end": "\\)", - "keywords": "true false null new array", + "keywords": "array bool boolean float int integer new real string false FALSE null NULL true TRUE PHP_VERSION PHP_MAJOR_VERSION PHP_MINOR_VERSION PHP_RELEASE_VERSION PHP_VERSION_ID PHP_EXTRA_VERSION ZEND_THREAD_SAFE ZEND_DEBUG_BUILD PHP_ZTS PHP_DEBUG PHP_MAXPATHLEN PHP_OS PHP_OS_FAMILY PHP_SAPI PHP_EOL PHP_INT_MAX PHP_INT_MIN PHP_INT_SIZE PHP_FLOAT_DIG PHP_FLOAT_EPSILON PHP_FLOAT_MIN PHP_FLOAT_MAX DEFAULT_INCLUDE_PATH PEAR_INSTALL_DIR PEAR_EXTENSION_DIR PHP_EXTENSION_DIR PHP_PREFIX PHP_BINDIR PHP_BINARY PHP_MANDIR PHP_LIBDIR PHP_DATADIR PHP_SYSCONFDIR PHP_LOCALSTATEDIR PHP_CONFIG_FILE_PATH PHP_CONFIG_FILE_SCAN_DIR PHP_SHLIB_SUFFIX PHP_FD_SETSIZE E_ERROR E_WARNING E_PARSE E_NOTICE E_CORE_ERROR E_CORE_WARNING E_COMPILE_ERROR E_COMPILE_WARNING E_USER_ERROR E_USER_WARNING E_USER_NOTICE E_RECOVERABLE_ERROR E_DEPRECATED E_USER_DEPRECATED E_ALL E_STRICT __COMPILER_HALT_OFFSET__ PHP_WINDOWS_EVENT_CTRL_C PHP_WINDOWS_EVENT_CTRL_BREAK PHP_CLI_PROCESS_TITLE STDERR STDIN STDOUT __CLASS__ __DIR__ __FILE__ __FUNCTION__ __LINE__ __METHOD__ __NAMESPACE__ __TRAIT__", "contains": { - "$ref": "#contains.10.contains.1.contains" + "$ref": "#contains.9.contains.1.contains", + "_": "params" } + }, + { + "className": "meta", + "begin": "]", + "endsParent": true } ] }, @@ -50,7 +64,7 @@ "begin": "<\\?(php)?|\\?>" }, { - "$ref": "#contains.1.contains.0" + "$ref": "#contains.2.contains.0" }, { "className": "doctag", @@ -69,7 +83,7 @@ "begin": "@[A-Za-z]+" }, { - "$ref": "#contains.1.contains.0" + "$ref": "#contains.2.contains.0" }, { "className": "doctag", @@ -84,7 +98,7 @@ "end": false, "contains": [ { - "$ref": "#contains.1.contains.0" + "$ref": "#contains.2.contains.0" }, { "className": "doctag", @@ -120,67 +134,149 @@ ] }, { - "$ref": "#contains.2.contains.0" - }, - { - "className": "variable", - "begin": "\\$this\\b" + "$ref": "#contains.3.contains.0" }, { "className": "variable", - "begin": "\\$+[a-zA-Z_-ÿ][a-zA-Z0-9_-ÿ]*" + "begin": "\\$+[a-zA-Z_-ÿ][a-zA-Z0-9_-ÿ]*", + "returnBegin": true, + "contains": [ + { + "className": "variable-other-marker", + "begin": "\\$" + }, + { + "begin": "\\$*[a-zA-Z_-ÿ][a-zA-Z0-9_-ÿ]*" + } + ] }, { - "className": "operator", - "begin": "(::|->)", - "end": "[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*", - "excludeEnd": true + "begin": "\\b(?!fn\\b|function\\b|__CLASS__\\b|__DIR__\\b|__FILE__\\b|__FUNCTION__\\b|__COMPILER_HALT_OFFSET__\\b|__LINE__\\b|__METHOD__\\b|__NAMESPACE__\\b|__TRAIT__\\b|die\\b|echo\\b|exit\\b|include\\b|include_once\\b|print\\b|require\\b|require_once\\b|array\\b|abstract\\b|and\\b|as\\b|binary\\b|bool\\b|boolean\\b|break\\b|callable\\b|case\\b|catch\\b|class\\b|clone\\b|const\\b|continue\\b|declare\\b|default\\b|do\\b|double\\b|else\\b|elseif\\b|empty\\b|enddeclare\\b|endfor\\b|endforeach\\b|endif\\b|endswitch\\b|endwhile\\b|enum\\b|eval\\b|extends\\b|final\\b|finally\\b|float\\b|for\\b|foreach\\b|from\\b|global\\b|goto\\b|if\\b|implements\\b|instanceof\\b|insteadof\\b|int\\b|integer\\b|interface\\b|isset\\b|iterable\\b|list\\b|match\\b|mixed\\b|new\\b|never\\b|object\\b|or\\b|private\\b|protected\\b|public\\b|readonly\\b|real\\b|return\\b|string\\b|switch\\b|throw\\b|trait\\b|try\\b|unset\\b|use\\b|var\\b|void\\b|while\\b|xor\\b|yield|Countable\\b|OuterIterator\\b|RecursiveIterator\\b|SeekableIterator\\b|ArrayAccess\\b|BackedEnum\\b|Generator\\b|Iterator\\b|IteratorAggregate\\b|Serializable\\b|Stringable\\b|Throwable\\b|Traversable\\b|UnitEnum\\b|__PHP_Incomplete_Class\\b|parent\\b|php_user_filter\\b|self\\b|static\\b)[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*(?![A-Za-z0-9])(?![$])[ \\t\\n]*(?=(?=\\())", + "end": "\\)", + "returnBegin": true, + "contains": [ + { + "className": "title invoke__", + "begin": "[a-zA-Z0-9_\\x7f-\\xff]\\w*", + "relevance": 0 + }, + { + "begin": "\\(", + "endsWithParent": true, + "keywords": "array bool boolean float int integer new real string false FALSE null NULL true TRUE PHP_VERSION PHP_MAJOR_VERSION PHP_MINOR_VERSION PHP_RELEASE_VERSION PHP_VERSION_ID PHP_EXTRA_VERSION ZEND_THREAD_SAFE ZEND_DEBUG_BUILD PHP_ZTS PHP_DEBUG PHP_MAXPATHLEN PHP_OS PHP_OS_FAMILY PHP_SAPI PHP_EOL PHP_INT_MAX PHP_INT_MIN PHP_INT_SIZE PHP_FLOAT_DIG PHP_FLOAT_EPSILON PHP_FLOAT_MIN PHP_FLOAT_MAX DEFAULT_INCLUDE_PATH PEAR_INSTALL_DIR PEAR_EXTENSION_DIR PHP_EXTENSION_DIR PHP_PREFIX PHP_BINDIR PHP_BINARY PHP_MANDIR PHP_LIBDIR PHP_DATADIR PHP_SYSCONFDIR PHP_LOCALSTATEDIR PHP_CONFIG_FILE_PATH PHP_CONFIG_FILE_SCAN_DIR PHP_SHLIB_SUFFIX PHP_FD_SETSIZE E_ERROR E_WARNING E_PARSE E_NOTICE E_CORE_ERROR E_CORE_WARNING E_COMPILE_ERROR E_COMPILE_WARNING E_USER_ERROR E_USER_WARNING E_USER_NOTICE E_RECOVERABLE_ERROR E_DEPRECATED E_USER_DEPRECATED E_ALL E_STRICT __COMPILER_HALT_OFFSET__ PHP_WINDOWS_EVENT_CTRL_C PHP_WINDOWS_EVENT_CTRL_BREAK PHP_CLI_PROCESS_TITLE STDERR STDIN STDOUT __CLASS__ __DIR__ __FILE__ __FUNCTION__ __LINE__ __METHOD__ __NAMESPACE__ __TRAIT__", + "contains": [ + { + "className": "attr", + "begin": "[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*(?![A-Za-z0-9])(?![$])(?=:)(?=(?!::))" + }, + { + "variants": [ + { + "begin": "::(?=(?!class\\b))[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*(?![A-Za-z0-9])(?![$])\\b(?!\\()", + "returnBegin": true, + "contains": [ + { + "begin": "::" + }, + { + "className": "variable constant_", + "begin": "[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*(?![A-Za-z0-9])(?![$])\\b(?!\\()" + } + ] + }, + { + "begin": "::class", + "returnBegin": true, + "contains": [ + { + "begin": "::" + }, + { + "className": "variable language_", + "begin": "class" + } + ] + } + ] + }, + { + "$ref": "#contains.8", + "_": "variable" + }, + { + "$ref": "#contains.3", + "_": "comment" + }, + { + "$ref": "#contains.4", + "_": "comment" + }, + { + "$ref": "#contains.5", + "_": "comment" + }, + { + "$ref": "#contains.10.contains.3.contains.3", + "_": "string" + }, + { + "$ref": "#contains.10.contains.3.contains.4", + "_": "number" + }, + { + "$ref": "#contains.10", + "_": "closure" + }, + { + "$ref": "#contains.9", + "_": "invoke" + } + ] + } + ] }, { "className": "function", - "beginKeywords": "function", + "beginKeywords": "fn function", "end": "[;{]", "excludeEnd": true, "illegal": "\\$|\\[|%", "contains": [ + { + "beginKeywords": "use" + }, { "className": "title", "begin": "[a-zA-Z_]\\w*", "relevance": 0 }, + { + "begin": "=>", + "endsParent": true + }, { "className": "params", "begin": "\\(", "end": "\\)", - "keywords": "true false null new array", + "keywords": "array bool boolean callable float int integer iterable mixed never numeric object private protected public real string resource self static false FALSE null NULL true TRUE", "contains": [ "self", { - "$ref": "#contains.8" + "$ref": "#contains.8", + "_": "variable" }, { - "className": "comment", - "begin": "/\\*", - "end": "\\*/", - "contains": [ - { - "$ref": "#contains.1.contains.0" - }, - { - "className": "doctag", - "begin": "(?:TODO|FIXME|NOTE|BUG|XXX):", - "relevance": 0 - } - ] + "$ref": "#contains.5", + "_": "comment" }, { "className": "string", "contains": [ { - "$ref": "#contains.5.contains.0" + "$ref": "#contains.6.contains.0" }, { - "$ref": "#contains.2.contains.0" + "$ref": "#contains.3.contains.0" } ], "variants": [ @@ -199,7 +295,7 @@ "illegal": null, "contains": [ { - "$ref": "#contains.5.contains.0" + "$ref": "#contains.6.contains.0" } ] }, @@ -210,7 +306,7 @@ "illegal": null, "contains": [ { - "$ref": "#contains.5.contains.0" + "$ref": "#contains.6.contains.0" }, { "className": "subst", @@ -239,23 +335,44 @@ "relevance": 0 } ] + }, + { + "$ref": "#contains.0", + "_": "simple-attribute" + }, + { + "$ref": "#contains.1", + "_": "attribute" } ] } ] }, + { + "$ref": "#contains.9.contains.1.contains.1", + "_": "constant" + }, { "className": "class", - "beginKeywords": "class interface trait enum", - "end": "{", + "variants": [ + { + "beginKeywords": "enum", + "illegal": "[($\"]" + }, + { + "beginKeywords": "class interface trait", + "illegal": "[:($\"]" + } + ], + "end": "\\{", "excludeEnd": true, - "illegal": "[:\\(\\$\"]", "contains": [ { "beginKeywords": "extends implements" }, { - "$ref": "#contains.10.contains.0" + "$ref": "#contains.10.contains.1", + "_": "title" } ] }, @@ -265,7 +382,8 @@ "illegal": "[\\.']", "contains": [ { - "$ref": "#contains.10.contains.0" + "$ref": "#contains.10.contains.1", + "_": "title" } ] }, @@ -274,7 +392,8 @@ "end": ";", "contains": [ { - "$ref": "#contains.10.contains.0" + "$ref": "#contains.10.contains.1", + "_": "title" } ] }, @@ -282,10 +401,12 @@ "begin": "=>" }, { - "$ref": "#contains.10.contains.1.contains.3" + "$ref": "#contains.10.contains.3.contains.3", + "_": "string" }, { - "$ref": "#contains.10.contains.1.contains.4" + "$ref": "#contains.10.contains.3.contains.4", + "_": "number" } ] } 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/src/Templates/highlight.php/yaml.json b/src/Templates/highlight.php/yaml.json new file mode 100644 index 00000000..3db70a84 --- /dev/null +++ b/src/Templates/highlight.php/yaml.json @@ -0,0 +1,127 @@ +{ + "case_insensitive": true, + "aliases": [ + "yml", + "YAML", + "yaml" + ], + "contains": [ + { + "className": "attr", + "variants": [ + { + "begin": "\\w[\\w :\\\/.-]*:(?=[ \t]|$)" + }, + { + "begin": "\"\\w[\\w :\\\/.-]*\":(?=[ \t]|$)" + }, + { + "begin": "'\\w[\\w :\\\/.-]*':(?=[ \t]|$)" + } + ] + }, + { + "className": "meta", + "begin": "^---s*$", + "relevance": 10 + }, + { + "className": "string", + "begin": "[\\|>]([0-9]?[+-])?[ ]*\\n( *)[\\S ]+\\n(\\2[\\S ]+\\n?)*" + }, + { + "begin": "<%[%=-]?", + "end": "[%-]?%>", + "subLanguage": "ruby", + "excludeBegin": true, + "excludeEnd": true, + "relevance": 0 + }, + { + "className": "type", + "begin": "![a-zA-Z_]\\w*" + }, + { + "className": "type", + "begin": "!![a-zA-Z_]\\w*" + }, + { + "className": "meta", + "begin": "&[a-zA-Z_]\\w*$" + }, + { + "className": "meta", + "begin": "\\*[a-zA-Z_]\\w*$" + }, + { + "className": "bullet", + "begin": "\\-(?=[ ]|$)", + "relevance": 0 + }, + { + "className": "comment", + "begin": "#", + "end": "$", + "contains": [ + { + "begin": "\\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\\b" + }, + { + "className": "doctag", + "begin": "(?:TODO|FIXME|NOTE|BUG|XXX):", + "relevance": 0 + } + ] + }, + { + "beginKeywords": "true false yes no null", + "keywords": { + "literal": "true false yes no null" + } + }, + { + "className": "number", + "begin": "\\b([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(([Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(\\.([0-9]*))?([ \\t]*(Z|([-+])([0-9][0-9]?)(:([0-9][0-9]))?))?)?\\b" + }, + { + "className": "number", + "begin": "(-?)(\\b0[xX][a-fA-F0-9_]+|(\\b\\d[\\d_]*(\\.[\\d_]*)?|\\.\\d[\\d_]*)([eE][-+]?\\d[\\d_]*)?)\\b" + }, + { + "className": "string", + "relevance": 0, + "variants": [ + { + "begin": "'", + "end": "'" + }, + { + "begin": "\"", + "end": "\"" + }, + { + "begin": "\\S+" + } + ], + "contains": [ + { + "begin": "\\\\[\\s\\S]", + "relevance": 0 + }, + { + "className": "template-variable", + "variants": [ + { + "begin": "{{", + "end": "}}" + }, + { + "begin": "%{", + "end": "}" + } + ] + } + ] + } + ] +} diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 69b36815..07f37338 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -115,8 +115,8 @@ public function testParseUnitBlock(string $blockName) $expected = preg_replace('/<\!\-\- REMOVE(.)+\-\->/', '', $expected); $this->assertSame( - $indenter->indent($expected), - $indenter->indent(trim($actualCrawler->filter('body')->html())) + $this->normalize($indenter->indent($expected)), + $this->normalize($indenter->indent(trim($actualCrawler->filter('body')->html()))) ); } @@ -142,6 +142,10 @@ public function parserUnitBlockProvider() 'blockName' => 'nodes/span-link', ]; + yield 'text' => [ + 'blockName' => 'nodes/text', + ]; + yield 'title' => [ 'blockName' => 'nodes/title', ]; @@ -294,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', ]; @@ -351,6 +359,11 @@ public function testParseString() $this->assertSame($htmlString, (new DocBuilder())->buildString($rstString)->getStringResult()); } + private function normalize(string $str): string + { + return preg_replace('/\s+$/m', '', $str); + } + private function createIndenter(): Indenter { $indenter = new Indenter(); diff --git a/tests/Templates/fixtures/php.output.html b/tests/Templates/fixtures/php.output.html index b8a1b330..2ce6dcb3 100644 --- a/tests/Templates/fixtures/php.output.html +++ b/tests/Templates/fixtures/php.output.html @@ -11,10 +11,10 @@ * * @Route("/blog/{slug}", name="blog_list") */ - public function list(UrlGeneratorInterface $urlGenerator, string $slug) + public function list(UrlGeneratorInterface $urlGenerator, string $slug) { - return $this->render('foo/bar.html.twig', [ - 'key' => $value + return $this->render('foo/bar.html.twig', [ + 'key' => $value ] } } \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/code-blocks/php-attributes.html b/tests/fixtures/expected/blocks/code-blocks/php-attributes.html index 541681cd..363b21f4 100644 --- a/tests/fixtures/expected/blocks/code-blocks/php-attributes.html +++ b/tests/fixtures/expected/blocks/code-blocks/php-attributes.html @@ -1,4 +1,4 @@ -
+
1
 2
@@ -53,7 +53,18 @@
 51
 52
 53
-54
+54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65
             
                 // src/SomePath/SomeClass.php
@@ -64,77 +75,87 @@
                     SomeClass
                 
                 {
-                #[AttributeName]
+                #[AttributeName]
                 private
                 
                     $ property1
                 ;
-                #[AttributeName()]
+                #[AttributeName()]
                 private
                 
                     $ property2
                 ;
-                #[AttributeName('value')]
+                #[AttributeName('value')]
                 private
                 
                     $ property3
                 ;
-                #[AttributeName('value', option: 'value')]
+                #[AttributeName('value', option: 'value')]
                 private
                 
                     $ property4
                 ;
-                #[AttributeName(['value' => 'value'])]
+                #[AttributeName(['value' => 'value'])]
                 private
                 
                     $ property5
                 ;
-                #[AttributeName(
+                #[AttributeName(
                     'value',
-                    option: 'value'
-                )]
+                    option: 'value'
+                )]
                 private
                 
                     $ property6
                 ;
-                #[Assert\AttributeName('value')]
+                #[Assert\AttributeName('value')]
                 private
                 
                     $ property7
                 ;
-                #[Assert\AttributeName(
+                #[Assert\AttributeName(
                     'value',
-                    option: 'value'
-                )]
+                    option: 'value'
+                )]
                 private
                 
                     $ property8
                 ;
-                #[Route('/blog/{page<\d+>}', name: 'blog_list')]
+                #[Route('/blog/{page<\d+>}', name: 'blog_list')]
                 private
                 
                 $ property9
                 ;
-                #[Assert\GreaterThanOrEqual(
-                    value: 18,
-                )]
+                #[Assert\GreaterThanOrEqual(
+                    value: 18,
+                )]
                 private
                 
                 $ property10
                 ;
-                #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
+                #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
                 private
                 
                 $ property11
                 ;
-                #[Assert\AtLeastOneOf([
-                    new Assert\Regex('/#/'),
-                    new Assert\Length(min: 10),
-                ])]
+                #[Assert\AtLeastOneOf([
+                    new Assert\Regex('/#/'),
+                    new Assert\Length(min: 10),
+                ])]
                 private
                 
                 $ property12
                 ;
+                public function __construct(
+                        #[TaggedIterator('app.handlers')]
+                        iterable $handlers,
+                ){
+                }
+
+                #[AsController]
+                public functionsomeAction(#[CurrentUser] User $user)
+                {
+                }
 }
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/php.html b/tests/fixtures/expected/blocks/code-blocks/php.html index c005a13d..163de59a 100644 --- a/tests/fixtures/expected/blocks/code-blocks/php.html +++ b/tests/fixtures/expected/blocks/code-blocks/php.html @@ -1,4 +1,4 @@ -
+
1
 2
@@ -6,13 +6,108 @@
 4
 5
 6
-7
+7 +8 +9
// config/routes.php
 namespace Symfony\Component\Routing\Loader\Configurator;
 
-return function (RoutingConfigurator $routes) {
-    $routes->add('about_us', ['nl' => '/over-ons', 'en' => '/about-us'])
-        ->controller('App\Controller\CompanyController::about');
+    use App\Controller\CompanyController;
+
+return static function (RoutingConfigurator $routes): void {
+    $routes->add('about_us', ['nl' => '/over-ons', 'en' => '/about-us'])
+        ->controller(CompanyController::class.'::about');
 };
+
+
+
1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+

+enum TextAlign: string implements TranslatableInterface
+{
+    case Left = 'Left aligned';
+    case Center = 'Center aligned';
+    case Right = 'Right aligned';
+
+    public function trans(TranslatorInterface $translator, ?string $locale = null): string
+    {
+        // Translate enum using custom labels
+        return match ($this) {
+            self::Left => $translator->trans('text_align.left.label', locale: $locale),
+            self::Center => $translator->trans('text_align.center.label', locale: $locale),
+            self::Right => $translator->trans('text_align.right.label', locale: $locale),
+        };
+    }
+}
+            
+        
+
+
+
+
+
1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+

+public function getUserBadgeFrom(string $accessToken): UserBadge
+{
+    // get the data from the token
+    $payload = ...;
+
+    return new UserBadge(
+        $payload->getUserId(),
+        fn (string $userIdentifier): User => new User($userIdentifier, $payload->getRoles())
+    );
+
+    // or
+    return new UserBadge(
+        $payload->getUserId(),
+        $this->loadUser(...)
+    );
+}
+        
+
+
+
+
+
1
+2
+3
+4
+

+public function __construct(
+    private string $username
+) {
+}
+        
+
+
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/code-blocks/yaml.html b/tests/fixtures/expected/blocks/code-blocks/yaml.html index fceca11e..2de3b7b2 100644 --- a/tests/fixtures/expected/blocks/code-blocks/yaml.html +++ b/tests/fixtures/expected/blocks/code-blocks/yaml.html @@ -1,7 +1,36 @@ -
+
-
1
-
# some code
-
+
1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+
+            
+                # some code
+                parameters:
+                credit_card_number:
+                1234_5678_9012_3456
+                long_number:
+                10_000_000_000
+                pi:
+                3.14159_26535_89793
+                hex_words:
+                0x_CAFE_F00D
+                canonical:
+                2001-12-15T02:59:43.1Z
+                iso8601:
+                2001-12-14t21:59:43.10-05:00
+                spaced:
+                2001-12-14 21:59:43.10 -5
+                date:
+                2002-12-14
+            
+        
diff --git a/tests/fixtures/expected/blocks/nodes/literal.html b/tests/fixtures/expected/blocks/nodes/literal.html index 1c12afae..28eb3bf8 100644 --- a/tests/fixtures/expected/blocks/nodes/literal.html +++ b/tests/fixtures/expected/blocks/nodes/literal.html @@ -12,8 +12,8 @@ namespace Symfony\Component\Routing\Loader\Configurator; return function (RoutingConfigurator $routes) { - $routes->add('about_us', ['nl' => '/over-ons', 'en' => '/about-us']) - ->controller('App\Controller\CompanyController::about'); + $routes->add('about_us', ['nl' => '/over-ons', 'en' => '/about-us']) + ->controller('App\Controller\CompanyController::about'); };
diff --git a/tests/fixtures/expected/blocks/nodes/text.html b/tests/fixtures/expected/blocks/nodes/text.html new file mode 100644 index 00000000..afc3337c --- /dev/null +++ b/tests/fixtures/expected/blocks/nodes/text.html @@ -0,0 +1,7 @@ +

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut enim ad minim +veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea +commodo consequat. Duis aute irure dolor in reprehenderit in voluptate +velit esse cillum dolore eu fugiat nulla pariatur.

+ +

Excepteur ~1,000 sint! Occaecat cupidatat non proident, sunt in culpa qui officia +deserunt mollit anim id est laborum. áàâäãåéèêëíìîïóòôöõúùûüñçÿ

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/build-pdf/book.html b/tests/fixtures/expected/build-pdf/book.html index a2144636..4454f945 100644 --- a/tests/fixtures/expected/build-pdf/book.html +++ b/tests/fixtures/expected/build-pdf/book.html @@ -8,8 +8,8 @@

Book

Here is a link to the main index

diff --git a/tests/fixtures/expected/main/datetime.html b/tests/fixtures/expected/main/datetime.html index c1ea0890..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().

@@ -143,12 +143,10 @@

$ builder - -> - add( + -> + add( 'startDateTime' - , DateTimeType - :: - class, + , DateTimeType::class, array ( 'placeholder' @@ -417,8 +415,8 @@

$ container - -> - loadFromExtension( + -> + loadFromExtension( 'framework' , array diff --git a/tests/fixtures/expected/main/index.html b/tests/fixtures/expected/main/index.html index 13463739..628cc916 100644 --- a/tests/fixtures/expected/main/index.html +++ b/tests/fixtures/expected/main/index.html @@ -10,7 +10,7 @@

Some Test Docs!

- +

A header

diff --git a/tests/fixtures/expected/toctree/index.html b/tests/fixtures/expected/toctree/index.html index e07a28e7..676005ad 100644 --- a/tests/fixtures/expected/toctree/index.html +++ b/tests/fixtures/expected/toctree/index.html @@ -9,11 +9,11 @@ diff --git a/tests/fixtures/source/blocks/code-blocks/php-attributes.rst b/tests/fixtures/source/blocks/code-blocks/php-attributes.rst index 31b5f998..808e6c45 100644 --- a/tests/fixtures/source/blocks/code-blocks/php-attributes.rst +++ b/tests/fixtures/source/blocks/code-blocks/php-attributes.rst @@ -53,4 +53,15 @@ new Assert\Length(min: 10), ])] private $property12; + + public function __construct( + #[TaggedIterator('app.handlers')] + iterable $handlers, + ) { + } + + #[AsController] + public function someAction(#[CurrentUser] User $user) + { + } } 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/php.rst b/tests/fixtures/source/blocks/code-blocks/php.rst index e9d65938..33ed08e6 100644 --- a/tests/fixtures/source/blocks/code-blocks/php.rst +++ b/tests/fixtures/source/blocks/code-blocks/php.rst @@ -1,9 +1,56 @@ - .. code-block:: php + // config/routes.php namespace Symfony\Component\Routing\Loader\Configurator; - return function (RoutingConfigurator $routes) { + use App\Controller\CompanyController; + + return static function (RoutingConfigurator $routes): void { $routes->add('about_us', ['nl' => '/over-ons', 'en' => '/about-us']) - ->controller('App\Controller\CompanyController::about'); + ->controller(CompanyController::class.'::about'); }; + +.. code-block:: php + + enum TextAlign: string implements TranslatableInterface + { + case Left = 'Left aligned'; + case Center = 'Center aligned'; + case Right = 'Right aligned'; + + public function trans(TranslatorInterface $translator, ?string $locale = null): string + { + // Translate enum using custom labels + return match ($this) { + self::Left => $translator->trans('text_align.left.label', locale: $locale), + self::Center => $translator->trans('text_align.center.label', locale: $locale), + self::Right => $translator->trans('text_align.right.label', locale: $locale), + }; + } + } + +.. code-block:: php + + public function getUserBadgeFrom(string $accessToken): UserBadge + { + // get the data from the token + $payload = ...; + + return new UserBadge( + $payload->getUserId(), + fn (string $userIdentifier): User => new User($userIdentifier, $payload->getRoles()) + ); + + // or + return new UserBadge( + $payload->getUserId(), + $this->loadUser(...) + ); + } + +.. code-block:: php + + public function __construct( + private string $username + ) { + } 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/code-blocks/yaml.rst b/tests/fixtures/source/blocks/code-blocks/yaml.rst index 45ce98d5..f56652d3 100644 --- a/tests/fixtures/source/blocks/code-blocks/yaml.rst +++ b/tests/fixtures/source/blocks/code-blocks/yaml.rst @@ -1,3 +1,12 @@ .. code-block:: yaml # some code + parameters: + credit_card_number: 1234_5678_9012_3456 + long_number: 10_000_000_000 + pi: 3.14159_26535_89793 + hex_words: 0x_CAFE_F00D + canonical: 2001-12-15T02:59:43.1Z + iso8601: 2001-12-14t21:59:43.10-05:00 + spaced: 2001-12-14 21:59:43.10 -5 + date: 2002-12-14 diff --git a/tests/fixtures/source/blocks/nodes/text.rst b/tests/fixtures/source/blocks/nodes/text.rst new file mode 100644 index 00000000..f5dbb33e --- /dev/null +++ b/tests/fixtures/source/blocks/nodes/text.rst @@ -0,0 +1,7 @@ +**Lorem ipsum** dolor sit amet, consectetur adipisicing elit. Ut enim ad minim +veniam, quis nostrud *exercitation ullamco laboris* nisi ut aliquip ex ea +commodo consequat. ``Duis aute irure dolor`` in reprehenderit in voluptate +velit esse cillum dolore eu fugiat nulla pariatur. + +Excepteur ~1,000 sint! Occaecat cupidatat non proident, sunt in culpa qui officia +deserunt mollit anim id est laborum. áàâäãåéèêëíìîïóòôöõúùûüñçÿ 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`