[flutter_markdown] Require pkg:markdown v7.0.0 (#3194)

* [flutter_markdown] Require pkg:markdown v7.0.0

Remove code that supports markdown ^6.0.0

Closes https://github.com/flutter/flutter/issues/120486

* remove comment

* whitespace silly
This commit is contained in:
Kevin Moore
2023-02-11 15:31:28 -08:00
committed by GitHub
parent 6e00c2b7e2
commit 0fe1b4448f
8 changed files with 59 additions and 176 deletions

View File

@ -1,3 +1,7 @@
## 0.6.14
* Require `markdown: ^7.0.0`
## 0.6.13+1 ## 0.6.13+1
* Adjusts code to account for nullability change in Flutter SDK. * Adjusts code to account for nullability change in Flutter SDK.

View File

@ -11,7 +11,7 @@ dependencies:
sdk: flutter sdk: flutter
flutter_markdown: flutter_markdown:
path: ../ path: ../
markdown: ^6.0.0 markdown: ^7.0.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

View File

@ -470,31 +470,11 @@ class MarkdownBuilder implements md.NodeVisitor {
current.children.add(_buildRichText(const TextSpan(text: '\n'))); current.children.add(_buildRichText(const TextSpan(text: '\n')));
} else if (tag == 'th' || tag == 'td') { } else if (tag == 'th' || tag == 'td') {
TextAlign? align; TextAlign? align;
// `style` was using in pkg:markdown <= 6.0.1 final String? alignAttribute = element.attributes['align'];
// Can be removed when min pkg:markedwn > 6.0.1 if (alignAttribute == null) {
final String? style = element.attributes['style']; align = tag == 'th' ? styleSheet.tableHeadAlign : TextAlign.left;
if (style == null) {
// `align` is using in pkg:markdown > 6.0.1
final String? alignAttribute = element.attributes['align'];
if (alignAttribute == null) {
align = tag == 'th' ? styleSheet.tableHeadAlign : TextAlign.left;
} else {
switch (alignAttribute) {
case 'left':
align = TextAlign.left;
break;
case 'center':
align = TextAlign.center;
break;
case 'right':
align = TextAlign.right;
break;
}
}
} else { } else {
final RegExp regExp = RegExp(r'text-align: (left|center|right)'); switch (alignAttribute) {
final Match match = regExp.matchAsPrefix(style)!;
switch (match[1]) {
case 'left': case 'left':
align = TextAlign.left; align = TextAlign.left;
break; break;

View File

@ -4,7 +4,7 @@ description: A Markdown renderer for Flutter. Create rich text output,
formatted with simple Markdown tags. formatted with simple Markdown tags.
repository: https://github.com/flutter/packages/tree/main/packages/flutter_markdown 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 issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_markdown%22
version: 0.6.13+1 version: 0.6.14
environment: environment:
sdk: ">=2.12.0 <3.0.0" sdk: ">=2.12.0 <3.0.0"
@ -13,7 +13,7 @@ environment:
dependencies: dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
markdown: ^6.0.0 markdown: ^7.0.0
meta: ^1.3.0 meta: ^1.3.0
path: ^1.8.0 path: ^1.8.0

View File

@ -629,13 +629,7 @@ void defineTests() {
); );
expectValidLink('link'); expectValidLink('link');
if (!newMarkdown) { expectLinkTap(linkTapResults, const MarkdownLink('link', 'foo%08ar'));
// For pkg:markdown <= v6.0.1
expectLinkTap(linkTapResults, const MarkdownLink('link', 'foo\bar'));
} else {
// For pkg:markdown > v6.0.1
expectLinkTap(linkTapResults, const MarkdownLink('link', 'foo%08ar'));
}
}, },
); );
@ -656,15 +650,8 @@ void defineTests() {
); );
expectValidLink('link'); expectValidLink('link');
if (!newMarkdown) { expectLinkTap(
// For pkg:markdown <= v6.0.1 linkTapResults, const MarkdownLink('link', 'foo%20b%C3%A4'));
expectLinkTap(
linkTapResults, const MarkdownLink('link', 'foo%20b&auml;'));
} else {
// For pkg:markdown > v6.0.1
expectLinkTap(
linkTapResults, const MarkdownLink('link', 'foo%20b%C3%A4'));
}
}, },
); );
@ -773,15 +760,8 @@ void defineTests() {
); );
expectValidLink('link'); expectValidLink('link');
if (!newMarkdown) { expectLinkTap(linkTapResults,
// For pkg:markdown <= v6.0.1 const MarkdownLink('link', '/url', 'title &quot;&quot;'));
expectLinkTap(linkTapResults,
const MarkdownLink('link', '/url', 'title %22&quot;'));
} else {
// For pkg:markdown > v6.0.1
expectLinkTap(linkTapResults,
const MarkdownLink('link', '/url', 'title &quot;&quot;'));
}
}, },
); );
@ -802,15 +782,8 @@ void defineTests() {
); );
expectValidLink('link'); expectValidLink('link');
if (!newMarkdown) { expectLinkTap(linkTapResults,
// For pkg:markdown <= v6.0.1 const MarkdownLink('link', '/url%EC%8A%A0%22title%22'));
expectLinkTap(linkTapResults,
const MarkdownLink('link', '/url\u{C2A0}%22title%22'));
} else {
// For pkg:markdown > v6.0.1
expectLinkTap(linkTapResults,
const MarkdownLink('link', '/url%EC%8A%A0%22title%22'));
}
}, },
); );
@ -853,17 +826,10 @@ void defineTests() {
); );
expectValidLink('link'); expectValidLink('link');
if (!newMarkdown) { expectLinkTap(
// For pkg:markdown <= v6.0.1 linkTapResults,
expectLinkTap(linkTapResults, const MarkdownLink('link', '/url', 'title &quot;and&quot; title'),
const MarkdownLink('link', '/url', 'title %22and%22 title')); );
} else {
// For pkg:markdown > v6.0.1
expectLinkTap(
linkTapResults,
const MarkdownLink('link', '/url', 'title &quot;and&quot; title'),
);
}
}, },
); );

View File

@ -5,6 +5,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'utils.dart'; import 'utils.dart';
void main() => defineTests(); void main() => defineTests();
@ -86,35 +87,18 @@ void defineTests() {
); );
final Iterable<Widget> widgets = tester.allWidgets; final Iterable<Widget> widgets = tester.allWidgets;
if (!newMarkdown) { expectTextStrings(widgets, <String>[
// For pkg:markdown <= v6.0.1 '1.',
expectTextStrings(widgets, <String>[ 'Item 1',
'1.', '2.',
'Item 1', 'Item 2',
'2.', '3.',
'Item 2', 'Item 3',
'3.', '4.',
'Item 3', 'Item 10',
'10.', '5.',
'Item 10', 'Item 11'
'11.', ]);
'Item 11'
]);
} else {
// For pkg:markdown > v6.0.1
expectTextStrings(widgets, <String>[
'1.',
'Item 1',
'2.',
'Item 2',
'3.',
'Item 3',
'4.',
'Item 10',
'5.',
'Item 11'
]);
}
}, },
); );

View File

@ -391,43 +391,18 @@ void defineTests() {
expectTableSize(3, 2); expectTableSize(3, 2);
if (!newMarkdown) { expect(find.byType(RichText), findsNWidgets(7));
// For pkg:markdown <= v6.0.1 final List<String?> text = find
expect(find.byType(RichText), findsNWidgets(6)); .byType(RichText)
final List<String?> text = find .evaluate()
.byType(RichText) .map((Element e) => e.widget)
.evaluate() .cast<RichText>()
.map((Element e) => e.widget) .map((RichText richText) => richText.text)
.cast<RichText>() .cast<TextSpan>()
.map((RichText richText) => richText.text) .map((TextSpan e) => e.text)
.cast<TextSpan>() .toList();
.map((TextSpan e) => e.text) expect(text, <String>['abc', 'def', 'bar', 'baz', 'bar', '', 'bar']);
.toList(); expect(table.defaultColumnWidth, columnWidth);
expect(text[0], 'abc');
expect(text[1], 'def');
expect(text[2], 'bar');
expect(text[3], 'baz');
expect(text[4], 'bar');
expect(table.defaultColumnWidth, columnWidth);
// Paragraph text
expect(text[5], 'bar');
} else {
// For pkg:markdown > v6.0.1
expect(find.byType(RichText), findsNWidgets(7));
final List<String?> text = find
.byType(RichText)
.evaluate()
.map((Element e) => e.widget)
.cast<RichText>()
.map((RichText richText) => richText.text)
.cast<TextSpan>()
.map((TextSpan e) => e.text)
.toList();
expect(
text, <String>['abc', 'def', 'bar', 'baz', 'bar', '', 'bar']);
expect(table.defaultColumnWidth, columnWidth);
}
}, },
); );
@ -460,7 +435,6 @@ void defineTests() {
.toList(); .toList();
expect(text[0], '| abc | def | | --- | | bar |'); expect(text[0], '| abc | def | | --- | | bar |');
}, },
skip: !newMarkdown,
); );
testWidgets( testWidgets(
@ -485,39 +459,18 @@ void defineTests() {
expectTableSize(3, 2); expectTableSize(3, 2);
if (!newMarkdown) { expect(find.byType(RichText), findsNWidgets(6));
// For pkg:markdown <= v6.0.1 final List<String?> cellText = find
expect(find.byType(RichText), findsNWidgets(5)); .byType(RichText)
final List<String?> cellText = find .evaluate()
.byType(RichText) .map((Element e) => e.widget)
.evaluate() .cast<RichText>()
.map((Element e) => e.widget) .map((RichText richText) => richText.text)
.cast<RichText>() .cast<TextSpan>()
.map((RichText richText) => richText.text) .map((TextSpan e) => e.text)
.cast<TextSpan>() .toList();
.map((TextSpan e) => e.text) expect(cellText, <String>['abc', 'def', 'bar', '', 'bar', 'baz']);
.toList(); expect(table.defaultColumnWidth, columnWidth);
expect(cellText[0], 'abc');
expect(cellText[1], 'def');
expect(cellText[2], 'bar');
expect(cellText[3], 'bar');
expect(cellText[4], 'baz');
expect(table.defaultColumnWidth, columnWidth);
} else {
// For pkg:markdown > v6.0.1
expect(find.byType(RichText), findsNWidgets(6));
final List<String?> cellText = find
.byType(RichText)
.evaluate()
.map((Element e) => e.widget)
.cast<RichText>()
.map((RichText richText) => richText.text)
.cast<TextSpan>()
.map((TextSpan e) => e.text)
.toList();
expect(cellText, <String>['abc', 'def', 'bar', '', 'bar', 'baz']);
expect(table.defaultColumnWidth, columnWidth);
}
}, },
); );

View File

@ -9,10 +9,6 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:markdown/markdown.dart' as md show version;
// TODO(Zhiguang): delete this once the min version of pkg:markdown is updated
final bool newMarkdown = md.version.compareTo('6.0.1') > 0;
final TextTheme textTheme = Typography.material2018() final TextTheme textTheme = Typography.material2018()
.black .black