Skip to content

Commit e8459ab

Browse files
committed
Show line numbers
1 parent 3d213cc commit e8459ab

File tree

2 files changed

+48
-14
lines changed

2 files changed

+48
-14
lines changed

src/pages/_template.php

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,45 @@
9999
min-width: 30px;
100100
display: inline-block;
101101
text-indent: 0;
102-
102+
}
103+
pre, code,
104+
.file-code .lines span {
105+
margin: 0;
106+
font-family: "Fira Mono", "Source Code Pro", monospace;
107+
font-weight: 400;
108+
font-size: 1rem;
109+
line-height: 1.5rem;
110+
-moz-tab-size: 4;
111+
-o-tab-size: 4;
112+
tab-size: 4;
103113
}
104114
.file-code {
105115
border: 1px gray solid;
106-
padding: 1%;
116+
padding: 0;
107117
background: #fff;
108118
overflow-x: auto;
109-
width: 98%;
119+
width: 100%;
110120
margin: 0 auto;
111-
white-space: pre;
112-
word-wrap: break-word;
113-
-moz-tab-size: 4;
114-
-o-tab-size: 4;
115-
tab-size: 4;
116121
}
117-
.file-code code {
118-
white-space: normal;
122+
.file-code > * {
123+
float: left;
124+
}
125+
.file-code .lines {
126+
background: #e6e6e6;
127+
border-right: 1px gray solid;
128+
padding: 0 5px;
129+
min-width: 20px;
130+
}
131+
.file-code .lines span {
132+
display: block;
133+
line-height: 1.595rem;
134+
}
135+
.file-code .code {
136+
width: 800px;
137+
padding-left: 5px;
138+
}
139+
.file-code .code span {
140+
white-space: pre;
119141
}
120142
.date {
121143
float: right;

src/pages/show-file.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
<?php
22
$contents = file_get_contents($absolute_path);
3-
$contents = substr($absolute_path, -3) === 'php'
4-
? highlight_string($contents, true)
5-
: htmlentities($contents);
3+
if (substr($absolute_path, -3) === 'php') {
4+
$contents = highlight_string($contents, true);
5+
$contents = strtr($contents, [PHP_EOL => '', '&nbsp;' => ' ']);
6+
$contents = str_replace(['<br>', '<br />'],"\n",$contents);
7+
} else {
8+
$contents = '<pre>' . htmlentities($contents) . '</pre>';
9+
}
10+
611
$function_parent_dir($relative_path);
712
?>
8-
<div class="file-code"><?= $contents ?></div>
13+
<div class="file-code">
14+
<div class="lines"><?php
15+
foreach (explode("\n", $contents) as $line => $c) {
16+
echo '<span>' . ($line + 1) . '</span>';
17+
}
18+
?></div>
19+
<div class="code"><?= $contents ?></div>
20+
</div>

0 commit comments

Comments
 (0)