import re # check: https://github.com/vasturiano/d3-zoomable/blob/master/example/svg/index.html def remove_links_svg(svg): svg = svg.replace("","") svg = svg.replace("\n\n","\n") regex = r"]*>" svg = re.sub(regex, "", svg, count=0, flags=re.MULTILINE) return svg def resize_svg(svg, max_width=800): regex = r"[\d]+)pt\" height=\"(?P[\d]+)pt\"" match = next(re.finditer(regex, svg, re.MULTILINE)) width = int(match.group("width")) height = int(match.group("height")) if width <= max_width: return svg scale = max_width / width s_width = round(scale * width) s_height = round(scale * height) s_svg = svg.replace(match.group(), f'