themes-terminal/heading_override.go
Alex Dunmow 0a9b177f7c initial: theme plugin terminal
Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously
an unversioned directory inside ~/src/blockninja-themes/terminal.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 14:11:44 +08:00

45 lines
1.1 KiB
Go

package main
import (
"bytes"
"context"
"strconv"
"strings"
)
// TerminalHeadingBlock renders a heading with markdown-style hash prefix and
// uppercase tracking, per the terminal aesthetic.
//
// Content shape (same as built-in heading): {text, level, textClass}.
func TerminalHeadingBlock(ctx context.Context, content map[string]any) string {
text := strings.ToUpper(getString(content, "text"))
textClass := getString(content, "textClass")
level := parseHeadingLevel(content)
var buf bytes.Buffer
_ = terminalHeadingComponent(level, text, textClass).Render(ctx, &buf)
return buf.String()
}
// parseHeadingLevel parses the level from content, defaulting to 2. Tolerates
// JSON float64, native int, and string-encoded levels.
func parseHeadingLevel(content map[string]any) int {
if level, ok := content["level"].(float64); ok {
l := int(level)
if l >= 1 && l <= 6 {
return l
}
}
if level, ok := content["level"].(int); ok {
if level >= 1 && level <= 6 {
return level
}
}
if level, ok := content["level"].(string); ok {
if l, err := strconv.Atoi(level); err == nil && l >= 1 && l <= 6 {
return l
}
}
return 2
}