Skip to content

Commit 53288a5

Browse files
authored
Merge pull request #78 from weaverryan/terminal-start-wrapper
Adding a span around code blocks that start with $
2 parents 93d3230 + fd77b3b commit 53288a5

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

src/Renderers/CodeNodeRenderer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ 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) {
78+
$highlightedCode = preg_replace('/^\$/m', '<span class="hljs-prompt">$</span>', $highlightedCode);
79+
$highlightedCode = preg_replace('/^C:\\\&gt;/m', '<span class="hljs-prompt">C:\&gt;</span>', $highlightedCode);
80+
}
81+
7782
$numOfLines = \count(preg_split('/\r\n|\r|\n/', $highlightedCode));
7883
$lines = implode("\n", range(1, $numOfLines - 1));
7984

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,34 @@
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
21+
2</pre>
22+
<pre class="codeblock-code">
23+
<code>
24+
<span class="hljs-prompt">$</span> cowsay
25+
<span class="hljs-string">'eat more chicken'</span>
26+
<span class="hljs-prompt">$</span> cowsay
27+
<span class="hljs-string">'mmmm'</span>
28+
</code>
29+
</pre>
30+
</div>
31+
</div>
32+
33+
<div translate="no" class="notranslate codeblock codeblock-loc-1 codeblock-terminal codeblock-bash">
34+
<div class="codeblock-scroll">
35+
<pre class="codeblock-lines">1
36+
2
37+
3</pre>
38+
<pre class="codeblock-code">
39+
<code>
40+
<span class="hljs-prompt">C:\&gt;</span> CIV
41+
<span class="hljs-comment"># Civilization for DOS - my first computer game!</span>
42+
</code>
43+
</pre>
44+
</div>
45+
</div>
46+
1847
</body>
19-
</html>
48+
</html>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
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'
8+
$ cowsay 'mmmm'
9+
10+
.. code-block:: terminal
11+
12+
C:\> CIV
13+
14+
# Civilization for DOS - my first computer game!

0 commit comments

Comments
 (0)