MCPcopy Create free account
hub / github.com/ResearAI/AutoFigure / validate_svg_syntax

Function validate_svg_syntax

autofigure/generator.py:926–951  ·  view source on GitHub ↗
(svg_code: str)

Source from the content-addressed store, hash-verified

924
925
926def validate_svg_syntax(svg_code: str) -> Tuple[bool, str]:
927 try:
928 import xml.etree.ElementTree as ET
929
930 if not svg_code.strip().startswith('<svg'):
931 return False, "SVG code must start with <svg"
932
933 if not svg_code.strip().endswith('</svg>'):
934 return False, "SVG code must end with </svg>"
935
936 try:
937 ET.fromstring(svg_code)
938 except ET.ParseError as e:
939 return False, f"XML parsing error: {e}"
940
941 lines = svg_code.split('\n')
942 for i, line in enumerate(lines, 1):
943 import re
944 unquoted_attrs = re.findall(r'(\w+)=([^"\s>]+)', line)
945 if unquoted_attrs:
946 return False, f"Line {i} has unquoted attribute values: {unquoted_attrs[0]}"
947
948 return True, "SVG syntax is correct"
949
950 except Exception as e:
951 return False, f"Validation process error: {e}"
952
953
954def validate_mxgraphxml_syntax(mxgraph_code: str) -> Tuple[bool, str]:

Callers 1

validate_code_syntaxFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected