diff --git a/cmd/present/static/styles.css b/cmd/present/static/styles.css index d877682bb9..bd24e4c081 100644 --- a/cmd/present/static/styles.css +++ b/cmd/present/static/styles.css @@ -391,18 +391,9 @@ article > .video { margin-top: 40px; } -article > .background { - position: absolute; - top: 0; - left: 0; - right: 0; - bottom: 0; - z-index: -1; -} - -article > .background > img { - max-height: 100%; - max-width: 100%; +article.background { + background-size: contain; + background-repeat: round; } table { diff --git a/cmd/present/templates/slides.tmpl b/cmd/present/templates/slides.tmpl index 878440b644..37484000c0 100644 --- a/cmd/present/templates/slides.tmpl +++ b/cmd/present/templates/slides.tmpl @@ -55,7 +55,7 @@ {{range $i, $s := .Sections}} -
+
{{if $s.Elem}}

{{$s.Title}}

{{range $s.Elem}}{{elem $.Template .}}{{end}} diff --git a/present/background.go b/present/background.go deleted file mode 100644 index 0a6216ab00..0000000000 --- a/present/background.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2016 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package present - -import ( - "strings" -) - -func init() { - Register("background", parseBackground) -} - -type Background struct { - URL string -} - -func (i Background) TemplateName() string { return "background" } - -func parseBackground(ctx *Context, fileName string, lineno int, text string) (Elem, error) { - args := strings.Fields(text) - background := Background{URL: args[1]} - return background, nil -} diff --git a/present/parse.go b/present/parse.go index b26d65bbb9..d7289dbaf2 100644 --- a/present/parse.go +++ b/present/parse.go @@ -96,12 +96,32 @@ func (p *Author) TextElem() (elems []Elem) { // Section represents a section of a document (such as a presentation slide) // comprising a title and a list of elements. type Section struct { - Number []int - Title string - Elem []Elem - Notes []string + Number []int + Title string + Elem []Elem + Notes []string + Classes []string + Styles []string } +// HTMLAttributes for the section +func (s Section) HTMLAttributes() template.HTMLAttr { + if len(s.Classes) == 0 && len(s.Styles) == 0 { + return "" + } + + var class string + if len(s.Classes) > 0 { + class = fmt.Sprintf(`class=%q`, strings.Join(s.Classes, " ")) + } + var style string + if len(s.Styles) > 0 { + style = fmt.Sprintf(`style=%q`, strings.Join(s.Styles, " ")) + } + return template.HTMLAttr(strings.Join([]string{class, style}, " ")) +} + +// Sections contained within the section. func (s Section) Sections() (sections []Section) { for _, e := range s.Elem { if section, ok := e.(Section); ok { @@ -366,6 +386,11 @@ func parseSections(ctx *Context, name string, lines *Lines, number []int) ([]Sec } case strings.HasPrefix(text, "."): args := strings.Fields(text) + if args[0] == ".background" { + section.Classes = append(section.Classes, "background") + section.Styles = append(section.Styles, "background-image: url('"+args[1]+"')") + break + } parser := parsers[args[0]] if parser == nil { return nil, fmt.Errorf("%s:%d: unknown command %q\n", name, lines.line, text)