git ssb

30+

cel / git-ssb-web



Commit e92c15b1dae34409fb4c17abf69cce004e58f89c

Add line numbers to files in blob view

Charles Lehner committed on 4/2/2016, 2:42:46 AM
Parent: 7eac9610f25b563106240cb97750fd27e660a643

Files changed

index.jschanged
static/styles.csschanged
index.jsView
@@ -717,13 +717,24 @@
717717 buf = buf.toString('utf8')
718718 if (err) return cb(err)
719719 cb(null, (ext == 'md' || ext == 'markdown')
720720 ? markdown(buf, repo)
721- : '<pre>' + highlight(buf, ext) + '</pre>')
721+ : renderCodeTable(buf, ext))
722722 })
723723 })
724724 }
725725
726+ function renderCodeTable(buf, ext) {
727+ return '<pre><table class="code">' +
728+ highlight(buf, ext).split('\n').map(function (line, i) {
729+ i++
730+ return '<tr id="L' + i + '">' +
731+ '<td class="code-linenum">' + '<a href="#L' + i + '">' + i + '</td>' +
732+ '<td class="code-text">' + line + '</td></tr>'
733+ }).join('') +
734+ '</table></pre>'
735+ }
736+
726737 /* Feed */
727738
728739 function renderFeed(req, feedId) {
729740 var query = req._u.query
@@ -1360,16 +1371,16 @@
13601371 var lineNums = [s == '+' ? '' : oldLine++, s == '-' ? '' : newLine++]
13611372 var id = [filename].concat(lineNums).join('-')
13621373 return '<tr id="' + escapeHTML(id) + '" class="' + trClass + '">' +
13631374 lineNums.map(function (num) {
1364- return '<td class="diff-linenum">' +
1375+ return '<td class="code-linenum">' +
13651376 (num ? '<a href="#' + encodeURIComponent(id) + '">' +
13661377 num + '</a>' : '') + '</td>'
13671378 }).join('') +
1368- '<td class="diff-text">' + html + '</td></tr>'
1379+ '<td class="code-text">' + html + '</td></tr>'
13691380 }))
13701381 })
1371- return '<pre><table class="diff">' +
1382+ return '<pre><table class="code">' +
13721383 '<tr><th colspan=3><a name="' + anchor + '">' + filename + '</a>' +
13731384 '<span class="right-bar">' +
13741385 '<a href="' + blobHref + '">View</a> ' +
13751386 '</span></th></tr>' +
static/styles.cssView
@@ -317,16 +317,16 @@
317317 padding: .25ex .5ex;
318318 margin: -.25ex -.5ex;
319319 }
320320
321-/* diffs */
321+/* code and diffs */
322322
323-.diff {
323+.code {
324324 border-collapse: collapse;
325325 text-align: left;
326326 }
327327
328-.diff th {
328+.code th {
329329 font-family: sans-serif;
330330 font-size: 1.25em;
331331 padding-bottom: .5ex;
332332 }
@@ -335,32 +335,32 @@
335335 background-color: #eee;
336336 color: grey;
337337 }
338338
339-.diff td {
339+.code td {
340340 padding: 0 1ex 0;
341341 }
342342
343-.diff tr:hover {
343+.code tr:hover {
344344 background-color: #fff8d2;
345345 }
346346
347-.diff-linenum {
347+.code-linenum {
348348 vertical-align: top;
349349 text-align: right;
350350 color: grey;
351351 border-right: 1px solid rgba(0, 0, 0, 0.06);
352352 }
353353
354-.diff-linenum a {
354+.code-linenum a {
355355 color: inherit;
356356 }
357357
358-.diff-linenum a:hover {
358+.code-linenum a:hover {
359359 color: #9f9999;
360360 }
361361
362-.diff-text {
362+.code-text {
363363 white-space: pre-wrap;
364364 width: 100%;
365365 }
366366

Built with git-ssb-web