Skip to content

Commit 7da60e6

Browse files
committed
Adding a span around code blocks that start with $
1 parent 82a2fa3 commit 7da60e6

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/Renderers/CodeNodeRenderer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ public function render(): string
7474
$highlightedCode = str_replace('<span class="hljs-variable">$', '<span class="hljs-variable"><span class="hljs-variable-other-marker">$</span>', $highlightedCode);
7575
}
7676

77+
if ('terminal' === $language && str_starts_with($highlightedCode, '$')) {
78+
$highlightedCode = '<span class="hljs-prompt">$</span>' . substr($highlightedCode, 1);
79+
}
80+
7781
$numOfLines = \count(preg_split('/\r\n|\r|\n/', $highlightedCode));
7882
$lines = implode("\n", range(1, $numOfLines - 1));
7983

tests/fixtures/expected/blocks/code-blocks/terminal.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,17 @@
1515
</div>
1616
</div>
1717

18+
<div translate="no" class="notranslate codeblock codeblock-loc-1 codeblock-terminal codeblock-bash">
19+
<div class="codeblock-scroll">
20+
<pre class="codeblock-lines">1</pre>
21+
<pre class="codeblock-code">
22+
<code>
23+
<span class="hljs-prompt">$</span> cowsay
24+
<span class="hljs-string">'eat more chicken'</span>
25+
</code>
26+
</pre>
27+
</div>
28+
</div>
29+
1830
</body>
19-
</html>
31+
</html>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11

22
.. code-block:: terminal
33
git clone git@github.com:symfony/symfony.git
4+
5+
.. code-block:: terminal
6+
7+
$ cowsay 'eat more chicken'

0 commit comments

Comments
 (0)