Skip to content

Commit 40a4acf

Browse files
committed
add php highlighter
1 parent 4c01163 commit 40a4acf

File tree

8 files changed

+28
-26
lines changed

8 files changed

+28
-26
lines changed

_build/notes.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ Changes needed in symfony.com
99
Notes
1010
=====
1111

12-
- warning about exceptions thrown and abortOnError conf
1312
- add some format check on references
14-
- conf file, at least for sf version
13+
- toc tree bugs whith :glob:

_build/src/Nodes/CodeNode.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace SymfonyDocs\Nodes;
44

55
use Doctrine\RST\Nodes\CodeNode as Base;
6-
use function htmlspecialchars;
6+
use Highlight\Highlighter;
77

88
class CodeNode extends Base
99
{
@@ -18,15 +18,15 @@ class CodeNode extends Base
1818
</td>
1919
<td class="code">
2020
<div class="highlight">
21-
<pre>%s</pre>
21+
<pre class="hljs">%s</pre>
2222
</div>
2323
</td>
2424
</tr>
2525
</table>
2626
</div>
2727
</div>';
2828

29-
public function render() : string
29+
public function render(): string
3030
{
3131
$nodeValue = $this->getValue();
3232
assert(is_string($nodeValue));
@@ -41,11 +41,16 @@ public function render() : string
4141
$lineNumbers .= $iAsString."\n";
4242
}
4343

44+
$language = $this->getLanguage() ?? 'php';
45+
46+
$highLighter = new Highlighter();
47+
$highlightedCode = $highLighter->highlight($language, implode("\n", $lines));
48+
4449
return sprintf(
4550
self::CODE_BLOCK_TEMPLATE,
46-
$this->getLanguage() ?? 'php',
51+
$language,
4752
rtrim($lineNumbers),
48-
implode("\n", $lines)
53+
$highlightedCode->value
4954
);
5055
}
5156

_build/tests/IntegrationTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public function testIntegration(string $folder)
4242

4343
public function integrationProvider()
4444
{
45-
// yield 'main' => [
46-
// 'folder' => 'main'
47-
// ];
45+
// yield 'main' => [
46+
// 'folder' => 'main',
47+
// ];
4848

4949
yield 'toctree' => [
5050
'folder' => 'toctree',

_build/tests/fixtures/expected/blocks/code-block.html

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@
2121
</td>
2222
<td class="code">
2323
<div class="highlight">
24-
<pre>// config/routes.php
25-
namespace Symfony\Component\Routing\Loader\Configurator;
26-
27-
return function (RoutingConfigurator $routes) {
28-
$routes->add('about_us', ['nl' => '/over-ons', 'en' => '/about-us'])
29-
->controller('App\Controller\CompanyController::about');
24+
<pre class="hljs">
25+
<span class="hljs-comment">// config/routes.php</span>
26+
<span class="hljs-keyword">namespace</span> <span class="hljs-title">Symfony</span>\<span class="hljs-title">Component</span>\<span class="hljs-title">Routing</span>\<span class="hljs-title">Loader</span>\<span class="hljs-title">Configurator</span>; <span class="hljs-keyword">return</span>
27+
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-params">(RoutingConfigurator $routes)</span> </span>
28+
{ $routes-&gt;add(<span class="hljs-string">'about_us'</span>, [<span class="hljs-string">'nl'</span> =&gt; <span class="hljs-string">'/over-ons'</span>, <span class="hljs-string">'en'</span> =&gt; <span class="hljs-string">'/about-us'</span>]) -&gt;controller(<span class="hljs-string">'App\Controller\CompanyController::about'</span>);
3029
};</pre>
3130
</div>
3231
</td>

_build/tests/fixtures/expected/blocks/configuration-block.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</td>
1616
<td class="code">
1717
<div class="highlight">
18-
<pre># app/config/services.yml</pre>
18+
<pre class="hljs"><span class="hljs-comment"># app/config/services.yml</span></pre>
1919
</div>
2020
</td>
2121
</tr>
@@ -32,7 +32,7 @@
3232
</td>
3333
<td class="code">
3434
<div class="highlight">
35-
<pre>// config/routes.php</pre>
35+
<pre class="hljs"><span class="hljs-comment">// config/routes.php</span></pre>
3636
</div>
3737
</td>
3838
</tr>

_build/tests/fixtures/expected/blocks/literal.html

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222
</td>
2323
<td class="code">
2424
<div class="highlight">
25-
<pre>// config/routes.php
26-
namespace Symfony\Component\Routing\Loader\Configurator;
27-
28-
return function (RoutingConfigurator $routes) {
29-
$routes->add('about_us', ['nl' => '/over-ons', 'en' => '/about-us'])
30-
->controller('App\Controller\CompanyController::about');
25+
<pre class="hljs">
26+
<span class="hljs-comment">// config/routes.php</span>
27+
<span class="hljs-keyword">namespace</span> <span class="hljs-title">Symfony</span>\<span class="hljs-title">Component</span>\<span class="hljs-title">Routing</span>\<span class="hljs-title">Loader</span>\<span class="hljs-title">Configurator</span>; <span class="hljs-keyword">return</span>
28+
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-params">(RoutingConfigurator $routes)</span> </span>
29+
{ $routes-&gt;add(<span class="hljs-string">'about_us'</span>, [<span class="hljs-string">'nl'</span> =&gt; <span class="hljs-string">'/over-ons'</span>, <span class="hljs-string">'en'</span> =&gt; <span class="hljs-string">'/about-us'</span>]) -&gt;controller(<span class="hljs-string">'App\Controller\CompanyController::about'</span>);
3130
};</pre>
3231
</div>
3332
</td>

_build/tests/fixtures/expected/blocks/note-code-block-nested.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
</td>
2121
<td class="code">
2222
<div class="highlight">
23-
<pre>// code</pre>
23+
<pre class="hljs"><span class="hljs-comment">// code</span></pre>
2424
</div>
2525
</td>
2626
</tr>

_build/tests/fixtures/expected/blocks/sidebar-code-block-nested.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
</td>
2121
<td class="code">
2222
<div class="highlight">
23-
<pre>// some code</pre>
23+
<pre class="hljs"><span class="hljs-comment">// some code</span></pre>
2424
</div>
2525
</td>
2626
</tr>

0 commit comments

Comments
 (0)