import 'package:collection/collection.dart'; /// Shorthand function to generate a new [Node]. Node h(String tagName, [Map attributes = const {}, Iterable children = const []]) => Node(tagName, attributes, children); /// Represents an HTML node. class Node { final String tagName; final Map attributes = {}; final List children = []; Node(this.tagName, [Map attributes = const {}, Iterable children = const []]) { this..attributes.addAll(attributes)..children.addAll(children); } Node._selfClosing(this.tagName, [Map attributes = const {}]) { this..attributes.addAll(attributes); } @override bool operator ==(other) { return other is Node && other.tagName == tagName && const ListEquality().equals(other.children, children) && const MapEquality() .equals(other.attributes, attributes); } } /// Represents a self-closing tag, i.e. `
`. class SelfClosingNode extends Node { final String tagName; final Map attributes = {}; @override List get children => List.unmodifiable([]); SelfClosingNode(this.tagName, [Map attributes = const {}]) : super._selfClosing(tagName, attributes); } /// Represents a text node. class TextNode extends Node { final String text; TextNode(this.text) : super(':text'); @override bool operator ==(other) => other is TextNode && other.text == text; }