getInlineStyles method

  1. @override
Future<List<TextSpan>> getInlineStyles(
  1. String line, [
  2. TextStyle? style
])
override

Implementation

@override
Future<List<pw.TextSpan>> getInlineStyles(String line, [pw.TextStyle? style]) async {
  final List<pw.TextSpan> spans = <pw.TextSpan>[];
  final Iterable<RegExpMatch> matches = Constant.INLINE_STYLES_PATTERN.allMatches(line);
  int currentIndex = 0;
  int i = 0;
  while (i < matches.length) {
    final RegExpMatch match = matches.elementAt(i);
    final String plainText = line.substring(currentIndex, match.start);
    if (plainText.isNotEmpty) {
      if (Constant.INLINE_MATCHER.hasMatch(plainText)) {
        spans.add(pw.TextSpan(
            children: await applyInlineStyles(plainText, style), style: style ?? defaultTextStyle)); // Apply currentinheritedStyle
      } else {
        spans.add(pw.TextSpan(
            text: plainText.convertUTF8QuotesToValidString.decodeSymbols,
            style: style ?? defaultTextStyle)); // Apply currentinheritedStyle
      }
    }
    final String contentWithMd = match.group(0)!;
    final String content = match.group(2)!;
    final bool isBold = contentWithMd.isBold;
    final bool isItalic = contentWithMd.isItalic;
    final bool isUnder = contentWithMd.isUnderline;
    final bool isStrike = contentWithMd.isStrike;
    final bool isAllInOne = contentWithMd.isAllStylesCombined;
    late pw.TextStyle textStyle;
    if (style == null) {
      textStyle = defaultTextStyle.resolveInline(
        isBold,
        isItalic,
        isUnder,
        isStrike,
        isAllInOne,
      );
    } else {
      textStyle = style.resolveInline(
        isBold,
        isItalic,
        isUnder,
        isStrike,
        isAllInOne,
      );
    }
    spans.add(pw.TextSpan(text: content.convertUTF8QuotesToValidString.replaceMd.decodeSymbols, style: textStyle));
    currentIndex = match.end;
    i++;
  }

  final String remainingText = line.substring(currentIndex);
  if (remainingText.isNotEmpty) {
    if (Constant.INLINE_MATCHER.hasMatch(remainingText)) {
      spans.add(pw.TextSpan(
          children: await applyInlineStyles(remainingText, style), style: style ?? defaultTextStyle)); // Apply currentinheritedStyle
    } else {
      spans.add(pw.TextSpan(
          text: remainingText.convertUTF8QuotesToValidString.decodeSymbols,
          style: style ?? defaultTextStyle)); // Apply currentinheritedStyle
    }
  }
  return spans;
}