Browse Source

#2103 #2181 improvments of highlight class name

pull/2222/head
Unknwon 9 years ago
parent
commit
6673dcb038
  1. 2
      README.md
  2. 5
      conf/locale/TRANSLATORS
  3. 2
      conf/locale/locale_en-US.ini
  4. 2
      gogs.go
  5. 8
      modules/bindata/bindata.go
  6. 80
      modules/template/highlight.go
  7. 6
      routers/repo/view.go
  8. 2
      templates/.VERSION
  9. 2
      templates/repo/view_file.tmpl

2
README.md

@ -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 |
|:-------------:|:-------:|:-------:| |:-------------:|:-------:|:-------:|

5
conf/locale/TRANSLATORS

@ -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>

2
conf/locale/locale_en-US.ini

@ -1056,5 +1056,5 @@ raw_minutes = minutes
[dropzone] [dropzone]
default_message = Drop files here or click to upload. default_message = Drop files here or click to upload.
invalid_input_type = You can't upload files of this type. invalid_input_type = You can't upload files of this type.
file_too_big = File size({{filesize}} MB) exceeds maximum size({{maxFilesize}} MB). file_too_big = File size ({{filesize}} MB) exceeds maximum size ({{maxFilesize}} MB).
remove_file = Remove file remove_file = Remove file

2
gogs.go

@ -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())

8
modules/bindata/bindata.go

File diff suppressed because one or more lines are too long

80
modules/template/highlight.go

@ -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 ""
}

6
routers/repo/view.go

@ -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)

2
templates/.VERSION

@ -1 +1 @@
0.8.7.1215 0.8.8.1216

2
templates/repo/view_file.tmpl

@ -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>

Loading…
Cancel
Save