Skip to content

Commit 22ef22e

Browse files
committed
[Site] switch from highlight.js to tempest/highlight
1 parent 38998c1 commit 22ef22e

File tree

14 files changed

+155
-151
lines changed

14 files changed

+155
-151
lines changed

ux.symfony.com/assets/controllers/code-highlighter-controller.js

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,74 @@
1-
.hljs-comment, .hljs-prompt {
2-
color: #8b949e;
3-
user-select: none;
4-
-webkit-user-select: none
1+
/** tempest/highlight theme (https://github.com/tempestphp/highlight/blob/main/src/Themes/Css/dracula.css) */
2+
.hl-keyword {
3+
color: #FF79C6;
54
}
65

7-
.codeblock-terminal .hljs-keyword {
8-
color: #6a737d;
6+
.hl-property {
7+
color: #50FA7B;
98
}
109

11-
.codeblock-terminal .hljs-prompt {
12-
color: #8b949e;
13-
user-select: none;
14-
-webkit-user-select: none
10+
.hl-attribute {
11+
font-style: italic;
1512
}
1613

17-
.codeblock-terminal .hljs-string {
18-
color: #a5d6ff
14+
.hl-type {
15+
color: #8BE9FD;
1916
}
2017

21-
.hljs-keyword {
22-
color: #ff7b72
18+
.hl-generic {
19+
color: #9d3af6;
2320
}
2421

25-
.hljs-title {
26-
color: #ffa657
22+
.hl-value {
23+
color: #F1FA8C;
2724
}
2825

29-
.hljs-variable-other-marker {
30-
color: #79c0ff
26+
.hl-variable {
27+
color: #F8F8F2;
3128
}
3229

33-
.hljs-function .hljs-title {
34-
color: #d2a8ff
30+
.hl-comment {
31+
color: #6272A4;
3532
}
3633

37-
.hljs-string {
38-
color: #a5d6ff
34+
.hl-blur {
35+
filter: blur(2px);
3936
}
4037

41-
.hljs-attr, .hljs-tag .hljs-name {
42-
color: #7ee787
38+
.hl-strong {
39+
font-weight: bold;
4340
}
4441

45-
.hljs-tag .hljs-attr {
46-
color: #d2a8ff
42+
.hl-em {
43+
font-style: italic;
44+
}
45+
46+
.hl-addition {
47+
display: inline-block;
48+
min-width: 100%;
49+
background-color: #00FF0022;
50+
}
51+
52+
.hl-deletion {
53+
display: inline-block;
54+
min-width: 100%;
55+
background-color: #FF000011;
56+
}
57+
58+
.hl-gutter {
59+
display: inline-block;
60+
font-size: 0.9em;
61+
color: #555;
62+
padding: 0 1ch;
63+
user-select: none;
4764
}
4865

49-
.hljs-addition {
50-
background: rgba(46, 160, 67, .3);
51-
outline: 3px solid rgba(46, 160, 67, .3)
66+
.hl-gutter-addition {
67+
background-color: #34A853;
68+
color: #fff;
5269
}
5370

54-
.hljs-deletion {
55-
background: rgba(218, 54, 51, .3);
56-
outline: 3px solid rgba(218, 54, 51, .3)
71+
.hl-gutter-deletion {
72+
background-color: #EA4334;
73+
color: #fff;
5774
}

ux.symfony.com/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"symfony/yaml": "7.0.*",
5555
"symfonycasts/dynamic-forms": "^0.1.0",
5656
"symfonycasts/sass-bundle": "^0.6.0",
57+
"tempest/highlight": "^2.3",
5758
"twbs/bootstrap": "^5.3",
5859
"twig/extra-bundle": "^3.8",
5960
"twig/html-extra": "^3.8",

ux.symfony.com/composer.lock

Lines changed: 54 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ux.symfony.com/config/services.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ services:
2323

2424
# add more service definitions when explicit configuration is needed
2525
# please note that last definitions always *replace* previous ones
26+
Tempest\Highlight\Highlighter:
27+
tags: ['twig.runtime']

ux.symfony.com/importmap.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,6 @@
126126
'svelte/internal' => [
127127
'version' => '3.59.2',
128128
],
129-
'highlight.js/lib/core' => [
130-
'version' => '11.9.0',
131-
],
132-
'highlight.js/lib/languages/javascript' => [
133-
'version' => '11.9.0',
134-
],
135-
'highlight.js/lib/languages/php' => [
136-
'version' => '11.9.0',
137-
],
138-
'highlight.js/lib/languages/twig' => [
139-
'version' => '11.9.0',
140-
],
141-
'highlight.js/lib/languages/xml' => [
142-
'version' => '11.9.0',
143-
],
144129
'intl-messageformat' => [
145130
'version' => '10.5.11',
146131
],
@@ -205,10 +190,4 @@
205190
'@kurkle/color' => [
206191
'version' => '0.3.2',
207192
],
208-
'highlight.js/lib/languages/yaml' => [
209-
'version' => '11.9.0',
210-
],
211-
'highlight.js/lib/languages/diff' => [
212-
'version' => '11.9.0',
213-
],
214193
];

ux.symfony.com/src/Service/CommonMark/CodeRenderer.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

ux.symfony.com/src/Service/CommonMark/ConverterFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
namespace App\Service\CommonMark;
1313

1414
use League\CommonMark\CommonMarkConverter;
15-
use League\CommonMark\Extension\CommonMark\Node\Block\FencedCode;
1615
use League\CommonMark\Extension\ExternalLink\ExternalLinkExtension;
1716
use League\CommonMark\Extension\Mention\MentionExtension;
1817
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
18+
use Tempest\Highlight\CommonMark\HighlightExtension;
1919

2020
/**
2121
* @author Kevin Bond <kevinbond@gmail.com>
@@ -44,9 +44,9 @@ public function __invoke(): CommonMarkConverter
4444
]);
4545

4646
$converter->getEnvironment()
47-
->addRenderer(FencedCode::class, new CodeRenderer(), 10)
4847
->addExtension(new ExternalLinkExtension())
4948
->addExtension(new MentionExtension())
49+
->addExtension(new HighlightExtension())
5050
;
5151

5252
return $converter;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace App\Twig;
13+
14+
use Tempest\Highlight\Highlighter;
15+
use Twig\Extension\AbstractExtension;
16+
use Twig\TwigFilter;
17+
18+
/**
19+
* @author Kevin Bond <kevinbond@gmail.com>
20+
*/
21+
final class HighlightExtension extends AbstractExtension
22+
{
23+
public function getFilters(): array
24+
{
25+
return [
26+
new TwigFilter('highlight', [Highlighter::class, 'parse'], ['is_safe' => ['html']]),
27+
];
28+
}
29+
}

ux.symfony.com/templates/components/CodeBlock.html.twig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
{% endif %}
2020
<div class="Terminal_content" style="height: {{ height }};"
2121
data-code-expander-target="codeContent"
22-
data-controller="code-highlighter"
2322
>
2423
{% for piece in this.prepareSource %}
2524
{% if piece.highlight ?? true %}
26-
<pre><code class="language-{{ this.language }}" data-code-highlighter-target="codeBlock">
27-
{{- piece.content -}}
25+
<pre><code class="language-{{ this.language }}">
26+
{{- piece.content|highlight(this.language) -}}
2827
</code></pre>
2928
{% else %}
3029
{{- piece.content|raw -}}

ux.symfony.com/templates/components/CodeLine.html.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
{% props highlight = false, code = '', height = null %}
1+
{% props code = '', height = null %}
22

33
<div
44
class="IconModal__code"
5-
data-controller="clipboarder {% if highlight %} code-highlighter{% endif %}"
5+
data-controller="clipboarder"
66
>
77
{% set __code -%}
88
{% block content -%}
@@ -13,7 +13,7 @@
1313
<pre
1414
{% if height %} style="--height: {{ height }}" {% endif %}
1515
data-clipboarder-target="source"
16-
><code {% if highlight %} data-code-highlighter-target="codeBlock" {% endif %}>{{ __code ? __code|trim|raw : code }}</code></pre>
16+
><code>{{ __code ? __code|trim|raw : code }}</code></pre>
1717

1818
<button class="btn btn-sm IconModal__copy" data-action="clipboarder#copy" data-clipboarder-target="button">
1919
<twig:Icon name="copy" />

0 commit comments

Comments
 (0)