diff --git a/src/Directive/CodeBlockDirective.php b/src/Directive/CodeBlockDirective.php index 72518db..6618c66 100644 --- a/src/Directive/CodeBlockDirective.php +++ b/src/Directive/CodeBlockDirective.php @@ -33,6 +33,9 @@ public function process(Parser $parser, ?Node $node, string $variable, string $d } $node->setLanguage($data); + // grab the "class" option and forward it onto the Node + // CodeNodeRenderer can then use it when rendering + $node->setClasses(isset($options['class']) ? explode(' ', $options['class']) : []); if ('' !== $variable) { $environment = $parser->getEnvironment(); 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 @@
+
+
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 @@