render method

String? render(
  1. String line, {
  2. int width = 80,
})

The styled line, or null for lines that are not shown (code fences).

Implementation

String? render(String line, {int width = 80}) {
  final trimmed = line.trimLeft();
  if (trimmed.startsWith('```') || trimmed.startsWith('~~~')) {
    _inCodeBlock = !_inCodeBlock;
    return null;
  }
  if (_inCodeBlock) {
    return Style.code(line);
  }
  if (_heading.firstMatch(line) case final match?) {
    return Style.bold(renderInlineMarkdown(match[2]!));
  }
  if (_rule.hasMatch(line)) {
    return Style.dim('─' * (width < 40 ? width : 40));
  }
  if (_quote.firstMatch(line) case final match?) {
    return '${Style.dim('▎')} ${Style.italic(renderInlineMarkdown(match[1]!))}';
  }
  return renderInlineMarkdown(line);
}