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

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

40 lines
1.0 KiB
Go

package main
import (
"bytes"
"context"
"strconv"
)
// Y2KHeadingBlock applies the chrome-stroke heading styling to the built-in
// heading block when the y2k theme is active.
// Content: {text, level, textClass}
func Y2KHeadingBlock(ctx context.Context, content map[string]any) string {
text := getString(content, "text")
textClass := getString(content, "textClass")
level := parseHeadingLevel(content)
var buf bytes.Buffer
_ = y2kHeadingComponent(level, text, textClass).Render(ctx, &buf)
return buf.String()
}
// parseHeadingLevel reads "level" from the content map, accepting float64
// (JSON), int (Go), or numeric strings. Returns 2 as a safe default.
func parseHeadingLevel(content map[string]any) int {
if v, ok := content["level"].(float64); ok {
l := int(v)
if l >= 1 && l <= 6 {
return l
}
}
if v, ok := content["level"].(int); ok && v >= 1 && v <= 6 {
return v
}
if v, ok := content["level"].(string); ok {
if l, err := strconv.Atoi(v); err == nil && l >= 1 && l <= 6 {
return l
}
}
return 2
}