Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/flutter_markdown/lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ class MarkdownBuilder implements md.NodeVisitor {
String? _lastVisitedTag;
bool _isInBlockquote = false;

bool _isBuildingLastNode = false;

/// Returns widgets that display the given Markdown nodes.
///
/// The returned widgets are typically used as children in a [ListView].
Expand All @@ -279,9 +281,10 @@ class MarkdownBuilder implements md.NodeVisitor {
});

_blocks.add(_BlockElement(null));

_isBuildingLastNode = false;
for (final md.Node node in nodes) {
assert(_blocks.length == 1);
_isBuildingLastNode = node == nodes.last;
//Not allow ul in p case
//https://stackoverflow.com/a/5681796
if (node is md.Element && node.tag == 'p') {
Expand Down Expand Up @@ -712,13 +715,16 @@ class MarkdownBuilder implements md.NodeVisitor {
child = child0;

if (isInlineBlock) {
// #20591: prevent applying extra \n for the last inline block
if (!_isBuildingLastNode) {
_inlineWidgets.add(_buildRichText(TextSpan(
// see another similar block in the visitElementBefore
// since we don't know if the following block is a inline text block,
// so we leave adding more \n to the next node
text: '\n',
style: styleSheet.styles[tag]
)));
}
} else {
_addBlockChild(child);
}
Expand Down