mirror of
https://gitcode.com/gitea/gitea.git
synced 2025-07-05 12:19:55 +08:00
Server-side syntax highlighting for all code (#12047)
* Server-side syntax hilighting for all code This PR does a few things: * Remove all traces of highlight.js * Use chroma library to provide fast syntax hilighting directly on the server * Provide syntax hilighting for diffs * Re-style both unified and split diffs views * Add custom syntax hilighting styling for both regular and arc-green Fixes #7729 Fixes #10157 Fixes #11825 Fixes #7728 Fixes #3872 Fixes #3682 And perhaps gets closer to #9553 * fix line marker * fix repo search * Fix single line select * properly load settings * npm uninstall highlight.js * review suggestion * code review * forgot to call function * fix test * Apply suggestions from code review suggestions from @silverwind thanks Co-authored-by: silverwind <me@silverwind.io> * code review * copy/paste error * Use const for highlight size limit * Update web_src/less/_repository.less Co-authored-by: Lauris BH <lauris@nix.lv> * update size limit to 1MB and other styling tweaks * fix highlighting for certain diff sections * fix test * add worker back as suggested Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
go.modgo.sumpackage-lock.jsonpackage.jsonmodules.txtwebpack.config.js
modules
highlight
indexer/code
markup
repofiles
routers/repo
services/gitdiff
templates
explore
repo
vendor
github.com
alecthomas/chroma
.gitignore.golangci.yml.goreleaser.yml.travis.ymlCOPYINGMakefileREADME.mdcoalesce.gocolour.godelegate.godoc.goformatter.go
formatters/html
go.modgo.sumiterator.golexer.golexers
README.md
mutators.gopygments-lexers.txtregexp.goremap.gostyle.goa
abap.goabnf.goactionscript.goactionscript3.goada.goangular2.goantlr.goapache.goapl.goapplescript.goarduino.goawk.go
b
c
c.gocapnproto.goceylon.gocfengine3.gochaiscript.gocheetah.gocl.goclojure.gocmake.gocobol.gocoffee.gocoldfusion.gocoq.gocpp.gocql.gocrystal.gocsharp.gocss.gocython.go
circular
d
e
f
g
h
hlb.goi
internal
j
k
l
lexers.gom
make.gomako.gomarkdown.gomason.gomathematica.gomatlab.gominizinc.gomlir.gomodula2.gomonkeyc.gomwscript.gomyghty.gomysql.go
n
o
p
pacman.goperl.gopig.gopkgconfig.goplaintext.goplsql.gopostgres.gopostscript.gopovray.gopowershell.goprolog.goprotobuf.gopuppet.gopython.gopython3.go
q
r
s
sas.gosass.goscala.goscheme.goscilab.goscss.gosmalltalk.gosmarty.gosml.gosnobol.gosolidity.gosparql.gosql.gosquid.goswift.gosystemd.gosystemverilog.go
t
tablegen.gotasm.gotcl.gotcsh.gotermcap.goterminfo.goterraform.gotex.gothrift.gotoml.gotradingview.gotransactsql.goturing.goturtle.gotwig.gotypescript.gotyposcript.go
v
w
x
y
styles
abap.goalgol.goalgol_nu.goapi.goarduino.goautumn.goborland.gobw.gocolorful.godracula.goemacs.gofriendly.gofruity.gogithub.goigor.golovelace.gomanni.gomonokai.gomonokailight.gomurphy.gonative.goparaiso-dark.goparaiso-light.gopastie.goperldoc.gopygments.gorainbow_dash.gorrt.gosolarized-dark.gosolarized-dark256.gosolarized-light.goswapoff.gotango.gotrac.govim.govs.goxcode.go
table.pytokentype_string.gotypes.godanwakefield/fnmatch
dlclark/regexp2
gorilla/mux
.travis.ymlAUTHORSISSUE_TEMPLATE.mdLICENSEREADME.mdcontext.gocontext_gorilla.godoc.gogo.modmiddleware.gomux.goregexp.goroute.go
mattn
go-colorable
.travis.ymlREADME.mdcolorable_appengine.gocolorable_others.gocolorable_windows.gogo.modgo.sumgo.test.sh
go-isatty
yuin/goldmark-highlighting
web_src
js
less
87
vendor/github.com/dlclark/regexp2/syntax/replacerdata.go
generated
vendored
Normal file
87
vendor/github.com/dlclark/regexp2/syntax/replacerdata.go
generated
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
package syntax
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type ReplacerData struct {
|
||||
Rep string
|
||||
Strings []string
|
||||
Rules []int
|
||||
}
|
||||
|
||||
const (
|
||||
replaceSpecials = 4
|
||||
replaceLeftPortion = -1
|
||||
replaceRightPortion = -2
|
||||
replaceLastGroup = -3
|
||||
replaceWholeString = -4
|
||||
)
|
||||
|
||||
//ErrReplacementError is a general error during parsing the replacement text
|
||||
var ErrReplacementError = errors.New("Replacement pattern error.")
|
||||
|
||||
// NewReplacerData will populate a reusable replacer data struct based on the given replacement string
|
||||
// and the capture group data from a regexp
|
||||
func NewReplacerData(rep string, caps map[int]int, capsize int, capnames map[string]int, op RegexOptions) (*ReplacerData, error) {
|
||||
p := parser{
|
||||
options: op,
|
||||
caps: caps,
|
||||
capsize: capsize,
|
||||
capnames: capnames,
|
||||
}
|
||||
p.setPattern(rep)
|
||||
concat, err := p.scanReplacement()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if concat.t != ntConcatenate {
|
||||
panic(ErrReplacementError)
|
||||
}
|
||||
|
||||
sb := &bytes.Buffer{}
|
||||
var (
|
||||
strings []string
|
||||
rules []int
|
||||
)
|
||||
|
||||
for _, child := range concat.children {
|
||||
switch child.t {
|
||||
case ntMulti:
|
||||
child.writeStrToBuf(sb)
|
||||
|
||||
case ntOne:
|
||||
sb.WriteRune(child.ch)
|
||||
|
||||
case ntRef:
|
||||
if sb.Len() > 0 {
|
||||
rules = append(rules, len(strings))
|
||||
strings = append(strings, sb.String())
|
||||
sb.Reset()
|
||||
}
|
||||
slot := child.m
|
||||
|
||||
if len(caps) > 0 && slot >= 0 {
|
||||
slot = caps[slot]
|
||||
}
|
||||
|
||||
rules = append(rules, -replaceSpecials-1-slot)
|
||||
|
||||
default:
|
||||
panic(ErrReplacementError)
|
||||
}
|
||||
}
|
||||
|
||||
if sb.Len() > 0 {
|
||||
rules = append(rules, len(strings))
|
||||
strings = append(strings, sb.String())
|
||||
}
|
||||
|
||||
return &ReplacerData{
|
||||
Rep: rep,
|
||||
Strings: strings,
|
||||
Rules: rules,
|
||||
}, nil
|
||||
}
|
Reference in New Issue
Block a user