htmlToMarkdown function
see this issue: https://github.com/dart-lang/markdown/issues/284#event-3216258013
use htmlToMarkdown to convert HTML in m.Text
to m.Node
Implementation
void htmlToMarkdown(h.Node? node, int deep, List<m.Node> mNodes) {
if (node == null) return;
if (node is h.Text) {
mNodes.add(m.Text(node.text));
} else if (node is h.Element) {
final tag = node.localName;
if (tag == img || tag == video) {
final element = m.Element(tag!, null);
element.attributes.addAll(node.attributes.cast());
mNodes.add(element);
} else {
final element = m.Element(tag!, null);
element.attributes.addAll(node.attributes.cast());
final customElement = m.Element(other, [element]);
mNodes.add(customElement);
}
if (node.nodes.isEmpty) return;
node.nodes.forEach((n) {
htmlToMarkdown(n, deep + 1, mNodes);
});
}
}