marp

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2026 License: MIT Imports: 5 Imported by: 5

Documentation

Overview

Package marp provides shared Marp slide rendering utilities for structured document projects.

Index

Constants

View Source
const SectionHeaderClass = "<!-- _class: section-header -->"

SectionHeaderClass is the CSS class for section header slides.

View Source
const SlideSeparator = "\n---\n"

SlideSeparator is the Marp slide separator.

Variables

View Source
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.

View Source
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 Add

func Add(a, b int) int

Add returns a + b.

func Coalesce

func Coalesce(values ...string) string

Coalesce returns the first non-empty string from the arguments.

func Default

func Default(defaultVal, val string) string

Default returns the value if non-empty, otherwise returns the default.

func Div

func Div(a, b int) int

Div returns a / b. Returns 0 if b is 0.

func ExecuteTemplate

func ExecuteTemplate(tmpl *template.Template, data any) (string, error)

ExecuteTemplate is a helper that executes a template and returns the result as a string.

func ExecuteTemplateToBuffer

func ExecuteTemplateToBuffer(buf *bytes.Buffer, tmpl *template.Template, data any) error

ExecuteTemplateToBuffer is a helper that executes a template into an existing buffer.

func GetFuncMap

func GetFuncMap(custom template.FuncMap) template.FuncMap

GetFuncMap returns a combined FuncMap with CommonFuncMap and any custom functions.

func Mul

func Mul(a, b int) int

Mul returns a * b.

func PriorityIcon

func PriorityIcon(priority string) string

PriorityIcon returns an icon for priority levels. Supports: p0/critical, p1/high, p2/medium, p3/low.

func PriorityLabel

func PriorityLabel(priority string) string

PriorityLabel returns a human-readable label for a priority value. Converts P0/P1/P2/P3 to descriptive labels.

func ProgressBar

func ProgressBar(progress float64) string

ProgressBar returns a text-based progress bar of default length 10. Progress should be between 0.0 and 1.0.

func ProgressBarLen

func ProgressBarLen(progress float64, length int) string

ProgressBarLen returns a text-based progress bar of specified length. Progress should be between 0.0 and 1.0.

func ProgressPercent

func ProgressPercent(progress float64) string

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

func ScorePercent(score float64) string

ScorePercent formats a 0.0-1.0 score as a percentage string.

func Seq

func Seq(start, end int) []int

Seq generates a sequence of integers from start to end (inclusive).

func SeverityIcon

func SeverityIcon(severity string) string

SeverityIcon returns an icon for severity levels (used in security contexts). Supports: critical, high, medium, low, informational.

func StatusEmoji

func StatusEmoji(status string) string

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

func StatusIcon(status string) string

StatusIcon returns an emoji icon for common status values. Supports: completed, done, in_progress, active, planned, pending, future, blocked, at_risk.

func StatusLabel

func StatusLabel(status string) string

StatusLabel returns a human-readable label for a status value. Converts snake_case/kebab-case to Title Case.

func Sub

func Sub(a, b int) int

Sub returns a - b.

func Ternary

func Ternary(condition bool, trueVal, falseVal any) any

Ternary returns trueVal if condition is true, otherwise falseVal.

func ThemeNames

func ThemeNames() []string

ThemeNames returns the list of available theme names.

func Truncate

func Truncate(s string, max int) string

Truncate shortens a string to max characters, adding "..." if truncated.

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".

func (*BaseRenderer) Format

func (r *BaseRenderer) Format() string

Format returns "marp".

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 content (e.g., "Document ID | Version").
	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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL