Documentation
¶
Overview ¶
Package marp provides shared Marp slide rendering utilities for structured document projects.
Index ¶
- Constants
- Variables
- func Add(a, b int) int
- func Coalesce(values ...string) string
- func Default(defaultVal, val string) string
- func Div(a, b int) int
- func ExecuteTemplate(tmpl *template.Template, data any) (string, error)
- func ExecuteTemplateToBuffer(buf *bytes.Buffer, tmpl *template.Template, data any) error
- func GetFuncMap(custom template.FuncMap) template.FuncMap
- func Mul(a, b int) int
- func PriorityIcon(priority string) string
- func PriorityLabel(priority string) string
- func ProgressBar(progress float64) string
- func ProgressBarLen(progress float64, length int) string
- func ProgressPercent(progress float64) string
- func RenderFrontMatter(data FrontMatterData) (string, error)
- func RenderTitleSlide(data TitleSlideData) (string, error)
- func ScorePercent(score float64) string
- func Seq(start, end int) []int
- func SeverityIcon(severity string) string
- func StatusEmoji(status string) string
- func StatusIcon(status string) string
- func StatusLabel(status string) string
- func Sub(a, b int) int
- func Ternary(condition bool, trueVal, falseVal any) any
- func ThemeNames() []string
- func Truncate(s string, max int) string
- type BaseRenderer
- type FrontMatterData
- type Options
- type Renderer
- type ThemeConfig
- type TitleSlideData
Constants ¶
const SectionHeaderClass = "<!-- _class: section-header -->"
SectionHeaderClass is the CSS class for section header slides.
const SlideSeparator = "\n---\n"
SlideSeparator is the Marp slide separator.
Variables ¶
var CommonFuncMap = template.FuncMap{ "add": Add, "sub": Sub, "mul": Mul, "div": Div, "truncate": Truncate, "progressBar": ProgressBar, "progressBarLen": ProgressBarLen, "progressPercent": ProgressPercent, "scorePercent": ScorePercent, "statusIcon": StatusIcon, "statusEmoji": StatusEmoji, "statusLabel": StatusLabel, "priorityIcon": PriorityIcon, "priorityLabel": PriorityLabel, "severityIcon": SeverityIcon, "join": strings.Join, "upper": strings.ToUpper, "lower": strings.ToLower, "title": strings.Title, "hasPrefix": strings.HasPrefix, "hasSuffix": strings.HasSuffix, "contains": strings.Contains, "replace": strings.ReplaceAll, "trim": strings.TrimSpace, "default": Default, "coalesce": Coalesce, "ternary": Ternary, "seq": Seq, }
CommonFuncMap provides template functions used across all Marp renderers. Import this into your template.FuncMap to ensure consistent behavior.
var DefaultThemes = map[string]ThemeConfig{
"default": {
Name: "default",
PrimaryBgColor: "#5a67d8",
PrimaryTextColor: "#ffffff",
AccentColor: "#7f9cf5",
SuccessColor: "#48bb78",
WarningColor: "#ed8936",
DangerColor: "#f56565",
},
"corporate": {
Name: "default",
PrimaryBgColor: "#1a365d",
PrimaryTextColor: "#ffffff",
AccentColor: "#2b6cb0",
SuccessColor: "#38a169",
WarningColor: "#d69e2e",
DangerColor: "#e53e3e",
},
"minimal": {
Name: "default",
PrimaryBgColor: "#2d3748",
PrimaryTextColor: "#ffffff",
AccentColor: "#4a5568",
SuccessColor: "#48bb78",
WarningColor: "#ecc94b",
DangerColor: "#fc8181",
},
}
DefaultThemes contains the standard theme configurations used across all structured document projects for consistency.
Functions ¶
func ExecuteTemplate ¶
ExecuteTemplate is a helper that executes a template and returns the result as a string.
func ExecuteTemplateToBuffer ¶
ExecuteTemplateToBuffer is a helper that executes a template into an existing buffer.
func GetFuncMap ¶
GetFuncMap returns a combined FuncMap with CommonFuncMap and any custom functions.
func PriorityIcon ¶
PriorityIcon returns an icon for priority levels. Supports: p0/critical, p1/high, p2/medium, p3/low.
func PriorityLabel ¶
PriorityLabel returns a human-readable label for a priority value. Converts P0/P1/P2/P3 to descriptive labels.
func ProgressBar ¶
ProgressBar returns a text-based progress bar of default length 10. Progress should be between 0.0 and 1.0.
func ProgressBarLen ¶
ProgressBarLen returns a text-based progress bar of specified length. Progress should be between 0.0 and 1.0.
func ProgressPercent ¶
ProgressPercent formats a 0.0-1.0 progress value as a percentage string. Alias for ScorePercent for semantic clarity.
func RenderFrontMatter ¶
func RenderFrontMatter(data FrontMatterData) (string, error)
RenderFrontMatter generates the Marp front matter YAML block.
func RenderTitleSlide ¶
func RenderTitleSlide(data TitleSlideData) (string, error)
RenderTitleSlide generates a standard title slide.
func ScorePercent ¶
ScorePercent formats a 0.0-1.0 score as a percentage string.
func SeverityIcon ¶
SeverityIcon returns an icon for severity levels (used in security contexts). Supports: critical, high, medium, low, informational.
func StatusEmoji ¶
StatusEmoji returns a text-based status indicator (not emoji) for use in contexts where emoji may not render well. Used by V2MOM and similar documents.
func StatusIcon ¶
StatusIcon returns an emoji icon for common status values. Supports: completed, done, in_progress, active, planned, pending, future, blocked, at_risk.
func StatusLabel ¶
StatusLabel returns a human-readable label for a status value. Converts snake_case/kebab-case to Title Case.
Types ¶
type BaseRenderer ¶
type BaseRenderer struct{}
BaseRenderer provides common Marp renderer functionality. Embed this in your document-specific renderer.
func (*BaseRenderer) FileExtension ¶
func (r *BaseRenderer) FileExtension() string
FileExtension returns ".md".
type FrontMatterData ¶
type FrontMatterData struct {
// Theme is the ThemeConfig to use for styling.
Theme ThemeConfig
// Title is displayed in the header (optional).
Title string
// Subtitle is displayed below the title (optional).
Subtitle string
Footer string
// Paginate enables slide numbers.
Paginate bool
// CustomCSS is additional CSS to include in the style block.
CustomCSS string
}
FrontMatterData contains the data needed to render Marp front matter.
type Options ¶
type Options struct {
// Theme is the theme name ("default", "corporate", "minimal").
Theme string
// IncludeNotes includes speaker notes in the output.
IncludeNotes bool
// Terminology controls label rendering (for multi-framework documents).
// Example values: "v2mom", "okr", "hybrid".
Terminology string
// CustomFuncs are additional template functions to include.
CustomFuncs template.FuncMap
}
Options configures Marp rendering behavior.
func DefaultOptions ¶
func DefaultOptions() *Options
DefaultOptions returns the default Marp rendering options.
type Renderer ¶
type Renderer interface {
// Format returns the output format name (always "marp" for Marp renderers).
Format() string
// FileExtension returns the output file extension (always ".md" for Marp).
FileExtension() string
}
Renderer is the interface that all Marp renderers should implement.
type ThemeConfig ¶
type ThemeConfig struct {
// Name is the Marp theme name (e.g., "default", "gaia", "uncover").
Name string
// PrimaryBgColor is the background color for title/header slides.
PrimaryBgColor string
// PrimaryTextColor is the text color on primary backgrounds.
PrimaryTextColor string
// AccentColor is used for highlights, links, and decorative elements.
AccentColor string
// SuccessColor indicates positive status (completed, on-track).
SuccessColor string
// WarningColor indicates caution status (at-risk, behind).
WarningColor string
// DangerColor indicates negative status (blocked, critical).
DangerColor string
}
ThemeConfig defines the color scheme and styling for Marp presentations.
func GetTheme ¶
func GetTheme(name string) ThemeConfig
GetTheme returns the ThemeConfig for the given theme name. If the theme is not found, it returns the default theme.
type TitleSlideData ¶
type TitleSlideData struct {
// Title is the main document title.
Title string
// DocumentType describes the document (e.g., "Product Requirements Document").
DocumentType string
// Author is the document author name.
Author string
// AuthorRole is the author's role (optional).
AuthorRole string
// Version is the document version.
Version string
// Status is the document status (e.g., "Draft", "Approved").
Status string
// Date is the document date. If zero, uses current date.
Date time.Time
}
TitleSlideData contains data for rendering a title slide.
func (TitleSlideData) FormattedDate ¶
func (d TitleSlideData) FormattedDate() string
FormattedDate returns the date formatted for display.