buildHtml method

String buildHtml()

Implementation

String buildHtml() {
  final useTable = columns.isNotEmpty;
  final buf = StringBuffer();

  if (useTable) {
    buf.writeln('<table>');
    for (final l in lines) {
      final bg = _rowBg(l);
      final fw = l.isHeader ? 'font-weight:bold;' : '';
      final fc = l.isFooter ? 'color:#666;' : '';
      final cells = lineToColumns(l);
      buf.write('<tr style="background:$bg;$fc">');
      for (int ci = 0; ci < columns.length; ci++) {
        final w = columns[ci].$1 != null
            ? ' width="${columns[ci].$1!.toInt()}"'
            : '';
        final txt = ci < cells.length ? cells[ci] : '';
        buf.write('<td$w style="$fw">$txt</td>');
      }
      buf.writeln('</tr>');
    }
    buf.writeln('</table>');
  } else {
    // No column definitions: output `text` directly (it may already be an HTML string)
    for (final l in lines) {
      buf.writeln(l.text);
    }
  }

  return buf.toString();
}