Skip to content

Commit 03062da

Browse files
authored
[flutter_markdown] Strip leading whitespace from list items (flutter#5294)
In line with standard Markdown practice, whitespace at the beginning of list items is removed. Fixes [Flutter issue flutter#134847 ](flutter#134847)
1 parent 49eac1f commit 03062da

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

packages/flutter_markdown/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.6.18+2
2+
3+
* Removes leading whitespace from list items.
4+
15
## 0.6.18+1
26

37
* Fixes a typo in README.

packages/flutter_markdown/lib/src/builder.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ class MarkdownBuilder implements md.NodeVisitor {
323323
// Leading spaces in paragraph or list item are ignored
324324
// https://github.github.com/gfm/#example-192
325325
// https://github.github.com/gfm/#example-236
326-
if (const <String>['ul', 'ol', 'p', 'br'].contains(_lastVisitedTag)) {
326+
if (const <String>['ul', 'ol', 'li', 'p', 'br']
327+
.contains(_lastVisitedTag)) {
327328
text = text.replaceAll(leadingSpacesPattern, '');
328329
}
329330

packages/flutter_markdown/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: A Markdown renderer for Flutter. Create rich text output,
44
formatted with simple Markdown tags.
55
repository: https://github.com/flutter/packages/tree/main/packages/flutter_markdown
66
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_markdown%22
7-
version: 0.6.18+1
7+
version: 0.6.18+2
88

99
environment:
1010
sdk: ">=3.0.0 <4.0.0"

packages/flutter_markdown/test/list_test.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,28 @@ void defineTests() {
7272
'two',
7373
]);
7474
});
75+
76+
testWidgets(
77+
'leading spaces are ignored (non-paragraph test case)',
78+
(WidgetTester tester) async {
79+
const String data = '- one\n- two\n- three';
80+
await tester.pumpWidget(
81+
boilerplate(
82+
const MarkdownBody(data: data),
83+
),
84+
);
85+
86+
final Iterable<Widget> widgets = tester.allWidgets;
87+
expectTextStrings(widgets, <String>[
88+
'•',
89+
'one',
90+
'•',
91+
'two',
92+
'•',
93+
'three',
94+
]);
95+
},
96+
);
7597
});
7698

7799
group('Ordered List', () {

0 commit comments

Comments
 (0)