prepare method
Converts parsed HTML to a StyledElement.
Implementation
@override
StyledElement prepare(
ExtensionContext context, List<StyledElement> children) {
if (context.elementName == "table") {
final cellDescendants = _getCellDescendants(children);
return TableElement(
name: context.elementName,
elementId: context.id,
elementClasses: context.classes.toList(),
tableStructure: children,
cellDescendants: cellDescendants,
style: Style(display: Display.table),
node: context.node,
);
}
if (context.elementName == "th" || context.elementName == "td") {
return TableCellElement(
style: context.elementName == "th"
? Style(
fontWeight: FontWeight.bold,
textAlign: TextAlign.center,
verticalAlign: VerticalAlign.middle,
display: Display.tableCell,
)
: Style(
verticalAlign: VerticalAlign.middle,
display: Display.tableCell,
),
children: children,
node: context.node,
name: context.elementName,
elementClasses: context.classes.toList(),
elementId: context.id,
);
}
if (context.elementName == "tbody" ||
context.elementName == "thead" ||
context.elementName == "tfoot") {
return TableSectionLayoutElement(
name: context.elementName,
elementId: context.id,
elementClasses: context.classes.toList(),
children: children,
style: Style(
display: context.elementName == "thead"
? Display.tableHeaderGroup
: context.elementName == "tfoot"
? Display.tableFooterGroup
: Display.tableRowGroup,
),
node: context.node,
);
}
if (context.elementName == "tr") {
return TableRowLayoutElement(
name: context.elementName,
elementId: context.id,
elementClasses: context.classes.toList(),
children: children,
style: Style(
display: Display.tableRow,
),
node: context.node,
);
}
if (context.elementName == "col" || context.elementName == "colgroup") {
return TableStyleElement(
name: context.elementName,
elementId: context.id,
elementClasses: context.classes.toList(),
children: children,
style: Style(
display: context.elementName == "col"
? Display.tableColumn
: Display.tableColumnGroup,
),
node: context.node,
);
}
throw UnimplementedError("This isn't possible");
}