diff --git a/graphviz-java/src/main/java/guru/nidi/graphviz/parse/Parser.java b/graphviz-java/src/main/java/guru/nidi/graphviz/parse/Parser.java index aa25f1ce..f2bec109 100644 --- a/graphviz-java/src/main/java/guru/nidi/graphviz/parse/Parser.java +++ b/graphviz-java/src/main/java/guru/nidi/graphviz/parse/Parser.java @@ -131,7 +131,13 @@ private MutableGraph subgraph(boolean directed) { if (token.type == SUBGRAPH) { nextToken(); if (token.type == ID) { - sub.setName(label(token).toString()); + final String name = label(token).toString(); + if (name.startsWith("cluster_")) { + sub.setName(name.substring(8)); + sub.setCluster(true); + } else { + sub.setName(name); + } nextToken(); } } diff --git a/graphviz-java/src/test/java/guru/nidi/graphviz/parse/ParserTest.java b/graphviz-java/src/test/java/guru/nidi/graphviz/parse/ParserTest.java index 65e08eba..c5efbe7f 100644 --- a/graphviz-java/src/test/java/guru/nidi/graphviz/parse/ParserTest.java +++ b/graphviz-java/src/test/java/guru/nidi/graphviz/parse/ParserTest.java @@ -135,4 +135,10 @@ void multiLinkAttr() throws IOException { assertEquals(mutGraph().add(a, b), Parser.read("graph { edge[color=red, width=1] a -- b edge[color=blue, a=b] a -- b }")); } + + @Test + void cluster() throws IOException { + assertEquals(mutGraph().add(mutGraph("sub").setCluster(true)), + Parser.read("graph { subgraph cluster_sub {} }")); + } }