summaryrefslogtreecommitdiffstats
path: root/modules/highlight
Commit message (Collapse)AuthorAgeFilesLines
* Upgrade chroma to v2.3.0 (#21259)silverwind2022-09-261-22/+17
| | | | | | | | | | | | | The behaviour of `PreventSurroundingPre` has changed in https://github.com/alecthomas/chroma/pull/618 so that apparently it now causes line wrapper tags to be no longer emitted, but we need some form of indication to split the HTML into lines, so I did what https://github.com/yuin/goldmark-highlighting/pull/33 did and added the `nopWrapper`. Maybe there are more elegant solutions but for some reason, just splitting the HTML string on `\n` did not work. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Rework file highlight rendering and fix yaml copy-paste (#19967)silverwind2022-07-302-130/+164
| | | | | | | | | | | * Rework file highlight rendering and fix yaml copy-paste * use Split+Trim to replace tag parser * remove unnecessary bytes.Count * remove newLineInHTML = "&#10;" Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Improve code diff highlight, fix incorrect rendered diff result (#19958)wxiaoguang2022-07-231-3/+5
| | | 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.
* Add more linters to improve code readability (#19989)Wim2022-06-201-4/+4
| | | | | | | | | | Add nakedret, unconvert, wastedassign, stylecheck and nolintlint linters to improve code readability - nakedret - https://github.com/alexkohler/nakedret - nakedret is a Go static analysis tool to find naked returns in functions greater than a specified function length. - unconvert - https://github.com/mdempsky/unconvert - Remove unnecessary type conversions - wastedassign - https://github.com/sanposhiho/wastedassign - wastedassign finds wasted assignment statements. - notlintlint - Reports ill-formed or insufficient nolint directives - stylecheck - https://staticcheck.io/docs/checks/#ST - keep style consistent - excluded: [ST1003 - Poorly chosen identifier](https://staticcheck.io/docs/checks/#ST1003) and [ST1005 - Incorrectly formatted error string](https://staticcheck.io/docs/checks/#ST1005)
* Fix copy/paste of empty lines (#19798)silverwind2022-06-102-61/+65
| | | | | | | | | | | | | | | | | | | | | | | | | | | * Fix copy/paste of empty newlines again Fixes: https://github.com/go-gitea/gitea/issues/19331 Regressed by: https://github.com/go-gitea/gitea/pull/18270 Needed to do another newline addition to the Chroma output HTML to get copy/paste work again. The previous replacement conditions are probably obsolete, but as I'm not 100% sure, I opted to keep them. Specifically, the Chroma HTML change mentioned in https://github.com/go-gitea/gitea/pull/18270#issuecomment-1013350246 broke our previous newline replacement for such empty lines. Also included are a few changes to make the test more pleasant to work with. * run go mod tidy * add util.Dedent * copy in the code Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Lauris BH <lauris@nix.lv>
* format with gofumpt (#18184)65432022-01-201-3/+3
| | | | | | | | | | | * gofumpt -w -l . * gofumpt -w -l -extra . * Add linter * manual fix * change make fmt
* Updated Chroma to v0.10.0 (#18270)Jelle Hulter2022-01-201-28/+26
|
* Add .gitattribute assisted language detection to blame, diff and render (#17590)zeripath2021-11-172-8/+30
| | | | | | | Use check attribute code to check the assigned language of a file and send that in to chroma as a hint for the language of the file. Signed-off-by: Andrew Thornton <art27@cantab.net>
* A better go code formatter, and now `make fmt` can run in Windows (#17684)wxiaoguang2021-11-172-0/+2
| | | | * go build / format tools * re-format imports
* Prevent panic in Org mode HighlightCodeBlock (#17140)zeripath2021-09-241-11/+12
| | | | | | | | | | | When rendering source in org mode there is a mistake in the highlight code that causes a panic. This PR fixes this. Fix #17139 Signed-off-by: Andrew Thornton <art27@cantab.net>
* Just use a slice when rendering file (#16774)zeripath2021-08-232-41/+39
| | | | | | Highlight currently uses a map which is memory inefficient. Switch to use a slice instead. Signed-off-by: Andrew Thornton <art27@cantab.net>
* Ensure empty lines are copiable and final new line too (#16678)zeripath2021-08-142-0/+116
| | | | | | | | | | | | * Ensure empty lines are copiable and final new line too When files are highlighted the newline character needs to be added in a whitespace compliant mode. Also ensure the final empty newline is rendered. Fix #16434 * Add test and ensure spans closed Signed-off-by: Andrew Thornton <art27@cantab.net>
* Replace ARCCache with TwoQueueCache to avoid patent issue (#16240)Mura Li2021-06-241-2/+2
| | | | Co-authored-by: Mura Li <typeless@users.noreply.github.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
* Speed up git diff highlight generation (#16180)Mura Li2021-06-171-0/+18
| | | | Co-authored-by: Mura Li <typeless@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
* Allow custom highlight mapping beyond file extensions (#15808)mlpo2021-05-131-10/+17
| | | Co-authored-by: Lauris BH <lauris@nix.lv>
* Use existing analyzer module for language detection for highlighting (#13522)mrsdizzie2020-11-131-2/+5
| | | | | | | | | | | | | * Use existing analyzer module for language detction for highlighting Thanks @lafriks for pointing out we can reuse existing code for more reliable language detection here. * Update modules/highlight/highlight.go Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
* Escape failed highlighted code (#12685)zeripath2020-09-021-1/+2
| | | Signed-off-by: Andrew Thornton <art27@cantab.net>
* Ensure syntax highlighting is the same inside diffs (#12205)mrsdizzie2020-07-111-4/+8
| | | | | Make sure to end up with the same syntax highlighting inside various sections of diffs by processing the code first before detecting specific changes between the lines. Also try and make sure that when highlighting individual lines in a diff that it is tokenized the same as it would be when part of an entire file with more context. Fixes: #12190
* Make copy/paste work for source code (#12191)mrsdizzie2020-07-081-2/+15
| | | | | | | | | | | | | | | * Make copy/paste work for source code Fix regression casued by #12047 so copy/paste works properly in all browsers. Fixes #12184 Also while looking at this I saw a small display issue for blame view. I think #12023 was merged into original PR through an update branch before #12047 was merged and made one of the css ruules not apply anymore. * use pseudo-element to prevent copying of comment + symbol even when not visually selected * remove added newline here should not be necessary anymore * make sure empty line is newline so there is something to select and copy
* Remove newline when highlighting random chunks of code (#12180)mrsdizzie2020-07-081-1/+2
| | | | | | | | | | | * Remove newline when highlighting random chunks of code Somewhere when tokenizing a newline gets added to code formatted by chroma. This breaks the case of 'added-code' inside of an 'added-line' in a diff. Just remove any newline when processing chunks of code since we don't need it. Fixes #12172 * don't process empty lines * This is the proper way to fix this by telling chroma not to add the newline in the first place
* Server-side syntax highlighting for all code (#12047)mrsdizzie2020-07-011-119/+116
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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>
* Add a lot of extension to language mappings for syntax highlights (#7741)silverwind2019-08-051-35/+79
| | | | | Data partially based on [CodeMirror's meta.js](https://github.com/codemirror/CodeMirror/blob/master/mode/meta.js). Fixes: https://github.com/go-gitea/gitea/issues/6057
* Fix specific highlighting (CMakeLists.txt ...) (#7686)FlorianBen2019-08-041-5/+7
| | | | | | | | * Fix specific highlighting. * Highlighting CMakeLists.txt: remove case sensitive checks. use lowercase checks instead.
* Add Rust highlighting (#7125)Rob Watson2019-06-041-0/+1
|
* Fix Erlang and Elixir highlight mappings (#7044)Robert A. Nowak2019-05-301-35/+37
|
* No highlighting for .txt files (#1922)Ethan Koenig2017-06-091-1/+3
|
* Update HighlightJS and fix YAML files highlighting (#1764)Andrey Nering2017-05-201-34/+36
| | | | | | * Update HighlightJS to 9.11.0 * Fix YAML files highlighting
* Integrate templates into bindata optionally (#314)Thomas Boerger2016-12-061-0/+98
Integrated optional bindata for the templates