It's likely that the dot code would be a lot clearer if expressed with text/template, the current implementation is pretty naive. It's probably possible to directly translate the dot language spec into a template.