diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2022-07-23 19:28:02 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-23 19:28:02 +0800 |
commit | 3310dd1d197495fbfa2d7ee490e19e6d08e1d30f (patch) | |
tree | 3903990d31f63fede56b555551796d52d960e018 /modules | |
parent | 14178c56bb0fbc8b0b5820539e7681a7defeff47 (diff) | |
download | gitea-3310dd1d197495fbfa2d7ee490e19e6d08e1d30f.tar.gz gitea-3310dd1d197495fbfa2d7ee490e19e6d08e1d30f.zip |
Improve code diff highlight, fix incorrect rendered diff result (#19958)
Use Unicode placeholders to replace HTML tags and HTML entities first, then do diff, then recover the HTML tags and HTML entities. Now the code diff with highlight has stable behavior, and won't emit broken tags.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/highlight/highlight.go | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/modules/highlight/highlight.go b/modules/highlight/highlight.go index acd3bebb9f..6832207c0f 100644 --- a/modules/highlight/highlight.go +++ b/modules/highlight/highlight.go @@ -40,9 +40,11 @@ var ( // NewContext loads custom highlight map from local config func NewContext() { once.Do(func() { - keys := setting.Cfg.Section("highlight.mapping").Keys() - for i := range keys { - highlightMapping[keys[i].Name()] = keys[i].Value() + if setting.Cfg != nil { + keys := setting.Cfg.Section("highlight.mapping").Keys() + for i := range keys { + highlightMapping[keys[i].Name()] = keys[i].Value() + } } // The size 512 is simply a conservative rule of thumb |