SvgElement.svg构造函数

SvgElement.svg(
  1. String svg,
  2. {NodeValidator? validator,
  3. NodeTreeSanitizer? treeSanitizer}
)

实现

factory SvgElement.svg(String svg,
    {NodeValidator? validator, NodeTreeSanitizer? treeSanitizer}) {
  if (validator == null && treeSanitizer == null) {
    validator = new NodeValidatorBuilder.common()..allowSvg();
  }

  final match = _START_TAG_REGEXP.firstMatch(svg);
  Element parentElement;
  if (match != null && match.group(1)!.toLowerCase() == 'svg') {
    parentElement = document.body!;
  } else {
    parentElement = new SvgSvgElement();
  }
  var fragment = parentElement.createFragment(svg,
      validator: validator, treeSanitizer: treeSanitizer);
  return fragment.nodes.where((e) => e is SvgElement).single as SvgElement;
}