convertAttributesToCssStyle method

String convertAttributesToCssStyle(
  1. Map<String, dynamic> attributes
)

Implementation

String convertAttributesToCssStyle(Map<String, dynamic> attributes) {
  final cssMap = <String, String>{};

  if (attributes.bold) {
    cssMap['font-weight'] = 'bold';
  }
  if (attributes.underline && attributes.strikethrough) {
    cssMap['text-decoration'] = 'underline line-through';
  } else if (attributes.underline) {
    cssMap['text-decoration'] = 'underline';
  } else if (attributes.strikethrough) {
    cssMap['text-decoration'] = 'line-through';
  }

  if (attributes.italic) {
    cssMap['font-style'] = 'italic';
  }

  final backgroundColor = attributes.backgroundColor;
  if (backgroundColor != null) {
    cssMap['background-color'] = backgroundColor.toRgbaString();
  }

  final color = attributes.color;
  if (color != null) {
    cssMap['color'] = color.toRgbaString();
  }

  return cssMap.entries.map((e) => '${e.key}: ${e.value}').join('; ');
}