prepare method

  1. @override
StyledElement prepare(
  1. ExtensionContext context,
  2. List<StyledElement> children
)

Converts parsed HTML to a StyledElement.

Implementation

@override
StyledElement prepare(
    ExtensionContext context, List<StyledElement> children) {
  if (context.elementName == "svg") {
    final parsedWidth = double.tryParse(context.attributes['width'] ?? "");
    final parsedHeight = double.tryParse(context.attributes['height'] ?? "");

    return SvgTagElement(
      name: context.elementName,
      elementId: context.id,
      node: context.node,
      children: children,
      style: Style(),
      width: parsedWidth != null ? Width(parsedWidth) : null,
      height: parsedHeight != null ? Height(parsedHeight) : null,
    );
  }

  if (context.elementName == "img") {
    final parsedWidth = double.tryParse(context.attributes['width'] ?? "");
    final parsedHeight = double.tryParse(context.attributes['height'] ?? "");

    return ImageElement(
      name: context.elementName,
      elementId: context.id,
      node: context.node,
      children: children,
      style: Style(),
      src: context.attributes['src'] ?? "",
      alt: context.attributes['alt'],
      width: parsedWidth != null ? Width(parsedWidth) : null,
      height: parsedHeight != null ? Height(parsedHeight) : null,
    );
  }

  return super.prepare(context, children);
}