Signed-off-by: oppiliappan me@oppi.li
-43
appview/pages/pages.go
-43
appview/pages/pages.go
···
1
package pages
2
3
import (
4
-
"bytes"
5
"crypto/sha256"
6
"embed"
7
"encoding/hex"
···
29
"tangled.org/core/patchutil"
30
"tangled.org/core/types"
31
32
-
"github.com/alecthomas/chroma/v2"
33
-
chromahtml "github.com/alecthomas/chroma/v2/formatters/html"
34
-
"github.com/alecthomas/chroma/v2/lexers"
35
-
"github.com/alecthomas/chroma/v2/styles"
36
"github.com/bluesky-social/indigo/atproto/identity"
37
"github.com/bluesky-social/indigo/atproto/syntax"
38
"github.com/go-git/go-git/v5/plumbing"
···
1387
}
1388
1389
func (p *Pages) SingleString(w io.Writer, params SingleStringParams) error {
1390
-
var style *chroma.Style = styles.Get("catpuccin-latte")
1391
-
1392
-
if params.ShowRendered {
1393
-
switch markup.GetFormat(params.String.Filename) {
1394
-
case markup.FormatMarkdown:
1395
-
p.rctx.RendererType = markup.RendererTypeRepoMarkdown
1396
-
htmlString := p.rctx.RenderMarkdown(params.String.Contents)
1397
-
sanitized := p.rctx.SanitizeDefault(htmlString)
1398
-
params.RenderedContents = template.HTML(sanitized)
1399
-
}
1400
-
}
1401
-
1402
-
c := params.String.Contents
1403
-
formatter := chromahtml.New(
1404
-
chromahtml.InlineCode(false),
1405
-
chromahtml.WithLineNumbers(true),
1406
-
chromahtml.WithLinkableLineNumbers(true, "L"),
1407
-
chromahtml.Standalone(false),
1408
-
chromahtml.WithClasses(true),
1409
-
)
1410
-
1411
-
lexer := lexers.Get(filepath.Base(params.String.Filename))
1412
-
if lexer == nil {
1413
-
lexer = lexers.Fallback
1414
-
}
1415
-
1416
-
iterator, err := lexer.Tokenise(nil, c)
1417
-
if err != nil {
1418
-
return fmt.Errorf("chroma tokenize: %w", err)
1419
-
}
1420
-
1421
-
var code bytes.Buffer
1422
-
err = formatter.Format(&code, style, iterator)
1423
-
if err != nil {
1424
-
return fmt.Errorf("chroma format: %w", err)
1425
-
}
1426
-
1427
-
params.String.Contents = code.String()
1428
return p.execute("strings/string", w, params)
1429
}
1430
···
1
package pages
2
3
import (
4
"crypto/sha256"
5
"embed"
6
"encoding/hex"
···
28
"tangled.org/core/patchutil"
29
"tangled.org/core/types"
30
31
"github.com/bluesky-social/indigo/atproto/identity"
32
"github.com/bluesky-social/indigo/atproto/syntax"
33
"github.com/go-git/go-git/v5/plumbing"
···
1382
}
1383
1384
func (p *Pages) SingleString(w io.Writer, params SingleStringParams) error {
1385
return p.execute("strings/string", w, params)
1386
}
1387
+2
-2
appview/pages/templates/strings/string.html
+2
-2
appview/pages/templates/strings/string.html
···
75
</div>
76
<div class="overflow-x-auto overflow-y-hidden relative">
77
{{ if .ShowRendered }}
78
-
<div id="blob-contents" class="prose dark:prose-invert">{{ .RenderedContents }}</div>
79
{{ else }}
80
-
<div id="blob-contents" class="whitespace-pre peer-target:bg-yellow-200 dark:peer-target:bg-yellow-900">{{ .String.Contents | escapeHtml }}</div>
81
{{ end }}
82
</div>
83
{{ template "fragments/multiline-select" }}
···
75
</div>
76
<div class="overflow-x-auto overflow-y-hidden relative">
77
{{ if .ShowRendered }}
78
+
<div id="blob-contents" class="prose dark:prose-invert">{{ .String.Contents | readme }}</div>
79
{{ else }}
80
+
<div id="blob-contents" class="whitespace-pre peer-target:bg-yellow-200 dark:peer-target:bg-yellow-900">{{ code .String.Contents .String.Filename | escapeHtml }}</div>
81
{{ end }}
82
</div>
83
{{ template "fragments/multiline-select" }}