-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Fix copy/paste of empty lines #19798
Conversation
Fixes: go-gitea#19331 Regressed by: go-gitea#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 go-gitea#18270 (comment) broke our previous newline replacement for such empty lines. Also included are a few changes to make the test more pleasant to work with.
The func main() {
m := regexp.MustCompile(`(?m:^\s*(.*?)\s*$)`) // use multi-line mode to trim spaces
s := " a \n\tb c \n"
t := m.ReplaceAllString(s, "$1")
fmt.Printf("origin:\n%s\n--------\ntrimed:\n%s\n(len=%d)\n", s, t, len(t))
}
|
Might be an option, yeah. One thing I don't like about the dependency is that it does not handle leading/trailing newlines, I mentioned it in lithammer/dedent#14. |
Actually, this is not a true dedent because |
Oh yup, I was thinking that the spaces should have been wrapped inside tags, so all spaces around the line could be trimmed. If it's not the case, then regex won't work. |
Refactored to |
ready to merge from my side. |
I think this could be in 1.17 (keep it open for one or two days for more suggestions) |
I'd even backport it to 1.16. I copy a lot of code from UI and it's a big issue for me. |
* giteaoffical/main: Fix data-race problems in git module (quick patch) (go-gitea#19934) [skip ci] Updated translations via Crowdin Fix copy/paste of empty lines (go-gitea#19798) Normalize line endings in fomantic build files (go-gitea#19932) Make user profile image show full image on mobile (go-gitea#19840) Custom regexp external issues (go-gitea#17624) Use Golang 1.18 for Gitea 1.17 release (go-gitea#19918) Refactor git module, make Gitea use internal git config (go-gitea#19732) [skip ci] Updated translations via Crowdin
Followup to go-gitea#19798. Trim off both the .line and .cl classes from Chroma's HTML which made the old conditional work again. This fixed Copy of YAML files for me.
Fixes: go-gitea#19331 Followup to go-gitea#19798. Trim off both the .line and .cl classes from Chroma's HTML which made the old conditional work again. This fixed Copy of YAML files for me while also reducing the amount of rendered HTML nodes.
* Fix copy/paste of empty newlines again Fixes: go-gitea#19331 Regressed by: go-gitea#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 go-gitea#18270 (comment) 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>
Fixes: #19331
Regressed by: #18270
Needed to do another string replacement in 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 #18270 (comment) broke our previous newline replacement for such empty lines.
Also included are a few changes to make the test more pleasant to work with.