-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Switch Unicode Escaping to a VSCode-like system #19990
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
2e935d3
Switch Unicode Escaping to a VSCode-like system
zeripath 0f00129
placate lint
zeripath 1b626e2
Merge remote-tracking branch 'origin/main' into vscode-escape
zeripath 5d0aaf1
fix template issue
zeripath 0fb4df2
Merge remote-tracking branch 'origin' into vscode-escape
zeripath 7826c68
placate yet another linter
zeripath 872844f
more placation
zeripath a638e64
Merge branch 'main' into vscode-escape
zeripath 8a448aa
Use var colors
zeripath f49a102
Merge remote-tracking branch 'origin/main' into vscode-escape
zeripath 3eddae1
add missing fix
zeripath d7b03b0
permit raw nbsps in rendered markdown
zeripath bb36c71
Merge branch 'main' into vscode-escape
lafriks c74f7bf
Update modules/charset/ambiguous.go
zeripath a3702f2
Merge branch 'main' into vscode-escape
wxiaoguang 739c4ba
Merge branch 'main' into vscode-escape
zeripath 9b83725
Merge remote-tracking branch 'origin/main' into vscode-escape
zeripath a16e264
as per review
zeripath 39f15b9
as per review
zeripath c73d810
fix test
zeripath bf0d9dc
placate lint
zeripath cd27248
Merge remote-tracking branch 'origin/main' into vscode-escape
zeripath bd1336b
Make it clearer where ambiguous.json comes from
zeripath 31954cc
use template for code declarations in diff
zeripath 9c336a6
furhter subtemplating
zeripath afc0064
Merge branch 'main' into vscode-escape
zeripath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package charset | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
) | ||
|
||
// BreakWriter wraps an io.Writer to always write '\n' as '<br>' | ||
type BreakWriter struct { | ||
io.Writer | ||
} | ||
|
||
// Write writes the provided bs transparently replacing '\n' with '<br>' | ||
func (b *BreakWriter) Write(bs []byte) (n int, err error) { | ||
pos := 0 | ||
for pos < len(bs) { | ||
idx := bytes.IndexByte(bs[pos:], '\n') | ||
if idx < 0 { | ||
wn, err := b.Writer.Write(bs[pos:]) | ||
return n + wn, err | ||
} | ||
|
||
if idx > 0 { | ||
wn, err := b.Writer.Write(bs[pos : pos+idx]) | ||
n += wn | ||
if err != nil { | ||
return n, err | ||
} | ||
} | ||
|
||
if _, err = b.Writer.Write([]byte("<br>")); err != nil { | ||
return n, err | ||
} | ||
pos += idx + 1 | ||
|
||
n++ | ||
} | ||
|
||
return n, err | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package charset | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestBreakWriter_Write(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
kase string | ||
expect string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "noline", | ||
kase: "abcdefghijklmnopqrstuvwxyz", | ||
expect: "abcdefghijklmnopqrstuvwxyz", | ||
}, | ||
{ | ||
name: "endline", | ||
kase: "abcdefghijklmnopqrstuvwxyz\n", | ||
expect: "abcdefghijklmnopqrstuvwxyz<br>", | ||
}, | ||
{ | ||
name: "startline", | ||
kase: "\nabcdefghijklmnopqrstuvwxyz", | ||
expect: "<br>abcdefghijklmnopqrstuvwxyz", | ||
}, | ||
{ | ||
name: "onlyline", | ||
kase: "\n\n\n", | ||
expect: "<br><br><br>", | ||
}, | ||
{ | ||
name: "empty", | ||
kase: "", | ||
expect: "", | ||
}, | ||
{ | ||
name: "midline", | ||
kase: "\nabc\ndefghijkl\nmnopqrstuvwxy\nz", | ||
expect: "<br>abc<br>defghijkl<br>mnopqrstuvwxy<br>z", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
buf := &strings.Builder{} | ||
b := &BreakWriter{ | ||
Writer: buf, | ||
} | ||
n, err := b.Write([]byte(tt.kase)) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("BreakWriter.Write() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if n != len(tt.kase) { | ||
t.Errorf("BreakWriter.Write() = %v, want %v", n, len(tt.kase)) | ||
} | ||
if buf.String() != tt.expect { | ||
t.Errorf("BreakWriter.Write() wrote %q, want %v", buf.String(), tt.expect) | ||
} | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.