diff options
author | tjpcc <tjp@ctrl-c.club> | 2023-09-17 16:35:13 -0600 |
---|---|---|
committer | tjpcc <tjp@ctrl-c.club> | 2023-09-17 16:35:13 -0600 |
commit | a7ce20fee62a52794bf8bf940d0fd1f4134158b1 (patch) | |
tree | 2e4c09dce0d5d3bf65a9bfbdb84faa2566b9ce80 /repo.go | |
parent | ce0def95f3924a10b0faceb72aa5df18bf813fb1 (diff) |
protocol-aware README escaping
Diffstat (limited to 'repo.go')
-rw-r--r-- | repo.go | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -211,10 +211,19 @@ type Readme struct { RawContents string } -func (r Readme) EscapedContents() string { +func (r Readme) GeminiEscapedContents() string { return strings.ReplaceAll(r.RawContents, "\n```", "\n ```") } +func (r Readme) GopherEscapedContents(selector, host, port string) string { + trailer := "\t"+selector+"\t"+host+"\t"+port+"\r\n" + lines := strings.Split(r.RawContents, "\n") + for i := range lines { + lines[i] = "i"+strings.TrimRight(strings.ReplaceAll(lines[i], "\t", " "), "\r\n") + trailer + } + return strings.Join(lines, "") +} + func (r *Repository) Readme(ctx context.Context, ref string) (*Readme, error) { dir, err := r.Tree(ctx, ref, "") if err != nil { |