convertSingleAttributeTextInsertToDomNode method

Element convertSingleAttributeTextInsertToDomNode(
  1. String text,
  2. Attributes attributes
)

Implementation

dom.Element convertSingleAttributeTextInsertToDomNode(
  String text,
  Attributes attributes,
) {
  assert(attributes.length == 1);

  final domText = dom.Text(text);

  // href is a special case, it should be an anchor tag
  final href = attributes.href;
  if (href != null) {
    return dom.Element.tag(HTMLTags.anchor)
      ..attributes['href'] = href
      ..append(domText);
  }
  //backgroud color and attribute color is added than that was ignoring now all attributes handled according to attributes
  if (attributes.backgroundColor != null || attributes.color != null) {
    return convertMultipleAttributeTextInsertToDomNode(text, attributes);
  }

  final keyToTag = {
    AppFlowyRichTextKeys.bold: HTMLTags.strong,
    AppFlowyRichTextKeys.italic: HTMLTags.italic,
    AppFlowyRichTextKeys.underline: HTMLTags.underline,
    AppFlowyRichTextKeys.strikethrough: HTMLTags.del,
    AppFlowyRichTextKeys.code: HTMLTags.code,
    null: HTMLTags.paragraph,
  };

  final tag = keyToTag[attributes.keys.first];
  return dom.Element.tag(tag)..append(domText);
}