Fix bug where SVG output would sometimes have extra </g> tag

When generating SVG images, if there is no "\</g>\<g data-header" present in svgData by line 501 to replace, the resulting SVG file encounters errors because of the unconditionally added "\</g>" tag:

![image](https://f.cloud.github.com/assets/2461496/1043861/0c045c42-1007-11e3-8b0c-e4e3e559cbb6.png)

This fix adds the "\</g>" tag only if the regex in line 498 finds at least one match (if onHeaderPath is called at least once, which would give line 501 something to replace).