diff --git a/dot/dot.go b/dot/dot.go index 03ca4e1..14dd7f7 100644 --- a/dot/dot.go +++ b/dot/dot.go @@ -71,7 +71,13 @@ func writeAttrs(w *bytes.Buffer, name string, tabs int, attrs map[string]interfa sort.Sort(keys) list := []string{} for _, k := range keys { - list = append(list, fmt.Sprintf("%s=%v", k, attrs[k])) + v := attrs[k] + switch value := v.(type) { + case string: + list = append(list, fmt.Sprintf("%s=%q", k, value)) + default: + list = append(list, fmt.Sprintf("%s=%v", k, value)) + } } fmt.Fprintln(w, strings.Join(list, ", "), "];") } diff --git a/dot/dot_test.go b/dot/dot_test.go index d5c139e..f2f018f 100644 --- a/dot/dot_test.go +++ b/dot/dot_test.go @@ -39,14 +39,14 @@ func TestDirectedDotWriter(t *testing.T) { expected := `digraph { graph [ splines=false ]; - 0 [ label=Happy ]; - 1 [ label=Sleepy, shape=egg ]; + 0 [ label="Happy" ]; + 1 [ label="Sleepy", shape="egg" ]; 1 -> 0; 1 -> 2; 3 -> 1; 4 -> 3; 4 -> 5; - 5 -> 6 [ arrowhead=diamond ]; + 5 -> 6 [ arrowhead="diamond" ]; 6 -> 7; 6 -> 9; 9 -> 8;