Skip to content

Commit

Permalink
Properly wrap paste content, add toggleable line numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
auravoid committed Jul 31, 2024
1 parent b27e6d9 commit 81dc673
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
10 changes: 10 additions & 0 deletions cmd/tclipd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
httpPort = flag.String("http-port", envOr("HTTP_PORT", ""), "optional http port to start an http server on, e.g for reverse proxies. will only serve funnel endpoints")
controlUrl = flag.String("control-url", envOr("TSNET_CONTROL_URL", ""), "optional alternate control server URL to use, for e.g. headscale")
disableHTTPS = flag.Bool("disable-https", hasEnv("DISABLE_HTTPS"), "disable http serve, required for Headscale support")
disableLineNumbers= flag.Bool("disable-line-numbers", hasEnv("DISABLE_LINE_NUMBERS"), "disables line numbers on paste content")

//go:embed schema.sql
sqlSchema string
Expand Down Expand Up @@ -517,6 +518,7 @@ WHERE p.id = ?1`
var fname, data, userLoginName, userDisplayName, userProfilePicURL string
var userID int64
var createdAt string
var lineNumbers string

err := row.Scan(&fname, &createdAt, &data, &userID, &userLoginName, &userDisplayName, &userProfilePicURL)
if err != nil {
Expand All @@ -537,6 +539,12 @@ WHERE p.id = ?1`
cssClass = fmt.Sprintf("lang-%s", strings.ToLower(lang))
}

lineNumbers = "line-numbers"

if *disableLineNumbers {
lineNumbers = "no-line-numbers"
}

p := bluemonday.UGCPolicy()
p.AllowAttrs("class").Matching(regexp.MustCompile("^language-[a-zA-Z0-9]+$")).OnElements("code")

Expand Down Expand Up @@ -654,6 +662,7 @@ WHERE p.id = ?1`
Data string
RawHTML *template.HTML
CSSClass string
DisableLineNumbers string
}{
UserInfo: up,
Title: fname,
Expand All @@ -667,6 +676,7 @@ WHERE p.id = ?1`
Data: data,
RawHTML: rawHTML,
CSSClass: cssClass,
DisableLineNumbers: lineNumbers,
})
if err != nil {
log.Printf("%s: %v", r.RemoteAddr, err)
Expand Down
3 changes: 2 additions & 1 deletion cmd/tclipd/static/css/prism.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 81dc673

Please sign in to comment.