#2103 #2181 improvments of highlight class name

This commit is contained in:
Unknwon 2015-12-16 22:13:12 -05:00
parent 71142929cc
commit 6673dcb038
9 changed files with 95 additions and 14 deletions

View file

@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true) ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
##### Current version: 0.8.7 ##### Current version: 0.8.8
| Web | UI | Preview | | Web | UI | Preview |
|:-------------:|:-------:|:-------:| |:-------------:|:-------:|:-------:|

View file

@ -1,8 +1,11 @@
# This file lists all PUBLIC individuals having contributed content to the translation. # This file lists all PUBLIC individuals having contributed content to the translation.
# Entries are in alphabetical order. # Entries are in alphabetical order.
Adam Strzelecki <ono AT java DOT pl>
Adrian Verde <me AT adrianverde DOT com>
Akihiro YAGASAKI <yaggytter AT momiage DOT com> Akihiro YAGASAKI <yaggytter AT momiage DOT com>
Aleksejs Grocevs <aleksejs AT grocevs DOT pro> Aleksejs Grocevs <aleksejs AT grocevs DOT pro>
Aleksey Tarakin <hukendo AT yandex DOT ru>
Alexander Steinhöfer <kontakt AT lx-s DOT de> Alexander Steinhöfer <kontakt AT lx-s DOT de>
Alexandre Magno <alexandre DOT mbm AT gmail DOT com> Alexandre Magno <alexandre DOT mbm AT gmail DOT com>
Andrey Nering <andrey AT nering DOT com DOT br> Andrey Nering <andrey AT nering DOT com DOT br>
@ -19,11 +22,13 @@ Hamid Feizabadi <hamidfzm AT gmail DOT com>
Huimin Wang <wanghm2009 AT hotmail DOT co DOT jp> Huimin Wang <wanghm2009 AT hotmail DOT co DOT jp>
ilko ilko
Ilya Makarov Ilya Makarov
Juraj Bubniak <contact AT jbub DOT eu>
Lafriks <lafriks AT gmail DOT com> Lafriks <lafriks AT gmail DOT com>
Lauri Ojansivu <x AT xet7 DOT org> Lauri Ojansivu <x AT xet7 DOT org>
Luc Stepniewski <luc AT stepniewski DOT fr> Luc Stepniewski <luc AT stepniewski DOT fr>
Marc Schiller <marc AT schiller DOT im> Marc Schiller <marc AT schiller DOT im>
Miguel de la Cruz <miguel AT mcrx DOT me> Miguel de la Cruz <miguel AT mcrx DOT me>
Mikhail Burdin <xdshot9000 AT gmail DOT com>
Morten Sørensen <klim8d AT gmail DOT com> Morten Sørensen <klim8d AT gmail DOT com>
Nakao Takamasa <at.mattenn AT gmail DOT com> Nakao Takamasa <at.mattenn AT gmail DOT com>
Natan Albuquerque <natanalbuquerque5 AT gmail DOT com> Natan Albuquerque <natanalbuquerque5 AT gmail DOT com>

View file

@ -18,7 +18,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.8.7.1215" const APP_VER = "0.8.8.1216"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,80 @@
// Copyright 2015 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package template
import (
"path"
"strings"
)
var (
// File name should ignore highlight.
ignoreFileNames = map[string]bool{
"license": true,
"copying": true,
}
// File names that are representing highlight class.
highlightFileNames = map[string]bool{
"dockerfile": true,
"makefile": true,
}
// Extensions that are same as highlight class.
highlightExts = map[string]bool{
".arm": true,
".as": true,
".sh": true,
".cs": true,
".cpp": true,
".c": true,
".css": true,
".cmake": true,
".bat": true,
".dart": true,
".patch": true,
".elixir": true,
".erlang": true,
".go": true,
".html": true,
".xml": true,
".hs": true,
".ini": true,
".json": true,
".java": true,
".js": true,
".less": true,
".lua": true,
".php": true,
".py": true,
".rb": true,
".scss": true,
".sql": true,
".scala": true,
".swift": true,
".ts": true,
".vb": true,
}
)
// FileNameToHighlightClass returns the best match for highlight class name
// based on the rule of highlight.js.
func FileNameToHighlightClass(fname string) string {
fname = strings.ToLower(fname)
if ignoreFileNames[fname] {
return "nohighlight"
}
if highlightFileNames[fname] {
return fname
}
ext := path.Ext(fname)
if highlightExts[ext] {
return ext[1:]
}
return ""
}

View file

@ -79,11 +79,7 @@ func Home(ctx *middleware.Context) {
ctx.Data["FileSize"] = blob.Size() ctx.Data["FileSize"] = blob.Size()
ctx.Data["IsFile"] = true ctx.Data["IsFile"] = true
ctx.Data["FileName"] = blob.Name() ctx.Data["FileName"] = blob.Name()
ext := path.Ext(blob.Name()) ctx.Data["HighlightClass"] = template.FileNameToHighlightClass(blob.Name())
if len(ext) > 0 {
ext = ext[1:]
}
ctx.Data["FileExt"] = ext
ctx.Data["FileLink"] = rawLink + "/" + treename ctx.Data["FileLink"] = rawLink + "/" + treename
buf := make([]byte, 1024) buf := make([]byte, 1024)

View file

@ -1 +1 @@
0.8.7.1215 0.8.8.1216

View file

@ -40,7 +40,7 @@
<tbody> <tbody>
<tr> <tr>
<td class="lines-num"></td> <td class="lines-num"></td>
<td class="lines-code"><pre class="{{if .FileExt}}lang-{{.FileExt}}{{end}}"><code><ol class="linenums">{{.FileContent}}</ol></code></pre></td> <td class="lines-code"><pre><code class="{{.HighlightClass}}"><ol class="linenums">{{.FileContent}}</ol></code></pre></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>