Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade chroma to v2.3.0 #21259

Merged
merged 10 commits into from Sep 26, 2022
Merged

Upgrade chroma to v2.3.0 #21259

merged 10 commits into from Sep 26, 2022

Conversation

silverwind
Copy link
Member

@silverwind silverwind commented Sep 25, 2022

The behaviour of PreventSurroundingPre has changed in alecthomas/chroma#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 yuin/goldmark-highlighting#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.

@silverwind silverwind added this to the 1.18.0 milestone Sep 25, 2022
@GiteaBot GiteaBot added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Sep 25, 2022
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Sep 25, 2022
@silverwind
Copy link
Member Author

It might be possible to use chroma.Iterator directly in highlight.go so we can skip the joining and splitting of the HTML altogether and nopWrapper wouldn't be needed as well, checking...

@silverwind silverwind marked this pull request as draft September 25, 2022 15:07
@silverwind
Copy link
Member Author

silverwind commented Sep 25, 2022

Now it uses chroma's SplitTokensIntoLines instead of homebrew line splitting and we don't need the nopWrapper any more.

It seems to work fine, but I'm unsure whether that range loop is as efficient as it can get because if flushs the writer and resets the buffer every iteration. Would appreciate feedback on whether this can be optimized.

@silverwind silverwind marked this pull request as ready for review September 25, 2022 15:39
@wxiaoguang
Copy link
Contributor

Some small changes:

  • remove htmlWriter (no need to have it or do flush), the htmlBuf.Reset will reuse the underlying allocated memory, so no performance problem
  • rename tokensArray to tokensLines to match the function chroma.SplitTokensIntoLines
  • pre-allocate memory for lines with make

and LGTM

@lunny
Copy link
Member

lunny commented Sep 26, 2022

make L-G-T-M work

@lunny lunny merged commit ec0a06e into go-gitea:main Sep 26, 2022
@silverwind silverwind deleted the chroma2 branch September 26, 2022 06:48
zjjhot added a commit to zjjhot/gitea that referenced this pull request Sep 27, 2022
* upstream/main:
  [skip ci] Updated translations via Crowdin
  Add author search input (go-gitea#21246)
  Upgrade chroma to v2.3.0 (go-gitea#21259)
@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants