@@ -29,9 +29,10 @@ abstract class ReplacedElement extends StyledElement {
2929 required String name,
3030 required Style style,
3131 required String elementId,
32+ List <StyledElement >? children,
3233 dom.Element ? node,
3334 this .alignment = PlaceholderAlignment .aboveBaseline,
34- }) : super (name: name, children: [], style: style, node: node, elementId: elementId);
35+ }) : super (name: name, children: children ?? [], style: style, node: node, elementId: elementId);
3536
3637 static List <String ?> parseMediaSources (List <dom.Element > elements) {
3738 return elements
@@ -230,22 +231,24 @@ class EmptyContentElement extends ReplacedElement {
230231class RubyElement extends ReplacedElement {
231232 dom.Element element;
232233
233- RubyElement ({required this .element, String name = "ruby" })
234- : super (name: name, alignment: PlaceholderAlignment .middle, style: Style (), elementId: element.id);
234+ RubyElement ({
235+ required this .element,
236+ required List <StyledElement > children,
237+ String name = "ruby"
238+ }) : super (name: name, alignment: PlaceholderAlignment .middle, style: Style (), elementId: element.id, children: children);
235239
236240 @override
237241 Widget toWidget (RenderContext context) {
238- dom. Node ? textNode;
242+ String ? textNode;
239243 List <Widget > widgets = < Widget > [];
240- //TODO calculate based off of parent font size.
241244 final rubySize = max (9.0 , context.style.fontSize! .size! / 2 );
242245 final rubyYPos = rubySize + rubySize / 2 ;
243- element.nodes .forEach ((c) {
244- if (c.nodeType == dom. Node . TEXT_NODE ) {
245- textNode = c;
246+ context.tree.children .forEach ((c) {
247+ if (c is TextContentElement ) {
248+ textNode = c.text ;
246249 }
247- if (c is dom. Element ) {
248- if (c.localName == "rt" && textNode != null ) {
250+ if (! ( c is TextContentElement ) ) {
251+ if (c.name == "rt" && textNode != null ) {
249252 final widget = Stack (
250253 alignment: Alignment .center,
251254 children: < Widget > [
@@ -255,12 +258,23 @@ class RubyElement extends ReplacedElement {
255258 child: Transform (
256259 transform:
257260 Matrix4 .translationValues (0 , - (rubyYPos), 0 ),
258- child: Text (c.innerHtml,
259- style: context.style
260- .generateTextStyle ()
261- .copyWith (fontSize: rubySize))))),
262- Container (
263- child: Text (textNode! .text! .trim (),
261+ child: ContainerSpan (
262+ newContext: RenderContext (
263+ buildContext: context.buildContext,
264+ parser: context.parser,
265+ style: c.style,
266+ tree: c,
267+ ),
268+ style: c.style,
269+ child: Text (c.element! .innerHtml,
270+ style: c.style
271+ .generateTextStyle ()
272+ .copyWith (fontSize: rubySize)),
273+ )))),
274+ ContainerSpan (
275+ newContext: context,
276+ style: context.style,
277+ child: Text (textNode! .trim (),
264278 style: context.style.generateTextStyle ())),
265279 ],
266280 );
@@ -361,6 +375,7 @@ class MathElement extends ReplacedElement {
361375
362376ReplacedElement parseReplacedElement (
363377 dom.Element element,
378+ List <StyledElement > children,
364379 NavigationDelegate ? navigationDelegateForIframe,
365380) {
366381 switch (element.localName) {
@@ -435,6 +450,7 @@ ReplacedElement parseReplacedElement(
435450 case "ruby" :
436451 return RubyElement (
437452 element: element,
453+ children: children,
438454 );
439455 case "math" :
440456 return MathElement (
0 commit comments