Skip to content

Commit 07b6da1

Browse files
committed
styling of chroma
1 parent 17cd58d commit 07b6da1

File tree

3 files changed

+27
-29
lines changed

3 files changed

+27
-29
lines changed

dashboard/views/event-details.templ

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import (
1414
// BodyContent renders a truncated body with a maximum length and syntax highlighting
1515
templ BodyContent(content string, contentType string, maxLength int) {
1616
if len(content) > maxLength {
17-
<div class="bg-neutral-50 p-3 rounded border border-neutral-200 font-mono text-sm">
17+
<div class="bg p-3 rounded border border-neutral-200 font-mono text-sm">
1818
<pre class="whitespace-pre-wrap break-words">{ content[:maxLength] }...</pre>
1919
</div>
2020
} else {
21-
<div class="bg-neutral-50 p-3 rounded border border-neutral-200 font-mono text-sm">
22-
@templ.Raw(highlightContent(content, contentType))
21+
<div class="bg p-3 rounded border border-neutral-200 font-mono text-sm">
22+
@highlightContent(content, contentType)
2323
</div>
2424
}
2525
}

dashboard/views/event-details_templ.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dashboard/views/helper.go

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package views
22

33
import (
4-
"bytes"
54
"context"
65
"fmt"
76
"io"
@@ -36,32 +35,29 @@ func formatDurationSince(t time.Time) string {
3635
}
3736

3837
// highlightContent applies syntax highlighting to the content
39-
func highlightContent(content string, contentType string) string {
40-
// Split content type before ;
41-
contentType = strings.Split(contentType, ";")[0]
38+
func highlightContent(content string, contentType string) templ.Component {
39+
return templ.ComponentFunc(func(ctx context.Context, w io.Writer) error {
40+
// Split content type before ;
41+
contentType = strings.Split(contentType, ";")[0]
4242

43-
lexer := lexers.MatchMimeType(contentType)
44-
if lexer == nil {
45-
fmt.Printf("DEBUG: mime type not matched: %q\n", contentType)
46-
lexer = lexers.Fallback
47-
} else {
48-
fmt.Printf("DEBUG: mime type matched lexer: %q\n", lexer.Config().Name)
49-
}
43+
lexer := lexers.MatchMimeType(contentType)
44+
if lexer == nil {
45+
fmt.Printf("DEBUG: mime type not matched: %q\n", contentType)
46+
lexer = lexers.Fallback
47+
} else {
48+
fmt.Printf("DEBUG: mime type matched lexer: %q\n", lexer.Config().Name)
49+
}
5050

51-
formatter, style := chromaFormatterAndStyle()
51+
formatter, style := chromaFormatterAndStyle()
5252

53-
iterator, err := lexer.Tokenise(nil, content)
54-
if err != nil {
55-
return content
56-
}
53+
iterator, err := lexer.Tokenise(nil, content)
54+
if err != nil {
55+
return err
56+
}
5757

58-
var buf bytes.Buffer
59-
err = formatter.Format(&buf, style, iterator)
60-
if err != nil {
61-
return content
62-
}
63-
64-
return buf.String()
58+
err = formatter.Format(w, style, iterator)
59+
return err
60+
})
6561
}
6662

6763
func chromaFormatterAndStyle() (*html.Formatter, *chroma.Style) {
@@ -84,6 +80,8 @@ func chromaStyles() templ.Component {
8480
_, _ = io.WriteString(w, "<style>")
8581
formatter, style := chromaFormatterAndStyle()
8682
err := formatter.WriteCSS(w, style)
83+
84+
_, _ = io.WriteString(w, ".chroma { white-space: pre-wrap; }\n")
8785
_, _ = io.WriteString(w, "</style>")
8886
return err
8987
})

0 commit comments

Comments
 (0)