Save SVG tag from a HTML page to a SVG image
<p>I have an application by which users can draw things using SVG (d3). I want a functionality that when I click a button or a link, I want to save a SVG tag called "main_svg" that in turn contains all the other SVG elements, to a SVG image in a separate file. I don't want to save the complete page but just the SVG tag with id "main_svg" </p>

<p>How can this be achieved? Are there any plugins that can do this? Any leads would be appreciated. </p>

<p>I tried: </p>

<ol>
<li><p>Saving the element into a text file and then renaming it to .svg, not very efficient. </p></li>
<li><p><a href="https://github.com/gabelerner/canvg" rel="noreferrer">Canvg</a> - But that coverts to png</p></li>
</ol>