     svg.setAttributeNS SVGNS, 'width', viewBox[2]
     svg.setAttributeNS SVGNS, 'height', viewBox[3]
     svg.setAttributeNS SVGNS, 'preserveAspectRatio', 'xMinYMin meet'
-    out = new XMLSerializer().serializeToString doc
+    doc
+  renderSVG: (mappings) ->
+    out = new XMLSerializer().serializeToString @renderSVGDOM mappings
     ## Parsing xlink:href in user's SVG fragments, and then serializing,
     ## can lead to these null namespace definitions.  Remove.
     out = out.replace /\sxmlns:xlink=""/g, ''

    console.log 'Not enough filename arguments'
    help()

unless window?
  main()

    console.log '->', filename
    fs.writeFileSync filename, @renderSVG mappings
    filename
  renderSVGDOM: (mappings) ->
    doc = domImplementation.createDocument SVGNS, 'svg'
    svg = doc.documentElement
    svg.setAttribute 'xmlns:xlink', XLINKNS
