|
@@ -15,12 +15,13 @@ class HTMLConverter {
|
|
final result = <Node>[];
|
|
final result = <Node>[];
|
|
final delta = Delta();
|
|
final delta = Delta();
|
|
|
|
|
|
- for (final child in _document.body?.nodes.toList() ?? <html.Node>[]) {
|
|
|
|
|
|
+ final childNodes = _document.body?.nodes.toList() ?? <html.Node>[];
|
|
|
|
+ for (final child in childNodes) {
|
|
if (child is html.Element) {
|
|
if (child is html.Element) {
|
|
- if (child.localName == "span") {
|
|
|
|
- delta.insert(child.text);
|
|
|
|
- } else if (child.localName == "strong") {
|
|
|
|
- delta.insert(child.text, {"bold": true});
|
|
|
|
|
|
+ if (child.localName == "a" ||
|
|
|
|
+ child.localName == "span" ||
|
|
|
|
+ child.localName == "strong") {
|
|
|
|
+ _handleRichTextElement(delta, child);
|
|
} else {
|
|
} else {
|
|
_handleElement(result, child);
|
|
_handleElement(result, child);
|
|
}
|
|
}
|
|
@@ -59,6 +60,25 @@ class HTMLConverter {
|
|
}
|
|
}
|
|
|
|
|
|
_handleParagraph(List<Node> nodes, html.Element element) {
|
|
_handleParagraph(List<Node> nodes, html.Element element) {
|
|
|
|
+ _handleRichText(nodes, element);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _handleRichTextElement(Delta delta, html.Element element) {
|
|
|
|
+ if (element.localName == "span") {
|
|
|
|
+ delta.insert(element.text);
|
|
|
|
+ } else if (element.localName == "a") {
|
|
|
|
+ final hyperLink = element.attributes["href"];
|
|
|
|
+ Map<String, dynamic>? attributes;
|
|
|
|
+ if (hyperLink != null) {
|
|
|
|
+ attributes = {"href": hyperLink};
|
|
|
|
+ }
|
|
|
|
+ delta.insert(element.text, attributes);
|
|
|
|
+ } else if (element.localName == "strong") {
|
|
|
|
+ delta.insert(element.text, {"bold": true});
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _handleRichText(List<Node> nodes, html.Element element) {
|
|
final image = element.querySelector("img");
|
|
final image = element.querySelector("img");
|
|
if (image != null) {
|
|
if (image != null) {
|
|
_handleImage(nodes, image);
|
|
_handleImage(nodes, image);
|
|
@@ -69,13 +89,10 @@ class HTMLConverter {
|
|
|
|
|
|
for (final child in element.nodes.toList()) {
|
|
for (final child in element.nodes.toList()) {
|
|
if (child is html.Element) {
|
|
if (child is html.Element) {
|
|
- if (child.localName == "a") {
|
|
|
|
- final hyperLink = child.attributes["href"];
|
|
|
|
- Map<String, dynamic>? attributes;
|
|
|
|
- if (hyperLink != null) {
|
|
|
|
- attributes = {"href": hyperLink};
|
|
|
|
- }
|
|
|
|
- delta.insert(child.text, attributes);
|
|
|
|
|
|
+ if (child.localName == "a" ||
|
|
|
|
+ child.localName == "span" ||
|
|
|
|
+ child.localName == "strong") {
|
|
|
|
+ _handleRichTextElement(delta, element);
|
|
} else {
|
|
} else {
|
|
delta.insert(child.text);
|
|
delta.insert(child.text);
|
|
}
|
|
}
|
|
@@ -122,11 +139,11 @@ class HTMLConverter {
|
|
}
|
|
}
|
|
|
|
|
|
_handleListElement(List<Node> nodes, html.Element element) {
|
|
_handleListElement(List<Node> nodes, html.Element element) {
|
|
- final delta = Delta();
|
|
|
|
- delta.insert(element.text);
|
|
|
|
- if (delta.operations.isNotEmpty) {
|
|
|
|
- nodes.add(TextNode(
|
|
|
|
- type: "text", attributes: {"subtype": "bullet-list"}, delta: delta));
|
|
|
|
|
|
+ final childNodes = element.nodes.toList();
|
|
|
|
+ for (final child in childNodes) {
|
|
|
|
+ if (child is html.Element) {
|
|
|
|
+ _handleRichText(nodes, child);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|