-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor the html_node_parser.dart
- Loading branch information
Showing
15 changed files
with
168 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 23 additions & 20 deletions
43
lib/src/plugins/html/encoder/parser/bulleted_list_node_parser.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,46 @@ | ||
import 'package:appflowy_editor/appflowy_editor.dart'; | ||
import 'package:html/dom.dart' as dom; | ||
|
||
class HtmlBulletedListNodeParser extends HtmlNodeParser { | ||
class HtmlBulletedListNodeParser extends HTMLNodeParser { | ||
const HtmlBulletedListNodeParser(); | ||
|
||
@override | ||
String get id => BulletedListBlockKeys.type; | ||
|
||
@override | ||
String transform(Node node, {required List<HtmlNodeParser> encodeParsers}) { | ||
String transformNodeToHTMLString( | ||
Node node, { | ||
required List<HTMLNodeParser> encodeParsers, | ||
}) { | ||
assert(node.type == BulletedListBlockKeys.type); | ||
|
||
return toHTMLString(htmlNodes(node, encodeParsers: encodeParsers)); | ||
return toHTMLString( | ||
transformNodeToDomNodes(node, encodeParsers: encodeParsers), | ||
); | ||
} | ||
|
||
@override | ||
List<dom.Node> htmlNodes( | ||
List<dom.Node> transformNodeToDomNodes( | ||
Node node, { | ||
required List<HtmlNodeParser> encodeParsers, | ||
required List<HTMLNodeParser> encodeParsers, | ||
}) { | ||
final List<dom.Node> result = []; | ||
final delta = node.delta; | ||
if (delta == null) { | ||
throw Exception('Delta is null'); | ||
} | ||
final convertedNodes = DeltaHtmlEncoder().convert(delta); | ||
const tagName = HTMLTags.list; | ||
if (node.children.isNotEmpty) { | ||
convertedNodes.addAll( | ||
childrenNodes(node.children.toList(), encodeParsers: encodeParsers), | ||
); | ||
} | ||
final element = insertText(tagName, childNodes: convertedNodes); | ||
|
||
final stashListContainer = dom.Element.tag( | ||
HTMLTags.unorderedList, | ||
final domNodes = deltaHTMLEncoder.convert(delta); | ||
domNodes.addAll( | ||
childrenNodes( | ||
node.children.toList(), | ||
encodeParsers: encodeParsers, | ||
), | ||
); | ||
stashListContainer.append(element); | ||
result.add(stashListContainer); | ||
return result; | ||
final element = insertText(HTMLTags.list, childNodes: domNodes); | ||
|
||
return [ | ||
dom.Element.tag( | ||
HTMLTags.unorderedList, | ||
)..append(element) | ||
]; | ||
} | ||
} |
17 changes: 11 additions & 6 deletions
17
lib/src/plugins/html/encoder/parser/heading_node_parser.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 10 additions & 5 deletions
15
lib/src/plugins/html/encoder/parser/image_node_parser.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 11 additions & 6 deletions
17
lib/src/plugins/html/encoder/parser/numbered_list_node_parser.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 11 additions & 6 deletions
17
lib/src/plugins/html/encoder/parser/quote_node_parser.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.