Skip to content

Commit b286ed8

Browse files
author
Wen-Zhe Liu
committed
Merge pull request golang#47 in ~WELIU/gotools from scrollgraphviz to dev
* commit '051a366f6d968396962d66a39c3f216fd01f0042': support -scroll and -style in graphviz
2 parents 66b37aa + 051a366 commit b286ed8

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

cmd/present/static/playground/welcome/index.slide

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ Support Formats: `PNG`, `BMP`, `JPG`, `GIF`, `SVG`
217217

218218
# You can use `.graph` command to show graphviz
219219

220-
.graph <url> [<height> <width>]?
220+
.graph <url> [-scroll|-style <css>] [<height> <width>]?
221+
222+
# -scroll is to show the scroll bar
223+
# -style is to set the css style (not contains space)
221224

222225
[[welcome/resources/graph.graph][Raw File]]
223226

present/graphviz.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package present
22

33
import (
44
"errors"
5+
"flag"
56
"fmt"
67
"html/template"
78
"path/filepath"
@@ -32,21 +33,35 @@ func parseGraphivz(ctx *Context, fileName string, lineno int, text string) (elem
3233
return nil, err
3334
}
3435

35-
a, err := parseArgs(fileName, lineno, args[2:])
36+
fs := flag.NewFlagSet("", flag.ExitOnError)
37+
style := fs.String("style", "", "CSS Style")
38+
scrollable := fs.Bool("scroll", false, "Show scroll bar")
39+
err = fs.Parse(args[2:])
40+
if err != nil {
41+
return
42+
}
43+
if *style != "" {
44+
*style = fmt.Sprintf(`style="%s"`, *style)
45+
} else {
46+
styles := make([]string, 0, 4)
47+
if *scrollable {
48+
styles = append(styles, fmt.Sprintf("overflow:scroll"))
49+
}
50+
if len(styles) > 0 {
51+
*style = fmt.Sprintf(`style="%s"`, strings.Join(styles, ";"))
52+
}
53+
}
54+
55+
a, err := parseArgs(fileName, lineno, fs.Args())
3656

3757
result := Graphivz{
3858
Content: string(bytes),
59+
Style: template.HTMLAttr(*style),
3960
}
4061

4162
switch len(a) {
4263
case 0:
4364
// no size parameters
44-
case 3:
45-
// TODO: change the param to -style overflow:scroll
46-
if v, ok := a[2].(int); ok && v == 1 { // scroll code is 1
47-
result.Style = template.HTMLAttr(fmt.Sprintf(`style="%s"`, "overflow:scroll"))
48-
}
49-
fallthrough
5065
case 2:
5166
// If a parameter is empty (underscore) or invalid
5267
// leave the field set to zero. The "image" action

0 commit comments

Comments
 (0)