diff --git a/cmd/present/static/styles.css b/cmd/present/static/styles.css
index f8673899e1..688127f6ee 100644
--- a/cmd/present/static/styles.css
+++ b/cmd/present/static/styles.css
@@ -379,7 +379,8 @@ code {
color: black;
}
-article > .image {
+article > .image,
+article > .video {
text-align: center;
margin-top: 40px;
}
diff --git a/cmd/present/templates/action.tmpl b/cmd/present/templates/action.tmpl
index 609dc11e8b..1eae3b7c8d 100644
--- a/cmd/present/templates/action.tmpl
+++ b/cmd/present/templates/action.tmpl
@@ -37,6 +37,14 @@ It determines how the formatting actions are rendered.
{{end}}
+{{define "video"}}
+
diff --git a/present/doc.go b/present/doc.go
index fa39648a16..351c5812c5 100644
--- a/present/doc.go
+++ b/present/doc.go
@@ -178,6 +178,22 @@ preserves the aspect ratio of the image when scaling.
.image images/janet.jpg _ 300
+video:
+
+The template uses the function "video" to inject video files.
+
+The syntax is simple: 2 or 4 space-separated arguments.
+The first argument is always the file name.
+The second argument is always the file content-type.
+If there are more arguments, they are the height and width;
+both must be present, or substituted with an underscore.
+Replacing a dimension argument with the underscore parameter
+preserves the aspect ratio of the video when scaling.
+
+ .video videos/evangeline.mp4 video/mp4 400 600
+
+ .video videos/mabel.ogg video/ogg 500 _
+
background:
The template uses the function "background" to set the background image for
diff --git a/present/video.go b/present/video.go
new file mode 100644
index 0000000000..913822e66b
--- /dev/null
+++ b/present/video.go
@@ -0,0 +1,51 @@
+// 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 (
+ "fmt"
+ "strings"
+)
+
+func init() {
+ Register("video", parseVideo)
+}
+
+type Video struct {
+ URL string
+ SourceType string
+ Width int
+ Height int
+}
+
+func (v Video) TemplateName() string { return "video" }
+
+func parseVideo(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
+ args := strings.Fields(text)
+ vid := Video{URL: args[1], SourceType: args[2]}
+ a, err := parseArgs(fileName, lineno, args[3:])
+ if err != nil {
+ return nil, err
+ }
+ switch len(a) {
+ case 0:
+ // no size parameters
+ case 2:
+ // If a parameter is empty (underscore) or invalid
+ // leave the field set to zero. The "video" action
+ // template will then omit that vid tag attribute and
+ // the browser will calculate the value to preserve
+ // the aspect ratio.
+ if v, ok := a[0].(int); ok {
+ vid.Height = v
+ }
+ if v, ok := a[1].(int); ok {
+ vid.Width = v
+ }
+ default:
+ return nil, fmt.Errorf("incorrect video invocation: %q", text)
+ }
+ return vid, nil
+}