From bbb1c45ba5baa5a03cd8088cad09f25fa8c579b8 Mon Sep 17 00:00:00 2001 From: Francesc Campoy Date: Tue, 15 Jul 2014 08:23:16 -0700 Subject: [PATCH] go.tools/present: add support for figure captions LGTM=adg R=adg CC=golang-codereviews https://golang.org/cl/110600043 --- cmd/present/static/styles.css | 5 +++++ cmd/present/templates/action.tmpl | 2 ++ present/caption.go | 22 ++++++++++++++++++++++ present/doc.go | 11 +++++++++++ 4 files changed, 40 insertions(+) create mode 100644 present/caption.go diff --git a/cmd/present/static/styles.css b/cmd/present/static/styles.css index 0ee98ce8..b3d829a2 100644 --- a/cmd/present/static/styles.css +++ b/cmd/present/static/styles.css @@ -453,4 +453,9 @@ div.output .buttons { } iframe { border: none; +} +figcaption { + color: #666; + text-align: center; + font-size: 0.75em; } \ No newline at end of file diff --git a/cmd/present/templates/action.tmpl b/cmd/present/templates/action.tmpl index 1fa0073b..2893058d 100644 --- a/cmd/present/templates/action.tmpl +++ b/cmd/present/templates/action.tmpl @@ -44,3 +44,5 @@ It determines how the formatting actions are rendered. {{define "link"}}{{end}} {{define "html"}}{{.HTML}}{{end}} + +{{define "caption"}}
{{style .Text}}
{{end}} \ No newline at end of file diff --git a/present/caption.go b/present/caption.go new file mode 100644 index 00000000..00e0b5d0 --- /dev/null +++ b/present/caption.go @@ -0,0 +1,22 @@ +// Copyright 2012 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("caption", parseCaption) +} + +type Caption struct { + Text string +} + +func (c Caption) TemplateName() string { return "caption" } + +func parseCaption(_ *Context, _ string, _ int, text string) (Elem, error) { + text = strings.TrimSpace(strings.TrimPrefix(text, ".caption")) + return Caption{text}, nil +} diff --git a/present/doc.go b/present/doc.go index da71e8d3..cc2f0088 100644 --- a/present/doc.go +++ b/present/doc.go @@ -61,6 +61,7 @@ After that come slides/sections, each after a blank line: .iframe http://foo .link http://foo label .html file.html + .caption _Gopher_ by [[http://www.reneefrench.com][Renée French]] Again, more text @@ -176,6 +177,16 @@ preserves the aspect ratio of the image when scaling. .image images/janet.jpg _ 300 + +caption: + +The template uses the function "caption" to inject figure captions. + +The text after ".caption" is embedded in a figcaption element after +processing styling and links as in standard text lines. + + .caption _Gopher_ by [[http://www.reneefrench.com][Renée French]] + iframe: The function "iframe" injects iframes (pages inside pages).