Help us shape the future of Go! Take the 2026 Go Developer Survey

theme

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package theme loads Marp theme CSS and packs it for a deck, as Marpit's Theme, ThemeSet and theme pack pipeline do (theme.js, theme_set.js and the postcss plugins they run).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Scope

func Scope(src, attr string) string

Scope confines a <style scoped> element's CSS to one slide, selected by attr (a data attribute the slide carries), as Marpit's style/assign.js does: a selector starting with section narrows the slide itself, any other becomes a descendant of it, and keyframes are renamed so they cannot collide with another slide's.

Types

type PackOptions

type PackOptions struct {
	// Before is CSS put ahead of the theme (Marpit's pack option of that
	// name): what the renderer needs whatever the theme, such as the rule
	// for emoji images.
	Before []string
	// After is CSS appended to the theme: the deck's style directive and
	// global <style> elements, then its scoped styles (see Scope).
	After []string
	// Container is the selector of the element holding the slides;
	// "" means "div.marpit".
	Container string
	// Slide lists the elements from the container down to the section;
	// nil means just "section".
	Slide []string
	// InlineSVG adds the advanced background rules.
	InlineSVG bool
	// Printable adds @page and the print rules.
	Printable bool
	// ContainerQuery makes the slide a size container (Marp Core).
	ContainerQuery bool
	// Size names a @size preset of the theme (the size directive).
	Size string
	// GeneratedContent lowers section::after to an element selector, for
	// layout engines that do not generate content (see Packed.After).
	GeneratedContent bool
}

PackOptions configures Pack.

type Packed

type Packed struct {
	CSS string
	// Width and Height are the slide size in CSS pixels.
	Width, Height float64
	// After is the content expression of the theme's section::after rule
	// when GeneratedContent lowered it, for the renderer to evaluate.
	After string
}

Packed is a packed style sheet.

type Set

type Set struct {

	// Default is the theme used when a deck names none or an unknown one;
	// nil falls back to Marpit's scaffold.
	Default *Theme
	// contains filtered or unexported fields
}

Set is a set of themes by name.

func NewSet

func NewSet() *Set

NewSet returns a set holding Marp Core's built-in themes (default, gaia and uncover), with default as the default.

func (*Set) Add

func (s *Set) Add(src string) (*Theme, error)

Add parses a theme and adds it, replacing a theme of the same name.

func (*Set) Get

func (s *Set) Get(name string) *Theme

Get returns a theme by name.

func (*Set) Has

func (s *Set) Has(name string) bool

Has reports whether a theme is known.

func (*Set) Meta

func (s *Set) Meta(t *Theme, key string) []string

Meta returns a theme's metadata through its imports: the first theme in the chain that defines the key, or, when every definition is a list, all of them with the importing theme's last.

func (*Set) Names

func (s *Set) Names() []string

Names lists the theme names, sorted.

func (*Set) Pack

func (s *Set) Pack(t *Theme, opts PackOptions) Packed

Pack builds the style sheet of a deck using theme t (Marpit's ThemeSet.pack, with Marp Core's size directive).

func (*Set) Resolve

func (s *Set) Resolve(name string) *Theme

Resolve returns the theme a deck naming name uses.

func (*Set) Size

func (s *Set) Size(t *Theme) (w, h string)

Size returns a theme's slide size, through its imports, falling back to the default theme and to Marpit's 1280x720.

func (*Set) SizePreset

func (s *Set) SizePreset(t *Theme, name string) (w, h string, ok bool)

SizePreset returns the size a @size preset of the theme names, as Marp Core's size directive reads it ("16:9 1280px 720px"; "name false" removes an imported preset).

type Theme

type Theme struct {
	Name string
	// CSS is the theme as loaded: nesting resolved and :root replaced.
	CSS string
	// Meta holds the @key value comments, every occurrence in order.
	Meta map[string][]string
	// Imports name the themes this one imports, @import-theme first.
	Imports []string
	// Width and Height are the section size the theme sets, as written.
	Width, Height string
}

Theme is a theme style sheet and what its comments declare.

func Parse

func Parse(src string) (*Theme, error)

Parse loads a theme. It fails when the CSS declares no @theme name.

func (*Theme) MetaValue

func (t *Theme) MetaValue(key string) string

MetaValue returns the last value of a metadata key.

Jump to

Keyboard shortcuts

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