importFromHtml method

Root importFromHtml(
  1. String html
)

Implementation

Root importFromHtml(String html) {
  final document = parse(html);
  final body = document.body;
  if (body == null) return Root(nodes: [Paragraph(text: '')]);
  final nodes = _elementsToNodes(body.children);
  // Filter out empty paragraphs (whitespace-only) that create unwanted spacing
  final filtered = nodes.where((n) => !_isEmptyParagraph(n)).toList();
  return Root(nodes: filtered.isEmpty ? [Paragraph(text: '')] : filtered);
}