Skip to content

Commit 17b714a

Browse files
[flutter_markdown] Soft wrapping in blockquotes (#7848)
Makes `flutter_markdown` treat paragraphs in blockquotes like a normal paragraph with respect to soft wrapping. Currently, line breaks in blockquotes translate directly to line breaks in the output. This happens regardless of the Markdown Specification chosen. Such behavior is different from most Markdown implementations, including the reference ones cited in [flutter_markdown ](https://pub.dev/packages/flutter_markdown) ([Dart Markdown Live Editor](https://dart-lang.github.io/markdown/) and the [Markdown Live Preview](https://markdownlivepreview.com/)). Example: ``` > my > blockquote ``` Currently renders like: > my > blockquote And this PR fixes it to become: > my blockquote Note: previewing in this GitHub editor, I get the hard-wrap behavior. However, [Dart Markdown Live Editor](https://dart-lang.github.io/markdown/) gives the soft-wrap behavior in all flavors, even when "GitHub Flavored Markdown" is selected. Reading the GFM spec [there's an example](https://github.github.com/gfm/#example-222) that to me implies that soft-wrapping is the correct thing in GFM, plus that's what I gather from reading [6.12](https://github.github.com/gfm/#hard-line-breaks) and [6.13](https://github.github.com/gfm/#soft-line-breaks). However, if for some reason we should hard-wrap in GFM, it should be just a matter of checking the chosen `extensionSet` when deciding whether to call `trimText()`. Seems clear to me hard-wrapping shouldn't ever be the only behavior. Issues: this fixes flutter/flutter#156554
1 parent 53a0563 commit 17b714a

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-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.7.4
2+
3+
* Makes paragraphs in blockquotes soft-wrap like a normal `<blockquote>` instead of hard-wrapping like a `<pre>` block.
4+
15
## 0.7.3+2
26

37
* Resolves an issue where code blocks in markdown were not highlighted during selection.

packages/flutter_markdown/lib/src/builder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ class MarkdownBuilder implements md.NodeVisitor {
362362
style: _isInBlockquote
363363
? styleSheet.blockquote!.merge(_inlines.last.style)
364364
: _inlines.last.style,
365-
text: _isInBlockquote ? text.text : trimText(text.text),
365+
text: trimText(text.text),
366366
recognizer: _linkHandlers.isNotEmpty ? _linkHandlers.last : null,
367367
),
368368
textAlign: _textAlignForBlockTag(_currentBlockTag),

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.7.3+2
7+
version: 0.7.4
88

99
environment:
1010
sdk: ^3.3.0

packages/flutter_markdown/test/blockquote_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ void defineTests() {
2525
},
2626
);
2727

28+
testWidgets(
29+
'soft wrapping in blockquote',
30+
(WidgetTester tester) async {
31+
await tester.pumpWidget(
32+
boilerplate(
33+
const MarkdownBody(data: '> soft\n> wrap'),
34+
),
35+
);
36+
37+
final Iterable<Widget> widgets = tester.allWidgets;
38+
expectTextStrings(widgets, <String>['soft wrap']);
39+
},
40+
);
41+
2842
testWidgets(
2943
'should work with styling',
3044
(WidgetTester tester) async {

0 commit comments

Comments
 (0)