slene 11 years ago
parent
commit
de956c4776
6 changed files with 81 additions and 12 deletions
  1. 39 6
      public/css/gogs.css
  2. 8 2
      public/css/markdown.css
  3. 22 1
      public/js/app.js
  4. 1 1
      public/js/lib.js
  5. 2 0
      routers/repo/single.go
  6. 9 2
      templates/repo/single_file.tmpl

+ 39 - 6
public/css/gogs.css

@@ -644,7 +644,7 @@ html, body {
 }
 
 .file-content .file-body {
-    padding: 0;
+    padding: 30px 30px 50px;
     border: none;
     background-color: #FFF;
 }
@@ -654,17 +654,50 @@ html, body {
     border: none;
 }
 
-.file-content .markdown > pre > ol.linenums > li:first-child {
-    padding-top: 0;
+.file-content .file-body.file-code {
+    padding: 0;
+}
+
+.file-content .file-body.file-code .lines-code > pre {
+    border: none;
+    background: none;
+    border-left: 1px solid #ddd;
+}
+
+.file-content .file-body.file-code .lines-code ol.linenums > .active {
+    background: #ffffdd;
+}
+
+.file-content .file-body.file-code .lines-num {
+    text-align: right;
+    color: #999;
+    background: #fafafa;
+    width: 1%;
+}
+
+.file-content .file-body.file-code .lines-num span {
+    font-family: Menlo,Monaco,Consolas,"Courier New",monospace;
+    line-height: 1.6;
+    padding: 0 8px 0 10px;
+    cursor: pointer;
+    display: block;
+    margin-top: 6px;
+    font-size: 90%;
+}
+
+.file-content .file-body.file-code .lines-num span:first-child {
     margin-top: 0;
 }
 
-.file-content .file-body.file-code {
-    padding: 0;
+.file-content .file-body.file-code > table {
+    width: 100%;
 }
 
-.file-content .file-body.file-code > pre {
+.file-content .file-body.file-code > table > tbody > tr,
+.file-content .file-body.file-code > table > tbody > tr > td,
+.file-content .file-body.file-code > table {
     border: none;
+    background: none;
 }
 
 .branch-list th, .commit-list th {

+ 8 - 2
public/css/markdown.css

@@ -111,7 +111,6 @@
   line-height: 1.6;
   overflow: auto;
   background: #f8f8f8;
-  padding: 6px 10px;
   border: 1px solid #ddd;
 }
 
@@ -120,6 +119,13 @@
 }
 
 .markdown > pre > ol.linenums {
+  list-style: none;
+  padding: 0;
+}
+
+.markdown > pre.linenums-style > ol.linenums {
+  list-style-type: decimal;
+  padding: 0 0 0 40px;
   -webkit-box-shadow: inset 40px 0 0 #f5f5f5, inset 41px 0 0 #ccc;
   box-shadow: inset 40px 0 0 #f5f5f5, inset 41px 0 0 #ccc;
 }
@@ -142,7 +148,7 @@
   padding-bottom: 12px;
 }
 
-.markdown > pre > ol.linenums > li {
+.markdown > pre.linenums-style > ol.linenums > li {
   border-left: 1px solid #ddd;
 }
 

+ 22 - 1
public/js/app.js

@@ -68,9 +68,30 @@ var Gogits = {
     Gogits.renderMarkdown = function () {
         var $md = $('.markdown');
         var $pre = $md.find('pre > code').parent();
-        $pre.addClass("prettyprint");
+        $pre.addClass('prettyprint');
         prettyPrint();
 
+        var $lineNums = $pre.parent().siblings('.lines-num');
+        if($lineNums.length > 0){
+            var nums = $pre.find('ol.linenums > li').length;
+            for(var i=0;i < nums;i++){
+                $lineNums.append('<span id="L'+i+'" rel=".L'+i+'">'+(i+1)+'</span>');
+            }
+
+            var last;
+            $(document).on('click', '.lines-num span', function(){
+                var $e = $(this);
+                console.log($e.parent().siblings('.lines-code').find('ol.linenums > ' + $e.attr('rel')));
+                console.log('ol.linenums > ' + $e.attr('rel'));
+                if(last){
+                    last.removeClass('active');
+                }
+                last = $e.parent().siblings('.lines-code').find('ol.linenums > ' + $e.attr('rel'));
+                last.addClass('active');
+                window.location.href = '#' + $e.attr('id');
+            });
+        }
+
         // Set anchor.
         var headers = {};
         $md.find('h1, h2, h3, h4, h5, h6').each(function () {

File diff suppressed because it is too large
+ 1 - 1
public/js/lib.js


+ 2 - 0
routers/repo/single.go

@@ -5,6 +5,7 @@
 package repo
 
 import (
+	"path"
 	"strings"
 
 	"github.com/codegangsta/martini"
@@ -95,6 +96,7 @@ func Single(ctx *middleware.Context, params martini.Params) {
 		} else {
 			ctx.Data["IsFile"] = true
 			ctx.Data["FileName"] = repoFile.Name
+			ctx.Data["FileExt"] = path.Ext(repoFile.Name)
 
 			readmeExist := base.IsMarkdownFile(repoFile.Name) || base.IsReadmeFile(repoFile.Name)
 			ctx.Data["ReadmeExist"] = readmeExist

+ 9 - 2
templates/repo/single_file.tmpl

@@ -16,8 +16,15 @@
                 {{.FileContent|str2html}}
             </div>
         {{else}}
-            <div class="panel-body file-body file-code markdown">
-                <pre class="linenums"><code>{{.FileContent}}</code></pre>
+            <div class="panel-body file-body file-code">
+                <table>
+                    <tbody>
+                        <tr>
+                            <td class="lines-num"></td>
+                            <td class="lines-code markdown"><pre class="linenums lang-{{.FileExt}}"><code>{{.FileContent}}</code></pre></td>
+                        </tr>
+                    </tbody>
+                </table>
             </div>
         {{end}}
     {{end}}