Skip to content

Commit

Permalink
fix text
Browse files Browse the repository at this point in the history
  • Loading branch information
alextekartik committed Feb 19, 2025
1 parent 3311464 commit 8ab3d3a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/src/html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ abstract class Node {
}

/// Text node
abstract class Text extends Node {}
abstract class Text extends Node {
/// Non-null text content
String get text;
}

abstract class Element extends Node {
ElementList get children;
Expand Down
3 changes: 3 additions & 0 deletions lib/src/html5lib/html_html5lib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,9 @@ abstract class _Text implements Text {
}

class _TextImpl with _NodeImpl implements _Text {
/// Non nullable text
@override
String get text => _node.text!;
_TextImpl(html5lib.Text node) {
_node = node;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/src/web/html_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ abstract class _Text implements Text {
}

class _TextImpl extends _NodeBase with _NodeImpl implements _Text {
/// Non nullable text content
@override
String get text => webNode.textContent!;
_TextImpl(super.webNode);
_TextImpl.text(String value) : super(web.Text(value));
}
1 change: 1 addition & 0 deletions test/node_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void nodeTestGroup(HtmlProvider html) {
expect(firstNode.nodeType, Node.textNode);
expect(firstNode.nodeValue, ' ');
expect(firstNode, isA<Text>());
expect((firstNode as Text).text, ' ');
});
});
}

0 comments on commit 8ab3d3a

Please sign in to comment.