createNode method

  1. @override
Element createNode(
  1. InlineParser parser,
  2. String destination,
  3. String? title, {
  4. required List<Node> getChildren(),
})
override

Create the node represented by a Markdown link.

Implementation

@override
Element createNode(
  InlineParser parser,
  String destination,
  String? title, {
  required List<Node> Function() getChildren,
}) {
  final element = Element.empty('img');
  final children = getChildren();
  element.attributes['src'] = normalizeLinkDestination(
    escapePunctuation(destination),
  );
  final alt = children
      .map((node) {
        // See https://spec.commonmark.org/0.30/#image-description.
        // An image description may contain links. Fetch text from the alt
        // attribute if this nested link is an image.
        if (node case Element(tag: 'img', attributes: {'alt': final alt})) {
          return alt;
        }
        return node.textContent;
      })
      .nonNulls
      .join();
  element.attributes['alt'] = escapeAttributeCharactersValue(alt);
  if (title != null && title.isNotEmpty) {
    element.attributes['title'] = normalizeLinkTitle(title);
  }
  return element;
}