getHeaderBlock method

  1. @override
Future<Widget> getHeaderBlock(
  1. String line, [
  2. TextStyle? style
])
override

Implementation

@override
Future<pw.Widget> getHeaderBlock(String line, [pw.TextStyle? style]) async {
  final RegExpMatch match = Constant.HEADER_PATTERN.firstMatch(line)!;

  final String headerLevel = match.group(1)!;
  final String headerText = match.group(2)!;
  final double defaultFontSize = headerLevel.resolveHeaderLevel();
  final pw.TextStyle textStyle = style ?? defaultTextStyle.copyWith(fontSize: defaultFontSize);
  final List<pw.InlineSpan> spans = await getRichTextInlineStyles(
    headerText.replaceAllMapped(Constant.STARTS_WITH_RICH_TEXT_INLINE_STYLES_PATTERN, (Match match) {
      final String content = match.group(10)!;
      final String? fontFamily = match.group(7);
      if (fontFamily == null) return content;
      return '<span style="font-family: $fontFamily">$content</span>';
    }),
    textStyle,
    true,
    false,
  );
  return pw.Container(
      padding: const pw.EdgeInsets.only(top: 7, bottom: 3.5),
      child: pw.RichText(
        softWrap: true,
        overflow: pw.TextOverflow.span,
        text: pw.TextSpan(
          children: spans,
        ),
      ));
}