Skip to content

Commit 2a5e5a4

Browse files
authored
Use white-space: pre-wrap for code formatting (#810)
* Use `white-space: pre-wrap` for code formatting Apparently code formatting is used for the entire user comments. Use `white-space: pre-wrap` to avoid horizontal scrolling of the plaintext description. see 7d40388 * Unify `highlight_php()` with PhD see php/phd@01d6beb * Fix markup for notes in add-note.php
1 parent bd160d8 commit 2a5e5a4

File tree

3 files changed

+11
-35
lines changed

3 files changed

+11
-35
lines changed

include/layout.inc

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,14 @@ function highlight_php($code, $return = false)
2020
}
2121

2222
// Fix output to use CSS classes and wrap well
23-
$highlighted = '<div class="phpcode">' . str_replace(
23+
$highlighted = '<div class="phpcode">' . strtr(
24+
$highlighted,
2425
[
25-
'&nbsp;',
26-
'<br>',
27-
'<span style="color: ',
28-
'</font>',
29-
"\n ",
30-
' ',
31-
' '
32-
],
33-
[
34-
' ',
35-
"<br>\n",
36-
'<span class="',
37-
'</span>',
38-
"\n&nbsp;",
39-
'&nbsp; ',
40-
'&nbsp; '
26+
'&nbsp;' => ' ',
27+
"\n" => '',
28+
29+
'<span style="color: ' => '<span class="',
4130
],
42-
$highlighted
4331
) . '</div>';
4432

4533
if ($return) { return $highlighted; }

manual/add-note.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,7 @@
190190
</div>
191191
<div class="text">
192192
<div class="phpcode">
193-
<code>
194-
<span class="html">
195-
<p>eval() is the best for all sorts of things</p>
196-
</span>
197-
</code>
193+
<code><span class="html">eval() is the best for all sorts of things</span></code>
198194
</div>
199195
</div>
200196
</div>
@@ -220,11 +216,7 @@
220216
</div>
221217
<div class="text">
222218
<div class="phpcode">
223-
<code>
224-
<span class="html">
225-
<p>If eval() is the answer, you're almost certainly asking the wrong question.</p>
226-
</span>
227-
</code>
219+
<code><span class="html">If eval() is the answer, you're almost certainly asking the wrong question.</span></code>
228220
</div>
229221
</div>
230222
</div>
@@ -250,11 +242,7 @@
250242
</div>
251243
<div class="text">
252244
<div class="phpcode">
253-
<code>
254-
<span class="html">
255-
<p>egg bacon sausage spam spam baked beans</p>
256-
</span>
257-
</code>
245+
<code><span class="html">egg bacon sausage spam spam baked beans</span></code>
258246
</div>
259247
</div>
260248
</div>

styles/theme-base.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,10 +1325,10 @@ div.tip p:first-child {
13251325
margin-bottom: 1.5rem;
13261326
}
13271327

1328-
.docs .phpcode code {
1328+
.phpcode code {
13291329
display: block;
13301330
overflow-x: auto;
1331-
white-space: pre;
1331+
white-space: pre-wrap;
13321332
}
13331333

13341334
.docs .qandaentry dt .phpcode * {

0 commit comments

Comments
 (0)