43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"strconv"
|
|
)
|
|
|
|
// GothamHeadingBlock renders a heading with Gotham styling.
|
|
// Uses the same schema as the base heading block.
|
|
// Content expects: {"text": "Heading text", "level": 1-6, "textClass": "optional-class-for-h1"}
|
|
// Note: "class" is reserved for wrapper styling, use "textClass" for the heading element itself
|
|
func GothamHeadingBlock(ctx context.Context, content map[string]any) string {
|
|
text := getString(content, "text")
|
|
textClass := getString(content, "textClass")
|
|
level := parseHeadingLevel(content)
|
|
|
|
var buf bytes.Buffer
|
|
_ = gothamHeadingComponent(level, text, textClass).Render(ctx, &buf)
|
|
return buf.String()
|
|
}
|
|
|
|
// parseHeadingLevel parses the level from content, defaulting to 2.
|
|
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
|
|
}
|