From e22c8625235cb74c3ec11720a6df1a8024b8b84a Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 12 Mar 2021 12:36:12 +0100 Subject: [PATCH 1/4] Tweak the code blocks --- src/Renderers/CodeNodeRenderer.php | 38 ++++++++++------------- src/Templates/default/html/code.html.twig | 20 +++--------- 2 files changed, 21 insertions(+), 37 deletions(-) diff --git a/src/Renderers/CodeNodeRenderer.php b/src/Renderers/CodeNodeRenderer.php index 5180e47..91bead8 100644 --- a/src/Renderers/CodeNodeRenderer.php +++ b/src/Renderers/CodeNodeRenderer.php @@ -53,43 +53,39 @@ public function __construct(CodeNode $codeNode, TemplateRenderer $templateRender public function render(): string { - $this->configureHighlighter(); - - $value = $this->codeNode->getValue(); - + $code = $this->codeNode->getValue(); if ($this->codeNode->isRaw()) { - return $value; - } - - $lines = $this->getLines($value); - $code = implode("\n", $lines); - - $lineNumbers = ''; - for ($i = 1; $i <= \count($lines); ++$i) { - $lineNumbers .= u((string) $i)->padStart(2, ' ')."\n"; + return $code; } $language = $this->codeNode->getLanguage() ?? 'php'; + $languageMapping = self::LANGUAGES_MAPPING[$language] ?? $language; + $languages = array_unique([$language, $languageMapping]); + + if ('text' === $language) { + $highlightedCode = $code; + } else { + $this->configureHighlighter(); - if ('text' !== $language) { $highLighter = new Highlighter(); - $code = $highLighter->highlight(self::LANGUAGES_MAPPING[$language] ?? $language, $code)->value; + $highlightedCode = $highLighter->highlight($languageMapping, $code)->value; // this allows to highlight the $ in PHP variable names - $code = str_replace('$', '$', $code); + $highlightedCode = str_replace('$', '$', $highlightedCode); } + $numOfLines = \count(preg_split('/\r\n|\r|\n/', $highlightedCode)); + return $this->templateRenderer->render( 'code.html.twig', [ - 'language' => $language, - 'languageMapping' => self::LANGUAGES_MAPPING[$language] ?? $language, - 'code' => $code, - 'lineNumbers' => rtrim($lineNumbers), + 'languages' => $languages, + 'lines' => range(1, $numOfLines - 1), + 'code' => $highlightedCode, // this is the number of digits of the codeblock lines-of-code // e.g. LOC = 5, digits = 1; LOC = 18, digits = 2 // this is useful to tweak the code listings according to their length - 'numLocDigits' => strlen((string) \count($lines)), + 'numLocDigits' => strlen((string) $numOfLines), ] ); } diff --git a/src/Templates/default/html/code.html.twig b/src/Templates/default/html/code.html.twig index 7a1f9ba..b01ccee 100644 --- a/src/Templates/default/html/code.html.twig +++ b/src/Templates/default/html/code.html.twig @@ -1,18 +1,6 @@ -
-
- - - - - -
-
-
{{ lineNumbers }}
-
-
-
-
{{ code|raw }}
-
-
+
+
+
{{ lines|join("\n") }}
+
{{ code|raw }}
From 65c7eadbbe377a0a5fc9b7b7bec50e4f0e182a78 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Sat, 13 Mar 2021 12:20:08 +0100 Subject: [PATCH 2/4] Fixed tests --- .../expected/blocks/code-blocks/bash.html | 37 +- .../expected/blocks/code-blocks/html-php.html | 65 +- .../blocks/code-blocks/html-twig.html | 43 +- .../expected/blocks/code-blocks/html.html | 37 +- .../expected/blocks/code-blocks/ini.html | 37 +- .../blocks/code-blocks/php-annotations.html | 65 +- .../expected/blocks/code-blocks/php.html | 63 +- .../expected/blocks/code-blocks/terminal.html | 37 +- .../expected/blocks/code-blocks/text.html | 37 +- .../expected/blocks/code-blocks/twig.html | 37 +- .../expected/blocks/code-blocks/xml.html | 37 +- .../expected/blocks/code-blocks/yaml.html | 37 +- .../blocks/directives/admonition.html | 23 +- .../blocks/directives/best-practice.html | 23 +- .../expected/blocks/directives/caution.html | 27 +- .../expected/blocks/directives/class.html | 23 +- .../directives/configuration-block.html | 73 +- .../directives/note-code-block-nested.html | 50 +- .../expected/blocks/directives/note.html | 27 +- .../expected/blocks/directives/seealso.html | 23 +- .../directives/sidebar-code-block-nested.html | 47 +- .../expected/blocks/directives/sidebar.html | 24 +- .../expected/blocks/directives/tip.html | 27 +- .../expected/blocks/directives/topic.html | 21 +- .../blocks/directives/versionadded.html | 22 +- .../fixtures/expected/blocks/nodes/list.html | 26 +- .../expected/blocks/nodes/literal.html | 65 +- .../expected/blocks/nodes/tables.html | 164 ++-- .../expected/blocks/references/class.html | 18 +- .../expected/blocks/references/method.html | 18 +- .../expected/blocks/references/namespace.html | 18 +- .../expected/blocks/references/php-class.html | 18 +- .../blocks/references/php-function.html | 18 +- .../blocks/references/php-method.html | 18 +- .../expected/doc-reference/index.html | 25 +- tests/fixtures/expected/main/datetime.html | 709 +++++++----------- .../expected/main/form/form_type.html | 22 +- tests/fixtures/expected/main/index.html | 44 +- .../expected/ref-reference/index.html | 25 +- tests/fixtures/expected/toctree/index.html | 65 +- 40 files changed, 976 insertions(+), 1219 deletions(-) diff --git a/tests/fixtures/expected/blocks/code-blocks/bash.html b/tests/fixtures/expected/blocks/code-blocks/bash.html index f1aaa7c..1161c18 100644 --- a/tests/fixtures/expected/blocks/code-blocks/bash.html +++ b/tests/fixtures/expected/blocks/code-blocks/bash.html @@ -1,26 +1,19 @@ - - - - -
-
- - - - - -
-
-
 1
-
-
-
-
git clone git@github.com:symfony/symfony.git
-
-
+ + + + + + + +
+
+
1
+
git clone git@github.com:symfony/symfony.git
+
- - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/code-blocks/html-php.html b/tests/fixtures/expected/blocks/code-blocks/html-php.html index d4ebdc2..786d4c9 100644 --- a/tests/fixtures/expected/blocks/code-blocks/html-php.html +++ b/tests/fixtures/expected/blocks/code-blocks/html-php.html @@ -1,42 +1,41 @@ - - - - -
-
- - - - - -
-
-
 1 2 3 4 5 6 7 8 9
+    
+        
+
+            
+    
+
+    
+            
+
+
1
+2
+3
+4
+5
+6
+7
+8
+9
 10
 11
 12
-
-
-
-
-                            <!-- views/layout.php -->
+        
<!-- views/layout.php -->
 <!doctype html>
 <html>
-                            <head>
-                            <title>
-                            <?php echo 'title'; ?>
-                            </title>
-                            </head>
-                            <body>
-                            <?php echo 'body'; ?>
-                            </body>
-                            </html>
-                        
-
-
+ <head> + <title> + <?php echo 'title'; ?> + </title> + </head> + <body> + <?php echo 'body'; ?> + </body> +</html> +
- - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/code-blocks/html-twig.html b/tests/fixtures/expected/blocks/code-blocks/html-twig.html index 9d7ed91..0aafd23 100644 --- a/tests/fixtures/expected/blocks/code-blocks/html-twig.html +++ b/tests/fixtures/expected/blocks/code-blocks/html-twig.html @@ -1,30 +1,21 @@ - - - - -
-
- - - - - -
-
-
 1 2
-
-
-
-
-                            {# some code #}
-                            
-<!-- some code -->
-                        
-
-
+ + + + + + + +
+
+
1
+2
+
{# some code #}
+<!-- some code -->
+
- - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/code-blocks/html.html b/tests/fixtures/expected/blocks/code-blocks/html.html index d3bd004..4261a2e 100644 --- a/tests/fixtures/expected/blocks/code-blocks/html.html +++ b/tests/fixtures/expected/blocks/code-blocks/html.html @@ -1,26 +1,19 @@ - - - - -
-
- - - - - -
-
-
 1
-
-
-
-
<!-- some code -->
-
-
+ + + + + + + +
+
+
1
+
<!-- some code -->
+
- - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/code-blocks/ini.html b/tests/fixtures/expected/blocks/code-blocks/ini.html index 127d00b..0f52ec4 100644 --- a/tests/fixtures/expected/blocks/code-blocks/ini.html +++ b/tests/fixtures/expected/blocks/code-blocks/ini.html @@ -1,26 +1,19 @@ - - - - -
-
- - - - - -
-
-
 1
-
-
-
-
fetch = +refs/notes/*:refs/notes/*
-
-
+ + + + + + + +
+
+
1
+
fetch = +refs/notes/*:refs/notes/*
+
- - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/code-blocks/php-annotations.html b/tests/fixtures/expected/blocks/code-blocks/php-annotations.html index fbbd85a..8a5d85c 100644 --- a/tests/fixtures/expected/blocks/code-blocks/php-annotations.html +++ b/tests/fixtures/expected/blocks/code-blocks/php-annotations.html @@ -1,40 +1,45 @@ - - - - -
-
- - - - - -
-
-
 1 2 3 4 5 6 7 8 9
+    
+        
+
+            
+    
+
+    
+            
+
+
1
+2
+3
+4
+5
+6
+7
+8
+9
 10
 11
 12
 13
 14
-
-
-
-
-                                    // src/AppBundle/Entity/Transaction.php
-namespace AppBundle\Entity; use Symfony\Component\Validator\Constraints as Assert;
-                                    class Transaction
-
-                                    {
-                                    /** * @Assert\Iban( * message="This is not a valid International Bank Account Number (IBAN)." * ) */
-                                    protected $bankAccountNumber;
+        
// src/AppBundle/Entity/Transaction.php
+namespace AppBundle\Entity;
+
+use Symfony\Component\Validator\Constraints as Assert;
+
+class Transaction
+{
+    /**
+     * @Assert\Iban(
+     *     message="This is not a valid International Bank Account Number (IBAN)."
+     * )
+     */
+    protected $bankAccountNumber;
 }
-                                
-
-
+
- - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/code-blocks/php.html b/tests/fixtures/expected/blocks/code-blocks/php.html index 2820de9..5880771 100644 --- a/tests/fixtures/expected/blocks/code-blocks/php.html +++ b/tests/fixtures/expected/blocks/code-blocks/php.html @@ -1,40 +1,31 @@ - - - - -
-
- - - - - -
-
-
 1
- 2
- 3
- 4
- 5
- 6
- 7
-
-
-
-
-                                    // 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');
-};
-
-
+ + + + + + + +
+
+
1
+2
+3
+4
+5
+6
+7
+
// 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');
+};
+
- - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/code-blocks/terminal.html b/tests/fixtures/expected/blocks/code-blocks/terminal.html index 4ebc77b..6bde18a 100644 --- a/tests/fixtures/expected/blocks/code-blocks/terminal.html +++ b/tests/fixtures/expected/blocks/code-blocks/terminal.html @@ -1,26 +1,19 @@ - - - - -
-
- - - - - -
-
-
 1
-
-
-
-
git clone git@github.com:symfony/symfony.git
-
-
+ + + + + + + +
+
+
1
+
git clone git@github.com:symfony/symfony.git
+
- - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/code-blocks/text.html b/tests/fixtures/expected/blocks/code-blocks/text.html index 63b9988..8980981 100644 --- a/tests/fixtures/expected/blocks/code-blocks/text.html +++ b/tests/fixtures/expected/blocks/code-blocks/text.html @@ -1,26 +1,19 @@ - - - - -
-
- - - - - -
-
-
 1
-
-
-
-
some text
-
-
+ + + + + + + +
+
+
1
+
some text
+
- - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/code-blocks/twig.html b/tests/fixtures/expected/blocks/code-blocks/twig.html index cc0ec14..2e42e64 100644 --- a/tests/fixtures/expected/blocks/code-blocks/twig.html +++ b/tests/fixtures/expected/blocks/code-blocks/twig.html @@ -1,26 +1,19 @@ - - - - -
-
- - - - - -
-
-
 1
-
-
-
-
{# some code #}
-
-
+ + + + + + + +
+
+
1
+
{# some code #}
+
- - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/code-blocks/xml.html b/tests/fixtures/expected/blocks/code-blocks/xml.html index 5ba803e..c1c05de 100644 --- a/tests/fixtures/expected/blocks/code-blocks/xml.html +++ b/tests/fixtures/expected/blocks/code-blocks/xml.html @@ -1,26 +1,19 @@ - - - - -
-
- - - - - -
-
-
 1
-
-
-
-
<!-- some code -->
-
-
+ + + + + + + +
+
+
1
+
<!-- some code -->
+
- - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/code-blocks/yaml.html b/tests/fixtures/expected/blocks/code-blocks/yaml.html index 68e841a..13e8608 100644 --- a/tests/fixtures/expected/blocks/code-blocks/yaml.html +++ b/tests/fixtures/expected/blocks/code-blocks/yaml.html @@ -1,26 +1,19 @@ - - - - -
-
- - - - - -
-
-
 1
-
-
-
-
# some code
-
-
+ + + + + + + +
+
+
1
+
# some code
+
- - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/directives/admonition.html b/tests/fixtures/expected/blocks/directives/admonition.html index 724d693..5c67841 100644 --- a/tests/fixtures/expected/blocks/directives/admonition.html +++ b/tests/fixtures/expected/blocks/directives/admonition.html @@ -1,12 +1,17 @@ - - - - -
-

Screencast

-

Do you prefer video tutorials? Check out the the screencasts.

+ + + + + + + +
+

+ Screencast +

Do you prefer video tutorials? Check out the the screencasts.

- - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/directives/best-practice.html b/tests/fixtures/expected/blocks/directives/best-practice.html index 4188e35..1ed1305 100644 --- a/tests/fixtures/expected/blocks/directives/best-practice.html +++ b/tests/fixtures/expected/blocks/directives/best-practice.html @@ -1,12 +1,17 @@ - - - - -
-

Best Practice

-

Use the bcrypt encoder for hashing your users' passwords.

+ + + + + + + +
+

+ Best Practice +

Use the bcrypt encoder for hashing your users' passwords.

- - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/directives/caution.html b/tests/fixtures/expected/blocks/directives/caution.html index ac8a770..457b6b8 100644 --- a/tests/fixtures/expected/blocks/directives/caution.html +++ b/tests/fixtures/expected/blocks/directives/caution.html @@ -1,17 +1,18 @@ - - - - -
+ + + + + + + +

- - - - Caution -

-

Using too many sidebars or caution directives can be distracting!

+ + Caution +

Using too many sidebars or caution directives can be distracting!

- - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/directives/class.html b/tests/fixtures/expected/blocks/directives/class.html index edab3cb..596dfda 100644 --- a/tests/fixtures/expected/blocks/directives/class.html +++ b/tests/fixtures/expected/blocks/directives/class.html @@ -1,15 +1,18 @@ - - - - -
    -
  • list-item-1
  • -
  • list-item-2
  • -
  • list-item-3
  • + + + + + + + +
    • list-item-1
    • +
    • list-item-2
    • +
    • list-item-3

    some text

    - - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/directives/configuration-block.html b/tests/fixtures/expected/blocks/directives/configuration-block.html index 9c740b8..7d6505d 100644 --- a/tests/fixtures/expected/blocks/directives/configuration-block.html +++ b/tests/fixtures/expected/blocks/directives/configuration-block.html @@ -1,46 +1,35 @@ - - - - -
    • YAML
      -
      - - - - - -
      -
      -
       1
      -
      -
      -
      -
      # app/config/services.yml
      -
      -
      + + + + + + + +
      +
        +
      • + YAML +
        +
        +
        1
        +
        # app/config/services.yml
        +
        -
      • PHP
        -
        - - - - - -
        -
        -
         1
        -
        -
        -
        -
        // config/routes.php
        -
        -
        -
        -
        -
      • -
      - - +
    • +
    • + PHP +
      +
      +
      1
      +
      // config/routes.php
      +
      +
      +
      +
    • +
    + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/directives/note-code-block-nested.html b/tests/fixtures/expected/blocks/directives/note-code-block-nested.html index ae061ca..d3ff26e 100644 --- a/tests/fixtures/expected/blocks/directives/note-code-block-nested.html +++ b/tests/fixtures/expected/blocks/directives/note-code-block-nested.html @@ -1,35 +1,25 @@ - - - - -
    + + + + + + + +

    - - - - Note -

    -

    test

    -
    -
    - - - - - -
    -
    -
     1
    -
    -
    -
    -
    // code
    -
    -
    -
    + + Note +

    test

    +
    +
    +
    1
    +
    // code
    +
    - - +
    + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/directives/note.html b/tests/fixtures/expected/blocks/directives/note.html index 84bed1c..e056eaa 100644 --- a/tests/fixtures/expected/blocks/directives/note.html +++ b/tests/fixtures/expected/blocks/directives/note.html @@ -1,17 +1,18 @@ - - - - -
    + + + + + + + +

    - - - - Note -

    -

    Sometimes we add notes. But not too often because they interrupt the flow.

    + + Note +

    Sometimes we add notes. But not too often because they interrupt the flow.

    - - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/directives/seealso.html b/tests/fixtures/expected/blocks/directives/seealso.html index 43d6607..30f8cfa 100644 --- a/tests/fixtures/expected/blocks/directives/seealso.html +++ b/tests/fixtures/expected/blocks/directives/seealso.html @@ -1,12 +1,17 @@ - - - - -
    -

    See also

    -

    Also check out the homepage

    + + + + + + + +
    +

    + See also +

    Also check out the homepage

    - - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/directives/sidebar-code-block-nested.html b/tests/fixtures/expected/blocks/directives/sidebar-code-block-nested.html index 09b7b10..8e67aaa 100644 --- a/tests/fixtures/expected/blocks/directives/sidebar-code-block-nested.html +++ b/tests/fixtures/expected/blocks/directives/sidebar-code-block-nested.html @@ -1,33 +1,22 @@ - - - - -
    -
    - -

    some text before code block

    -
    -
    - - - - - -
    -
    -
     1
    -
    -
    -
    -
    // some code
    -
    -
    -
    -
    -

    some text after code block

    + + + + + + + +

    some text before code block

    +
    +
    +
    1
    +
    // some code
    +
    - - +

    some text after code block

    +
    + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/directives/sidebar.html b/tests/fixtures/expected/blocks/directives/sidebar.html index 07cbc97..2952441 100644 --- a/tests/fixtures/expected/blocks/directives/sidebar.html +++ b/tests/fixtures/expected/blocks/directives/sidebar.html @@ -1,14 +1,14 @@ - - - - -
    -
    - -

    some text inside sidebar

    -
    -
    - - + + + + + + + +

    some text inside sidebar

    +
    + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/directives/tip.html b/tests/fixtures/expected/blocks/directives/tip.html index fe5f29a..a26576b 100644 --- a/tests/fixtures/expected/blocks/directives/tip.html +++ b/tests/fixtures/expected/blocks/directives/tip.html @@ -1,17 +1,18 @@ - - - - -
    + + + + + + + +

    - - - - Tip -

    -

    This is a little tip about something! We an also talk about specific

    + + Tip +

    This is a little tip about something! We an also talk about specific

    - - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/directives/topic.html b/tests/fixtures/expected/blocks/directives/topic.html index 09b15b4..16c4447 100644 --- a/tests/fixtures/expected/blocks/directives/topic.html +++ b/tests/fixtures/expected/blocks/directives/topic.html @@ -1,12 +1,15 @@ - - - - -
    -

    Example

    -

    Here is a sample comment for a bug report that could be reproduced.

    + + + + + + + +
    +

    Example

    Here is a sample comment for a bug report that could be reproduced.

    - - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/directives/versionadded.html b/tests/fixtures/expected/blocks/directives/versionadded.html index 6b0faf6..649ca33 100644 --- a/tests/fixtures/expected/blocks/directives/versionadded.html +++ b/tests/fixtures/expected/blocks/directives/versionadded.html @@ -1,14 +1,14 @@ - - - - -
    -
    - New in version 4.1: -

    This option was introduced in Symfony 2.6 and replaces another option, which is available prior to 2.6.

    -
    -
    - + + + + + + + +
    New in version 4.1:

    This option was introduced in Symfony 2.6 and replaces another option, which is available prior to 2.6.

    +
    + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/nodes/list.html b/tests/fixtures/expected/blocks/nodes/list.html index 710af9d..cc1fad6 100644 --- a/tests/fixtures/expected/blocks/nodes/list.html +++ b/tests/fixtures/expected/blocks/nodes/list.html @@ -1,14 +1,18 @@ - - - - -
      -
    • List item 1
    • -
    • List item 2
    • -
    • List item 3
    • -
    • List item 4
    • + + + + + + + +
      • List item 1
      • +
      • List item 2
      • +
      • List item 3
      • +
      • List item 4
      - - + + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/nodes/literal.html b/tests/fixtures/expected/blocks/nodes/literal.html index 8408c0e..d85a683 100644 --- a/tests/fixtures/expected/blocks/nodes/literal.html +++ b/tests/fixtures/expected/blocks/nodes/literal.html @@ -1,41 +1,32 @@ - - - - -

      here is some php code from literal:

      -
      -
      - - - - - -
      -
      -
       1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      -
      -
      -
      -
      -                                    // 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');
      -};
      -
      -
      + + + + + + + +

      here is some php code from literal:

      +
      +
      +
      1
      +2
      +3
      +4
      +5
      +6
      +7
      +
      // 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');
      +};
      +
      - - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/nodes/tables.html b/tests/fixtures/expected/blocks/nodes/tables.html index 021119c..ad008ea 100644 --- a/tests/fixtures/expected/blocks/nodes/tables.html +++ b/tests/fixtures/expected/blocks/nodes/tables.html @@ -1,94 +1,100 @@ - - - - - - - - - - - - + + + + + + + +
      Route pathIf the requested URL is /fooIf the requested URL is /foo/
      + + + + + + + + - - - - - - - - - - - + + + + + + + + + + +
      Route pathIf the requested URL is /fooIf the requested URL is /foo/
      /fooIt matches (200 status response)It doesn't match (404 status response)
      /foo/It makes a 301 redirect to /foo/It matches (200 status response)
      /fooIt matches (200 status response)It doesn't match (404 status response)
      /foo/It makes a 301 redirect to /foo/It matches (200 status response)
      + - - - - - - - - - - - + + + + + + + + + + - - + +
      Cell 1Cell 2
      Cell 3Cell 4
      Cell 5Cell 6 +
      Cell 1Cell 2
      Cell 3Cell 4
      Cell 5Cell 6 extra line
      - - - - - - + + + + + + + - - - - - - - + + + + + + - - + +
      Cell 1Cell 2
      Cell 1Cell 2
      Cell 3Cell 4
      Cell 5Cell 6 +
      Cell 3Cell 4
      Cell 5Cell 6 extra line
      - - - - - - + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + +
      Cell 1Cell 2
      Cell 1Cell 2
      Cell 3Cell 4
      Cell 5 -
        -
      • List item 1
      • -
      • List item 2
      • -
      • List item 3
      • -
      • List item 4
      • -
      -
      Cell 7Cell 8
      Cell 3Cell 4
      Cell 5
      • List item 1
      • +
      • List item 2
      • +
      • List item 3
      • +
      • List item 4
      • +
      +
      Cell 7Cell 8
      - - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/references/class.html b/tests/fixtures/expected/blocks/references/class.html index af0437d..74f2148 100644 --- a/tests/fixtures/expected/blocks/references/class.html +++ b/tests/fixtures/expected/blocks/references/class.html @@ -1,9 +1,13 @@ - - - - -

      ContainerAwareHttpKernel

      - - + + + + + + + +

      ContainerAwareHttpKernel

      + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/references/method.html b/tests/fixtures/expected/blocks/references/method.html index 5b4feee..09ddab7 100644 --- a/tests/fixtures/expected/blocks/references/method.html +++ b/tests/fixtures/expected/blocks/references/method.html @@ -1,9 +1,13 @@ - - - - -

      getCurrentRequest()

      - - + + + + + + + +

      getCurrentRequest()

      + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/references/namespace.html b/tests/fixtures/expected/blocks/references/namespace.html index 657da32..69b820c 100644 --- a/tests/fixtures/expected/blocks/references/namespace.html +++ b/tests/fixtures/expected/blocks/references/namespace.html @@ -1,9 +1,13 @@ - - - - -

      HttpFoundation

      - - + + + + + + + +

      HttpFoundation

      + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/references/php-class.html b/tests/fixtures/expected/blocks/references/php-class.html index 6fdc725..de4cdbc 100644 --- a/tests/fixtures/expected/blocks/references/php-class.html +++ b/tests/fixtures/expected/blocks/references/php-class.html @@ -1,9 +1,13 @@ - - - - -

      ArrayAccess

      - - + + + + + + + +

      ArrayAccess

      + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/references/php-function.html b/tests/fixtures/expected/blocks/references/php-function.html index 164835a..0172ade 100644 --- a/tests/fixtures/expected/blocks/references/php-function.html +++ b/tests/fixtures/expected/blocks/references/php-function.html @@ -1,9 +1,13 @@ - - - - -

      trigger_error

      - - + + + + + + + +

      trigger_error

      + + + \ No newline at end of file diff --git a/tests/fixtures/expected/blocks/references/php-method.html b/tests/fixtures/expected/blocks/references/php-method.html index bc29459..dbcf43f 100644 --- a/tests/fixtures/expected/blocks/references/php-method.html +++ b/tests/fixtures/expected/blocks/references/php-method.html @@ -1,9 +1,13 @@ - - - - -

      Locale::getDefault()

      - - + + + + + + + +

      Locale::getDefault()

      + + + \ No newline at end of file diff --git a/tests/fixtures/expected/doc-reference/index.html b/tests/fixtures/expected/doc-reference/index.html index 5805d73..47d4f5f 100644 --- a/tests/fixtures/expected/doc-reference/index.html +++ b/tests/fixtures/expected/doc-reference/index.html @@ -1,14 +1,17 @@ - - - - -
      -

      - A test for doc link -

      -

      A doc test

      + + + + + + + + - - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/main/datetime.html b/tests/fixtures/expected/main/datetime.html index 9d0837e..d250b1a 100644 --- a/tests/fixtures/expected/main/datetime.html +++ b/tests/fixtures/expected/main/datetime.html @@ -1,315 +1,223 @@ - - - - -
      -

      - DateTimeType Field -

      -

      This field type allows the user to modify data that represents a specific + + + + + + + +

      +

      DateTimeType Field

      +

      This field type allows the user to modify data that represents a specific date and time (e.g. 1984-06-05 12:15:30).

      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +
      Underlying Data Typecan be DateTime, string, timestamp, or array (see the input option)
      Rendered assingle text box or three select fields
      Options - -
      Overridden options - -
      Parent typeFormType
      ClassDateTimeType
      RefSome Test Docs! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - -
      Underlying Data Typecan be DateTime, string, timestamp, or array (see the input option)
      Rendered assingle text box or three select fields
      Options +
      Overridden options +
      Parent typeFormType
      ClassDateTimeType
      RefSome Test Docs! Test reference
      -
      -

      - Field Options -

      -
      -

      - The date_format Option -

      -

      type: integer or stringdefault: IntlDateFormatter::MEDIUM

      -

      Defines the format option that will be passed down to the date field. +

      +
      +

      Field Options

      +
      +

      The date_format Option

      +

      type: integer or stringdefault: IntlDateFormatter::MEDIUM

      +

      Defines the format option that will be passed down to the date field. for more details.

      -
      -

      - - - - Tip -

      -

      This is a little tip about something! We an also talk about specific +

      +

      + + Tip +

      This is a little tip about something! We an also talk about specific methods: doRequest(). Or a namespace: Constraints. Or a PHP function: parse_ini_file. Or a PHP method! Locale::getDefault().

      -
      -
      -
      -

      - date_widget -

      -

      Date widget!

      -
      -

      - - - - Note -

      -

      Sometimes we add notes. But not too often because they interrupt the flow. +

      +
      +
      +

      date_widget

      +

      Date widget!

      +
      +

      + + Note +

      Sometimes we add notes. But not too often because they interrupt the flow. FormType Documentation

      -
      -

      This is included documentation about the date_widget option.

      -
      -
      -

      - placeholder -

      -
      -
      - New in version 2.6: -

      The placeholder option was introduced in Symfony 2.6 and replaces +

      +

      This is included documentation about the date_widget option.

      +
      +
      +

      placeholder

      +
      New in version 2.6:

      The placeholder option was introduced in Symfony 2.6 and replaces empty_value, which is available prior to 2.6. FormType Documentation

      -
      -
      -

      type: string | array

      -

      If your widget option is set to choice, then this field will be represented +

      +

      type: string | array

      +

      If your widget option is set to choice, then this field will be represented as a series of select boxes. When the placeholder value is a string, it will be used as the blank value of all select boxes:

      -
      -
      - - - - - -
      -
      -
       1 2 3 4 5
      -
      -
      -
      -
      -                                                        use
      -                                                        Symfony
      -                                                        \
      -                                                        Component
      -                                                        \
      -                                                        Form
      -                                                        \
      -                                                        Extension
      -                                                        \
      -                                                        Core
      -                                                        \
      -                                                        Type
      -                                                        \
      -                                                        DateTimeType
      -                                                        ; 
      -                                                        
      -                                                            $
      -                                                            builder
      -                                                        
      -                                                        ->
      -                                                        add(
      -                                                        'startDateTime'
      -                                                        , DateTimeType
      -                                                        ::
      -                                                        class, 
      -                                                        array
      -                                                        ( 
      -                                                        'placeholder'
      -                                                        => 
      -                                                        'Select a value'
      -                                                        ,
      +
      +
      +
      1
      +2
      +3
      +4
      +5
      +
      use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
      +
      +$builder->add('startDateTime', DateTimeType::class, array(
      +    'placeholder' => 'Select a value',
       ));
      -                                                    
      -
      -
      -
      -
      -
      -

      See also

      -

      Also check out the homepage - Some Test Docs!. + +

      +
      +
      +

      + See also +

      Also check out the homepage - Some Test Docs!. FormType Documentation

      -
      -

      Custom classes for links are also cool:

      - -
      -
      -

      - format -

      -

      type: stringdefault: Symfony\Component\Form\Extension\Core\Type\DateTimeType::HTML5_FORMAT

      -

      If the widget option is set to single_text, this option specifies +

      +

      Custom classes for links are also cool:

      + + +
      +
      +

      format

      +

      type: stringdefault: Symfony\Component\Form\Extension\Core\Type\DateTimeType::HTML5_FORMAT

      +

      If the widget option is set to single_text, this option specifies the format of the input, i.e. how Symfony will interpret the given input as a datetime string. See Date/Time Format Syntax.

      -
      -
      - -

      But do they really? They also get in the way!

      -
      -
      -
      -

      - - - - Caution -

      -

      Using too many sidebars or caution directives can be distracting!

      -
      -
      -

      Best Practice

      -

      Use the bcrypt encoder for hashing your users' passwords.

      -
      -
      -
      -

      - time_widget -

      -

      type: stringdefault: choice

      -

      Defines the widget option for the TimeType.

      -
      -
      -

      - widget -

      -

      type: stringdefault: null

      -

      Defines the widget option for both the DateType. +

      But do they really? They also get in the way!

      +
      +
      +

      + + Caution +

      Using too many sidebars or caution directives can be distracting!

      +
      +
      +

      + Best Practice +

      Use the bcrypt encoder for hashing your users' passwords.

      +
      +
      +
      +

      time_widget

      +

      type: stringdefault: choice

      +

      Defines the widget option for the TimeType.

      +
      +
      +

      widget

      +

      type: stringdefault: null

      +

      Defines the widget option for both the DateType. and TimeType. This can be overridden with the date_widget and time_widget options.

      -
      -
      +
      +
      +
      +
      +

      Overridden Options

      +
      +

      by_reference

      +

      default: false

      +

      The DateTime classes are treated as immutable objects.

      -

      - Overridden Options -

      -
      -

      - by_reference -

      -

      default: false

      -

      The DateTime classes are treated as immutable objects.

      +

      error_bubbling

      +

      default: false

      +

      We also support code blocks!

      +
      +
      +
      1
      +2
      +3
      +
      # app/config/parameters.yml
      +parameters:
      +    database_driver:   pdo_mysql
      +
      -
      -

      - error_bubbling -

      -

      default: false

      -

      We also support code blocks!

      -
      -
      - - - - - -
      -
      -
       1 2 3
      -
      -
      -
      -
      -                                                        # app/config/parameters.yml
      -                                                        parameters:
      -                                                        database_driver:
      -                                                        pdo_mysql
      -                                                    
      -
      -
      -
      -
      -

      And configuration blocks:

      -
      -
        -
      • - YAML -
        -
        - - - - - -
        -
        -
         1 2 3 4 5 6 7
        -
        -
        -
        -
        -                                                                    # app/config/config.yml
        -                                                                    framework:
        -                                                                    secret:
        -                                                                    '%secret%'
        -                                                                    router:
        -                                                                    {
        -                                                                    resource:
        -                                                                    '%kernel.root_dir%/config/routing.yml'
        -                                                                    }
        -                                                                    # ...
        -                                                                    # ...
        -                                                                
        -
        -
        -
        -
        -
      • -
      • - XML -
        -
        - - - - - -
        -
        -
         1 2 3 4 5 6 7 8 9
        +
        +

        And configuration blocks:

        +
        +
          +
        • + YAML +
          +
          +
          1
          +2
          +3
          +4
          +5
          +6
          +7
          +
          # app/config/config.yml
          +framework:
          +    secret:          '%secret%'
          +    router:          { resource: '%kernel.root_dir%/config/routing.yml' }
          +    # ...
          +
          +# ...
          +
          +
          +
          +
        • +
        • + XML +
          +
          +
          1
          +2
          +3
          +4
          +5
          +6
          +7
          +8
          +9
           10
           11
           12
          @@ -321,155 +229,92 @@ 

          18 19 20

          -
          -
        -
        -
        -                                                                    <!-- app/config/config.xml -->
        -                                                                    <?xml version="1.0" encoding="UTF-8" ?>
        -                                                                    
        -                                                                        <
        -                                                                        container
        -                                                                        xmlns
        -                                                                        =
        -                                                                        "http://symfony.com/schema/dic/services"
        -                                                                        xmlns:xsi
        -                                                                        =
        -                                                                        "http://www.w3.org/2001/XMLSchema-instance"
        -                                                                        xmlns:framework
        -                                                                        =
        -                                                                        "http://symfony.com/schema/dic/symfony"
        -                                                                        xmlns:twig
        -                                                                        =
        -                                                                        "http://symfony.com/schema/dic/twig"
        -                                                                        xsi:schemaLocation
        -                                                                        =
        -                                                                        "http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd"
        -                                                                        >
        -                                                                    
        -                                                                    
        -                                                                        <
        -                                                                        framework:config
        -                                                                        secret
        -                                                                        =
        -                                                                        "%secret%"
        -                                                                        >
        -                                                                    
        -                                                                    
        -                                                                        <
        -                                                                        framework:router
        -                                                                        resource
        -                                                                        =
        -                                                                        "%kernel.root_dir%/config/routing.xml"
        -                                                                        />
        -                                                                    
        -                                                                    <!-- ... -->
        -                                                                    
        -                                                                        </
        -                                                                        framework:config
        -                                                                        >
        -                                                                    
        -                                                                    <!-- ... -->
        -                                                                    
        -                                                                        </
        -                                                                        container
        -                                                                        >
        -                                                                    
        -                                                                
        -
        -
        -
        -
        -
      • -
      • - PHP -
        -
        - - - - - -
        -
        -
         1 2 3 4 5 6 7 8 9
        +        
        <!-- app/config/config.xml -->
        +<?xml version="1.0" encoding="UTF-8" ?>
        +<container xmlns="http://symfony.com/schema/dic/services"
        +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        +    xmlns:framework="http://symfony.com/schema/dic/symfony"
        +    xmlns:twig="http://symfony.com/schema/dic/twig"
        +    xsi:schemaLocation="http://symfony.com/schema/dic/services
        +        http://symfony.com/schema/dic/services/services-1.0.xsd
        +        http://symfony.com/schema/dic/symfony
        +        http://symfony.com/schema/dic/symfony/symfony-1.0.xsd
        +        http://symfony.com/schema/dic/twig
        +        http://symfony.com/schema/dic/twig/twig-1.0.xsd">
        +
        +    <framework:config secret="%secret%">
        +        <framework:router resource="%kernel.root_dir%/config/routing.xml" />
        +        <!-- ... -->
        +    </framework:config>
        +
        +    <!-- ... -->
        +</container>
        +
        +
        + + +
      • + PHP +
        +
        +
        1
        +2
        +3
        +4
        +5
        +6
        +7
        +8
        +9
         10
        -
        -
      • -
        -
        -                                                                    // app/config/config.php
        -                                                                    
        -                                                                        $
        -                                                                        container
        -                                                                    
        -                                                                    ->
        -                                                                    loadFromExtension(
        -                                                                    'framework'
        -                                                                    , 
        -                                                                    array
        -                                                                    ( 
        -                                                                    'secret'
        -                                                                    => 
        -                                                                    '%secret%'
        -                                                                    , 
        -                                                                    'router'
        -                                                                    => 
        -                                                                    array
        -                                                                    ( 
        -                                                                    'resource'
        -                                                                    => 
        -                                                                    '%kernel.root_dir%/config/routing.php'
        -                                                                    , ), 
        -                                                                    // ...
        -                                                                    )); 
        -                                                                    // ...
        -                                                                
        -
        -
        -
        -
        -
      • -
      -
      +
      // app/config/config.php
      +$container->loadFromExtension('framework', array(
      +    'secret' => '%secret%',
      +    'router' => array(
      +        'resource' => '%kernel.root_dir%/config/routing.php',
      +    ),
      +    // ...
      +));
      +
      +// ...
      +
      +
      + +
    +
    -

    - Field Variables -

    - - - - - - - - - - - - - - - - - - + +
    VariableTypeUsage
    widgetmixedThe value of the widget option
    typestringMultiple lines of text here, to show +

    Field Variables

    + + + + + + + + + + + + + + + + + + + - - -
    VariableTypeUsage
    widgetmixedThe value of the widget option
    typestringMultiple lines of text here, to show that off
    +
    -

    - Url checker errors -

    -

    This is a 404 error. +

    Url checker errors

    +

    This is a 404 error. And here is an invalid url invalid-url.

    - - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/main/form/form_type.html b/tests/fixtures/expected/main/form/form_type.html index 3c36b75..d2e828e 100644 --- a/tests/fixtures/expected/main/form/form_type.html +++ b/tests/fixtures/expected/main/form/form_type.html @@ -1,15 +1,17 @@ - - - - -
    -

    - FormType Documentation -

    + + + + + + + + - - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/main/index.html b/tests/fixtures/expected/main/index.html index 0e28229..3eda13c 100644 --- a/tests/fixtures/expected/main/index.html +++ b/tests/fixtures/expected/main/index.html @@ -1,34 +1,22 @@ - - - - -
    -

    - Some Test Docs! -

    - - + + + + + + + + - - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/ref-reference/index.html b/tests/fixtures/expected/ref-reference/index.html index 2635ceb..f258a77 100644 --- a/tests/fixtures/expected/ref-reference/index.html +++ b/tests/fixtures/expected/ref-reference/index.html @@ -1,14 +1,17 @@ - - - - -
    -

    - A test for reference -

    -

    A ref test

    + + + + + + + + - - + + + \ No newline at end of file diff --git a/tests/fixtures/expected/toctree/index.html b/tests/fixtures/expected/toctree/index.html index a8432bb..db95387 100644 --- a/tests/fixtures/expected/toctree/index.html +++ b/tests/fixtures/expected/toctree/index.html @@ -1,52 +1,21 @@ - - - - -
    + + + + + + + + - - + + + \ No newline at end of file From 82d69628fb67156561b28457ca0024fe161d842f Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 15 Mar 2021 13:00:14 +0100 Subject: [PATCH 3/4] Tweak --- src/Renderers/CodeNodeRenderer.php | 3 ++- src/Templates/default/html/code.html.twig | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Renderers/CodeNodeRenderer.php b/src/Renderers/CodeNodeRenderer.php index 91bead8..b3625a9 100644 --- a/src/Renderers/CodeNodeRenderer.php +++ b/src/Renderers/CodeNodeRenderer.php @@ -75,12 +75,13 @@ public function render(): string } $numOfLines = \count(preg_split('/\r\n|\r|\n/', $highlightedCode)); + $lines = implode("\n", range(1, $numOfLines - 1)); return $this->templateRenderer->render( 'code.html.twig', [ 'languages' => $languages, - 'lines' => range(1, $numOfLines - 1), + 'lines' => $lines, 'code' => $highlightedCode, // this is the number of digits of the codeblock lines-of-code // e.g. LOC = 5, digits = 1; LOC = 18, digits = 2 diff --git a/src/Templates/default/html/code.html.twig b/src/Templates/default/html/code.html.twig index b01ccee..cec9d91 100644 --- a/src/Templates/default/html/code.html.twig +++ b/src/Templates/default/html/code.html.twig @@ -1,6 +1,6 @@
    -
    {{ lines|join("\n") }}
    +
    {{ lines }}
    {{ code|raw }}
    From 28b3b55b4948756225bba5319f80e4fdbba4d32b Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 16 Mar 2021 09:17:34 +0100 Subject: [PATCH 4/4] Fixed tests --- tests/fixtures/expected/toctree/index.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/fixtures/expected/toctree/index.html b/tests/fixtures/expected/toctree/index.html index db95387..3480a0b 100644 --- a/tests/fixtures/expected/toctree/index.html +++ b/tests/fixtures/expected/toctree/index.html @@ -3,7 +3,7 @@ - + @@ -12,10 +12,10 @@

    - - + +
    - \ No newline at end of file +