From 6367bc321b1e7bc95af53bcf5c3b2f5c42c8800a Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 10 Feb 2022 16:22:32 +0100 Subject: [PATCH 1/2] Add support for CSS classes in code blocks --- src/Renderers/CodeNodeRenderer.php | 1 + src/Templates/default/html/code.html.twig | 2 +- .../expected/blocks/code-blocks/bash.html | 2 +- .../expected/blocks/code-blocks/diff.html | 4 ++-- .../expected/blocks/code-blocks/html-php.html | 2 +- .../blocks/code-blocks/html-twig.html | 2 +- .../expected/blocks/code-blocks/html.html | 2 +- .../expected/blocks/code-blocks/ini.html | 2 +- .../blocks/code-blocks/php-annotations.html | 2 +- .../expected/blocks/code-blocks/php.html | 2 +- .../expected/blocks/code-blocks/terminal.html | 19 ++++++++++++++++--- .../expected/blocks/code-blocks/text.html | 2 +- .../expected/blocks/code-blocks/twig.html | 2 +- .../expected/blocks/code-blocks/xml.html | 2 +- .../expected/blocks/code-blocks/yaml.html | 2 +- .../directives/configuration-block.html | 4 ++-- .../directives/note-code-block-nested.html | 2 +- .../directives/sidebar-code-block-nested.html | 2 +- .../expected/blocks/nodes/literal.html | 2 +- .../source/blocks/code-blocks/terminal.rst | 5 +++++ 20 files changed, 41 insertions(+), 22 deletions(-) diff --git a/src/Renderers/CodeNodeRenderer.php b/src/Renderers/CodeNodeRenderer.php index 26f16ff..356e923 100644 --- a/src/Renderers/CodeNodeRenderer.php +++ b/src/Renderers/CodeNodeRenderer.php @@ -84,6 +84,7 @@ public function render(): string return $this->templateRenderer->render( 'code.html.twig', [ + 'css_classes' => $this->codeNode->getClassesString(), 'languages' => $languages, 'line_numbers' => $lineNumbers, 'code' => $highlightedCode, diff --git a/src/Templates/default/html/code.html.twig b/src/Templates/default/html/code.html.twig index fa6ff8a..df32cb6 100644 --- a/src/Templates/default/html/code.html.twig +++ b/src/Templates/default/html/code.html.twig @@ -1,4 +1,4 @@ -
+
{{ line_numbers }}
{{ code|raw }}
diff --git a/tests/fixtures/expected/blocks/code-blocks/bash.html b/tests/fixtures/expected/blocks/code-blocks/bash.html index 499d001..2bd5494 100644 --- a/tests/fixtures/expected/blocks/code-blocks/bash.html +++ b/tests/fixtures/expected/blocks/code-blocks/bash.html @@ -1,4 +1,4 @@ -
+
1
git clone git@github.com:symfony/symfony.git
diff --git a/tests/fixtures/expected/blocks/code-blocks/diff.html b/tests/fixtures/expected/blocks/code-blocks/diff.html index 0a020cf..b28fd0b 100644 --- a/tests/fixtures/expected/blocks/code-blocks/diff.html +++ b/tests/fixtures/expected/blocks/code-blocks/diff.html @@ -1,4 +1,4 @@ -
+
1
 2
@@ -17,7 +17,7 @@
     
-
+
1
 2
diff --git a/tests/fixtures/expected/blocks/code-blocks/html-php.html b/tests/fixtures/expected/blocks/code-blocks/html-php.html
index d77a92e..a6a97c8 100644
--- a/tests/fixtures/expected/blocks/code-blocks/html-php.html
+++ b/tests/fixtures/expected/blocks/code-blocks/html-php.html
@@ -1,4 +1,4 @@
-
+
1
 2
diff --git a/tests/fixtures/expected/blocks/code-blocks/html-twig.html b/tests/fixtures/expected/blocks/code-blocks/html-twig.html
index dbe3101..fd757ff 100644
--- a/tests/fixtures/expected/blocks/code-blocks/html-twig.html
+++ b/tests/fixtures/expected/blocks/code-blocks/html-twig.html
@@ -1,4 +1,4 @@
-
+
1
 2
diff --git a/tests/fixtures/expected/blocks/code-blocks/html.html b/tests/fixtures/expected/blocks/code-blocks/html.html index f35e7e3..bdc5621 100644 --- a/tests/fixtures/expected/blocks/code-blocks/html.html +++ b/tests/fixtures/expected/blocks/code-blocks/html.html @@ -1,4 +1,4 @@ -
+
1
<!-- some code -->
diff --git a/tests/fixtures/expected/blocks/code-blocks/ini.html b/tests/fixtures/expected/blocks/code-blocks/ini.html
index 01600a9..5bc6410 100644
--- a/tests/fixtures/expected/blocks/code-blocks/ini.html
+++ b/tests/fixtures/expected/blocks/code-blocks/ini.html
@@ -1,4 +1,4 @@
-
+
1
fetch = +refs/notes/*:refs/notes/*
diff --git a/tests/fixtures/expected/blocks/code-blocks/php-annotations.html b/tests/fixtures/expected/blocks/code-blocks/php-annotations.html index d43ecf0..afe2a3c 100644 --- a/tests/fixtures/expected/blocks/code-blocks/php-annotations.html +++ b/tests/fixtures/expected/blocks/code-blocks/php-annotations.html @@ -1,4 +1,4 @@ -
+
1
 2
diff --git a/tests/fixtures/expected/blocks/code-blocks/php.html b/tests/fixtures/expected/blocks/code-blocks/php.html
index c005a13..e5d78ab 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
diff --git a/tests/fixtures/expected/blocks/code-blocks/terminal.html b/tests/fixtures/expected/blocks/code-blocks/terminal.html
index 15436ab..2879f6a 100644
--- a/tests/fixtures/expected/blocks/code-blocks/terminal.html
+++ b/tests/fixtures/expected/blocks/code-blocks/terminal.html
@@ -1,11 +1,11 @@
-
+
1
git clone git@github.com:symfony/symfony.git
-
+
1
 2
@@ -20,7 +20,7 @@
-
+
1
 2
@@ -33,3 +33,16 @@
        
+ +
+
+
1
+
+            
+                $ 
+                git branch -D sessions-in-db ||
+               true
+           
+        
+
+
diff --git a/tests/fixtures/expected/blocks/code-blocks/text.html b/tests/fixtures/expected/blocks/code-blocks/text.html index a30c3ed..91c0038 100644 --- a/tests/fixtures/expected/blocks/code-blocks/text.html +++ b/tests/fixtures/expected/blocks/code-blocks/text.html @@ -1,4 +1,4 @@ -
+
1
some text
diff --git a/tests/fixtures/expected/blocks/code-blocks/twig.html b/tests/fixtures/expected/blocks/code-blocks/twig.html index fab139d..2011c20 100644 --- a/tests/fixtures/expected/blocks/code-blocks/twig.html +++ b/tests/fixtures/expected/blocks/code-blocks/twig.html @@ -1,4 +1,4 @@ -
+
1
{# some code #}
diff --git a/tests/fixtures/expected/blocks/code-blocks/xml.html b/tests/fixtures/expected/blocks/code-blocks/xml.html index 4772257..1bf8d0b 100644 --- a/tests/fixtures/expected/blocks/code-blocks/xml.html +++ b/tests/fixtures/expected/blocks/code-blocks/xml.html @@ -1,4 +1,4 @@ -
+
1
<!-- some code -->
diff --git a/tests/fixtures/expected/blocks/code-blocks/yaml.html b/tests/fixtures/expected/blocks/code-blocks/yaml.html
index fceca11..5f24eef 100644
--- a/tests/fixtures/expected/blocks/code-blocks/yaml.html
+++ b/tests/fixtures/expected/blocks/code-blocks/yaml.html
@@ -1,4 +1,4 @@
-
+
1
# some code
diff --git a/tests/fixtures/expected/blocks/directives/configuration-block.html b/tests/fixtures/expected/blocks/directives/configuration-block.html
index bdff934..7a4a230 100644
--- a/tests/fixtures/expected/blocks/directives/configuration-block.html
+++ b/tests/fixtures/expected/blocks/directives/configuration-block.html
@@ -4,7 +4,7 @@
         
  • PHP
  • -
    +
    1
    # app/config/services.yml
    @@ -12,7 +12,7 @@