Skip to content

Commit

Permalink
[flutter_markdown] Strip leading whitespace from list items (flutter#…
Browse files Browse the repository at this point in the history
…5294)

In line with standard Markdown practice, whitespace at the beginning of list items is removed.

Fixes [Flutter issue #134847
](flutter/flutter#134847)
  • Loading branch information
krozett authored Nov 6, 2023
1 parent 49eac1f commit 03062da
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/flutter_markdown/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.18+2

* Removes leading whitespace from list items.

## 0.6.18+1

* Fixes a typo in README.
Expand Down
3 changes: 2 additions & 1 deletion packages/flutter_markdown/lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ class MarkdownBuilder implements md.NodeVisitor {
// Leading spaces in paragraph or list item are ignored
// https://github.github.com/gfm/#example-192
// https://github.github.com/gfm/#example-236
if (const <String>['ul', 'ol', 'p', 'br'].contains(_lastVisitedTag)) {
if (const <String>['ul', 'ol', 'li', 'p', 'br']
.contains(_lastVisitedTag)) {
text = text.replaceAll(leadingSpacesPattern, '');
}

Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_markdown/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: A Markdown renderer for Flutter. Create rich text output,
formatted with simple Markdown tags.
repository: https://github.com/flutter/packages/tree/main/packages/flutter_markdown
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_markdown%22
version: 0.6.18+1
version: 0.6.18+2

environment:
sdk: ">=3.0.0 <4.0.0"
Expand Down
22 changes: 22 additions & 0 deletions packages/flutter_markdown/test/list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,28 @@ void defineTests() {
'two',
]);
});

testWidgets(
'leading spaces are ignored (non-paragraph test case)',
(WidgetTester tester) async {
const String data = '- one\n- two\n- three';
await tester.pumpWidget(
boilerplate(
const MarkdownBody(data: data),
),
);

final Iterable<Widget> widgets = tester.allWidgets;
expectTextStrings(widgets, <String>[
'•',
'one',
'•',
'two',
'•',
'three',
]);
},
);
});

group('Ordered List', () {
Expand Down

0 comments on commit 03062da

Please sign in to comment.