SvgElement.svg constructor

SvgElement.svg(String svg, { NodeValidator validator, NodeTreeSanitizer treeSanitizer })

Implementation

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);
  var 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;
}