mirror of
https://github.com/golang/go
synced 2024-11-18 05:44:47 -07:00
657575a564
Commands like .code now have a TemplateCmd method that returns the original command. The Text struct now has a Raw field set when Pre==true. It contains the original indented text, without the tab "fixing". This helps building tooling that reformats or rewrites present files. For golang/go#33955. Change-Id: Ieb036e8b509a4531d120c597b19f2158306a5352 Reviewed-on: https://go-review.googlesource.com/c/tools/+/222845 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
// Copyright 2013 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("iframe", parseIframe)
|
|
}
|
|
|
|
type Iframe struct {
|
|
Cmd string // original command from present source
|
|
URL string
|
|
Width int
|
|
Height int
|
|
}
|
|
|
|
func (i Iframe) PresentCmd() string { return i.Cmd }
|
|
func (i Iframe) TemplateName() string { return "iframe" }
|
|
|
|
func parseIframe(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
|
|
args := strings.Fields(text)
|
|
if len(args) < 2 {
|
|
return nil, fmt.Errorf("incorrect iframe invocation: %q", text)
|
|
}
|
|
i := Iframe{Cmd: text, URL: args[1]}
|
|
a, err := parseArgs(fileName, lineno, args[2:])
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
switch len(a) {
|
|
case 0:
|
|
// no size parameters
|
|
case 2:
|
|
if v, ok := a[0].(int); ok {
|
|
i.Height = v
|
|
}
|
|
if v, ok := a[1].(int); ok {
|
|
i.Width = v
|
|
}
|
|
default:
|
|
return nil, fmt.Errorf("incorrect iframe invocation: %q", text)
|
|
}
|
|
return i, nil
|
|
}
|