diff options
-rw-r--r-- | modules/base/markdown.go | 4 | ||||
-rwxr-xr-x | public/css/gogs.css | 8 | ||||
-rw-r--r-- | public/css/markdown.css | 59 | ||||
-rw-r--r-- | public/js/app.js | 23 | ||||
-rw-r--r-- | routers/repo/single.go | 3 | ||||
-rw-r--r-- | templates/repo/single_file.tmpl | 10 |
6 files changed, 95 insertions, 12 deletions
diff --git a/modules/base/markdown.go b/modules/base/markdown.go index a9f4cbf0..e49e111c 100644 --- a/modules/base/markdown.go +++ b/modules/base/markdown.go @@ -36,7 +36,7 @@ func isLink(link []byte) bool { func IsMarkdownFile(name string) bool { name = strings.ToLower(name) switch filepath.Ext(name) { - case "md", "markdown": + case "md", "markdown", "mdown": return true } return false @@ -61,7 +61,7 @@ type CustomRender struct { func (options *CustomRender) Link(out *bytes.Buffer, link []byte, title []byte, content []byte) { if len(link) > 0 && !isLink(link) { if link[0] == '#' { - link = append([]byte(options.urlPrefix), link...) + // link = append([]byte(options.urlPrefix), link...) } else { link = []byte(path.Join(options.urlPrefix, string(link))) } diff --git a/public/css/gogs.css b/public/css/gogs.css index d2ba5b9a..eb5f7ad2 100755 --- a/public/css/gogs.css +++ b/public/css/gogs.css @@ -659,6 +659,14 @@ html, body { margin-top: 0; } +.file-content .file-body.file-code { + padding: 0; +} + +.file-content .file-body.file-code > pre { + border: none; +} + .branch-list th, .commit-list th { background-color: #FFF; line-height: 28px !important; diff --git a/public/css/markdown.css b/public/css/markdown.css index 9283fb84..1edc3b62 100644 --- a/public/css/markdown.css +++ b/public/css/markdown.css @@ -15,7 +15,8 @@ line-height: 1.7; padding: 15px 0 0; margin: 0 0 15px; - color: #666; + color: #444; + font-weight: bold; } .markdown h1, @@ -86,6 +87,10 @@ margin-top: 6px; } +.markdown li:first-child { + margin-top: 0; +} + .markdown dl dt { font-style: italic; margin-top: 9px; @@ -130,11 +135,11 @@ } .markdown > pre > ol.linenums > li:first-child { - padding-top: 6px; + padding-top: 12px; } .markdown > pre > ol.linenums > li:last-child { - padding-bottom: 6px; + padding-bottom: 12px; } .markdown > pre > ol.linenums > li { @@ -163,6 +168,54 @@ color: #fff; } +.markdown .anchor-wrap { + /*margin-top: -50px;*/ + /*padding-top: 50px;*/ +} + +.markdown h1 a, .markdown h2 a, .markdown h3 a { + text-decoration: none; +} + +.markdown h1 a.anchor, +.markdown h2 a.anchor, +.markdown h3 a.anchor, +.markdown h4 a.anchor, +.markdown h5 a.anchor, +.markdown h6 a.anchor { + text-decoration:none; + line-height:1; + padding-left:0; + margin-left:5px; + top:15%; +} +.markdown a span.octicon { + font-size: 16px; + font-family: "FontAwesome"; + line-height: 1; + display: inline-block; + text-decoration: none; + -webkit-font-smoothing: antialiased; +} + +.markdown a span.octicon-link { + display: none; + color: #000; +} + +.markdown a span.octicon-link:before { + content: "\f0c1"; +} + +.markdown h1:hover .octicon-link, +.markdown h2:hover .octicon-link, +.markdown h3:hover .octicon-link, +.markdown h4:hover .octicon-link, +.markdown h5:hover .octicon-link, +.markdown h6:hover .octicon-link { + display:inline-block +} + /* Author: jmblog */ /* Project: https://github.com/jmblog/color-themes-for-google-code-prettify */ /* GitHub Theme */ diff --git a/public/js/app.js b/public/js/app.js index 1f64b529..12f9e7f3 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -66,9 +66,28 @@ var Gogits = { // render markdown Gogits.renderMarkdown = function () { - var $pre = $('.markdown').find('pre > code').parent(); - $pre.addClass("prettyprint linenums"); + var $md = $('.markdown'); + var $pre = $md.find('pre > code').parent(); + $pre.addClass("prettyprint"); prettyPrint(); + + // Set anchor. + var headers = {}; + $md.find('h1, h2, h3, h4, h5, h6').each(function () { + var node = $(this); + var val = encodeURIComponent(node.text().toLowerCase().replace(/[^\w\- ]/g, '').replace(/[ ]/g, '-')); + var name = val; + if(headers[val] > 0){ + name = val + '-' + headers[val]; + } + if(headers[val] == undefined){ + headers[val] = 1; + }else{ + headers[val] += 1; + } + node = node.wrap('<div id="' + name + '" class="anchor-wrap" ></div>'); + node.append('<a class="anchor" href="#' + name + '"><span class="octicon octicon-link"></span></a>'); + }); } })(jQuery); diff --git a/routers/repo/single.go b/routers/repo/single.go index 4a6af9ff..6eb839c1 100644 --- a/routers/repo/single.go +++ b/routers/repo/single.go @@ -139,10 +139,9 @@ func Single(ctx *middleware.Context, params martini.Params) { return } else { // current repo branch link - urlPrefix := "http://" + base.Domain + branchLink ctx.Data["FileName"] = readmeFile.Name - ctx.Data["FileContent"] = string(base.RenderMarkdown(blob.Contents(), urlPrefix)) + ctx.Data["FileContent"] = string(base.RenderMarkdown(blob.Contents(), branchLink)) } } } diff --git a/templates/repo/single_file.tmpl b/templates/repo/single_file.tmpl index b4626053..0c1c3713 100644 --- a/templates/repo/single_file.tmpl +++ b/templates/repo/single_file.tmpl @@ -1,6 +1,10 @@ <div class="panel panel-default file-content"> <div class="panel-heading file-head"> - <i class="icon fa fa-book"></i> {{.FileName}} + {{if .ReadmeExist}} + <i class="icon fa fa-book"></i> + {{else}} + <i class="icon fa fa-file-text-o"></i> + {{end}}{{.FileName}} </div> {{if .FileIsLarge}} <div class="panel-footer"> @@ -12,8 +16,8 @@ {{.FileContent|str2html}} </div> {{else}} - <div class="panel-body file-body markdown"> - <pre><code>{{.FileContent}}</code></pre> + <div class="panel-body file-body file-code markdown"> + <pre class="linenums"><code>{{.FileContent}}</code></pre> </div> {{end}} {{end}} |