Hi Sami,
SVG/PNG export is implemented as a Rappid plugin. I cannot post the code for these plugins but I can give you a hint on how it's done.
Export to SVG: This might sound simple as JointJS uses SVG to render graphics. A naive implementation would just take the paper.svg (which points to the SVG document) and serialize it to SVG string:
var svgDoc = paper.svg;
var serializer = new XMLSerializer();
var svgString = serializer.serializeToString(svgDoc);
This has one important issue though. Elements in the SVG document can be styled in CSS (and many of them actually are). The way we deal with this in our plugin is as follows:
1. Disable all the stylesheets in the page and therefore collect only default style values.
This, together with the step 2, makes it possible to discard browser default CSS property values
and store only those that differ.
2. Enable back all the stylesheets in the page and collect styles that differ from the default values.
3. Apply the difference between default values and the ones set by custom stylesheets
onto the `style` attribute of each of the nodes in SVG.
This way, we create a clone of the paper SVG document that contains all the styles from external stylesheets inside the style attribute of all the relevant nodes.