Documentation
¶
Overview ¶
Package deck parses a Marp slide deck: Markdown split into slides, with Marpit's directives, image syntax, fragmented lists, speaker notes and scoped styles, plus this tool's two additions — Go template interpolation (package interp) and slide kinds (see Kind).
The behaviour follows the Marpit and Marp Core sources rather than their documentation where the two differ; the tests pin each case against output produced by marp-cli 4.5.1 (Marp Core 4.4.0).
Index ¶
Constants ¶
const KindDirective = "kind"
KindDirective is this tool's own local directive: it names a kind, a preset of local directives (see Kind).
Variables ¶
var KindMathBlock = gast.NewNodeKind("MathBlock")
KindMathBlock is the node kind of MathBlock.
var KindMathInline = gast.NewNodeKind("MathInline")
KindMathInline is the node kind of MathInline.
Functions ¶
Types ¶
type Background ¶
Background is a background image.
type Deck ¶
type Deck struct {
// Global holds the global directives, last value written winning.
Global Global
// Slides are the slides in order.
Slides []*Slide
// Styles are the deck's global CSS additions in order: the style
// directive first, then every unscoped <style> element.
Styles []string
// Front is the front matter decoded with YAML's core schema, for
// templates and tools; directives come from Global and Slide.Dirs.
Front map[string]any
// Kinds are the kinds the deck could use.
Kinds Kinds
// contains filtered or unexported fields
}
Deck is a parsed slide deck.
func (*Deck) Markdown ¶
Markdown returns the deck as plain Marp Markdown: templates expanded, page numbers written out, and kinds replaced by the directives they stand for, so that marp-cli or any Marp tool renders the same slides.
Kinds are removed from the front matter and from comments, then the result is parsed again the way Marpit would see it; wherever a slide's directives differ from what this deck gives it, a spot-directive comment at the start of the slide restores them.
func (*Deck) Render ¶
func (d *Deck) Render(opts RenderOptions) []Rendered
Render renders every slide.
type Dirs ¶
type Dirs struct {
// contains filtered or unexported fields
}
Dirs is an ordered set of directive values. Marpit writes them out as data-* attributes and CSS custom properties in the order they were set.
type Frame ¶
type Frame int
Frame is how a slide is wrapped.
const ( // FrameSVG wraps each slide in <svg><foreignObject>, Marp Core's // inline SVG mode: the slide scales with the viewport, and split // backgrounds are separate layers. FrameSVG Frame = iota // FramePlain writes bare <section> elements (Marpit without inline // SVG): split and multiple backgrounds collapse to the last image. FramePlain // FrameBox renders the inline SVG layers as absolutely positioned // <div>s, for layout engines without <foreignObject>. FrameBox )
type Global ¶
type Global struct {
Dirs Dirs
// HeadingDivider lists the heading levels that start a new slide.
HeadingDivider []int
}
Global holds the global directives.
type HTMLPolicy ¶
type HTMLPolicy int
HTMLPolicy says what raw HTML in the Markdown may do.
const ( // HTMLAllowlist keeps the elements and attributes Marp Core considers // safe and escapes the rest, as Marp Core does by default. HTMLAllowlist HTMLPolicy = iota // HTMLAll keeps all raw HTML (marp --html). HTMLAll // HTMLNone escapes all raw HTML. HTMLNone )
type Kind ¶
type Kind struct {
Name string
// Extends names a kind whose directives this one starts from.
Extends string
// Dirs are the kind's own directives, already normalized.
Dirs Dirs
}
A Kind is a named preset of local directives: the header, the footer, whether the slide is numbered, its class, its background. A slide states what it is ("kind: title") instead of repeating how it looks.
"kind: name" applies the preset like a local directive, to the slide and the ones after it; "_kind: name" applies it to one slide, like a spot directive. Switching kinds first clears what the previous kind set, so a class or a footer never leaks from one kind into the next. Directives written by hand always win over the kind, and, being the author's own, carry over to the following slides as in Marp, kind switches included.
type Kinds ¶
Kinds is a set of kinds by name.
func BuiltinKinds ¶
func BuiltinKinds() Kinds
BuiltinKinds returns the kinds every deck starts with. A deck, a configuration file or a kinds file can redefine any of them.
func LoadKindsFile ¶
LoadKindsFile reads kinds from a YAML file: either a mapping of kinds, or a mapping with a kinds key (so a configuration file can serve as one).
func ParseKinds ¶
ParseKinds reads kind definitions from a decoded YAML mapping of name to directives.
func ParseKindsYAML ¶
ParseKindsYAML reads kinds from YAML source; name is for errors.
type MathBlock ¶ added in v0.2.0
MathBlock is a display formula; Tex is its source.
type MathInline ¶ added in v0.2.0
type MathInline struct {
gast.BaseInline
Tex string
}
MathInline is an inline formula; Tex is its source.
func (*MathInline) Dump ¶ added in v0.2.0
func (n *MathInline) Dump(source []byte, level int)
Dump implements ast.Node.
func (*MathInline) Kind ¶ added in v0.2.0
func (n *MathInline) Kind() gast.NodeKind
Kind implements ast.Node.
type Options ¶
type Options struct {
// Data is template data; it overrides the front matter's keys and its
// data mapping.
Data map[string]any
// Kinds add to (and override) the built-in kinds; the deck's own
// kinds front-matter key overrides these in turn.
Kinds Kinds
// NoTemplate turns template interpolation off.
NoTemplate bool
// BaseDir resolves relative paths: included files and kinds files.
BaseDir string
// StrictYAML turns off loose YAML parsing of directives (Marp Core
// turns it on; plain Marpit leaves it off).
StrictYAML bool
// Now is the template clock; nil means time.Now.
Now func() time.Time
// Name names the deck in error messages.
Name string
}
Options configures Parse.
type RenderOptions ¶
type RenderOptions struct {
Frame Frame
HTML HTMLPolicy
// Lang is the lang attribute when no lang directive sets one.
Lang string
// Width and Height are the slide size in pixels, from the theme.
Width, Height int
// Highlight, when set, renders a fenced code block's content; ok false
// falls back to plain escaped code.
Highlight func(code, lang string) (htmlOut string, ok bool)
// GeneratedContent, when set, writes elements that stand for the
// ::after pseudo-element Marpit paginates with, for layout engines
// without generated content: <span data-slides-pseudo="after">.
GeneratedContent bool
// Math, when set, typesets a formula ($…$ inline, $$…$$ display) to
// HTML; nil leaves formulas as the text they were written as.
Math func(tex string, display bool) (string, error)
// AfterContent is the theme's section::after content expression (see
// theme.Packed.After); the element writes its value. Empty means the
// page number alone, Marpit's scaffold.
AfterContent string
}
RenderOptions configures Render.
type Slide ¶
type Slide struct {
// Index is the slide's position, from 0.
Index int
// Kind is the kind the slide was given, "" if none.
Kind string
// Dirs are the local and spot directives in effect on the slide.
Dirs Dirs
// Page is the page number as Marpit counts it: slides whose paginate
// directive is skip or hold do not advance it.
Page int
// Total is the last page number of the deck.
Total int
// Paginated reports whether the page number is shown.
Paginated bool
// Notes are the speaker notes: the slide's HTML comments that are not
// directives.
Notes []string
// Fragments counts the fragmented list items.
Fragments int
// Backgrounds are the slide's background images, in order.
Backgrounds []Background
// BackgroundSplit is "left" or "right" when the backgrounds take one
// side of the slide, and BackgroundSplitSize the width they take.
BackgroundSplit, BackgroundSplitSize string
// BackgroundDirection is "horizontal" (the default) or "vertical".
BackgroundDirection string
// ScopedStyles are the slide's <style scoped> contents.
ScopedStyles []string
// Headings are the slide's headings, for outlines.
Headings []Heading
// contains filtered or unexported fields
}
Slide is one slide.