getAlignedParagraphBlock method
Future<List<Widget>>
getAlignedParagraphBlock(
- String line, [
- TextStyle? style
])
override
Implementation
@override
Future<List<pw.Widget>> getAlignedParagraphBlock(String line, [pw.TextStyle? style]) async {
if (Constant.HTML_IMAGE_PATTERN.hasMatch(line)) {
final RegExp matcher = Constant.HTML_IMAGE_PATTERN;
final RegExpMatch match = matcher.firstMatch(line)!;
final pw.Alignment alignment = match.group(1)!.resolvePdfBlockAlign;
final String sourceImage = match.group(2)!;
String mdImage = convertHtmlToMarkdown(sourceImage, rules, <String>[]);
return <pw.Widget>[(await getImageBlock.call(mdImage, alignment)) ?? pw.SizedBox()];
}
final Iterable<RegExpMatch> matches = Constant.ALIGNED_P_PATTERN.allMatches(line);
final List<pw.Widget> widgets = <pw.Widget>[];
int index = 0;
while (index < matches.length) {
final RegExpMatch match = matches.elementAt(index);
final String alignment = match.group(1)!;
final String content = match.group(2)!;
final pw.Alignment blockAlign = alignment.resolvePdfBlockAlign;
final List<pw.InlineSpan> spans = <pw.InlineSpan>[];
if (content.isNotEmpty) {
spans.addAll(await _getStylesSpans(content, style));
}
widgets.add(
pw.Container(
alignment: blockAlign,
padding: const pw.EdgeInsets.symmetric(vertical: 2),
child: pw.RichText(
textAlign: alignment.resolvePdfTextAlign,
softWrap: true,
overflow: pw.TextOverflow.span,
text: pw.TextSpan(
children: spans,
),
),
),
);
index++;
}
return widgets;
}