-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[flutter_markdown] Fix WidgetSpan Support in MarkdownElementBuilder #6225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
d466fab
Enable RichText merging
pzierahn 413e890
Merge remote-tracking branch 'origin/main'
pzierahn 3ad85bf
Make text selectable
pzierahn 9ed8601
Added _getInlineSpans function
pzierahn 6c9fe97
Fix 'WidgetSpan in Text.rich is handled correctly' test
pzierahn 6db3f83
Modify _mergeSimilarTextSpans to handle a list of InlineSpans
pzierahn 716f1e7
Fix test 'TextSpan and WidgetSpan as children in Text.rich are handle…
pzierahn 82f6e63
Fix issue where certain children were not added correctly
pzierahn ff30c87
Update comments
pzierahn 4771d84
Added inline widget tests
pzierahn 60e981b
Update CHANGELOG.md
pzierahn b1e8ecb
Merge branch 'main' into main
pzierahn 5179ca6
Merge branch 'main' into main
domesticmouse 0aef52c
Fix missing type annotation
pzierahn 8e438bf
Remove print
pzierahn e3ea4fd
Merge remote-tracking branch 'origin/main'
pzierahn 1ae7cd0
Merge branch 'main' into main
pzierahn 8525899
Update package version
pzierahn 69876de
Merge remote-tracking branch 'origin/main'
pzierahn 10c0c7a
Merge branch 'main' into main
domesticmouse 6dfd49d
Ensure that sub spans match parent style
pzierahn ffae188
Simplified _getInlineSpans function
pzierahn 7b35dc8
Merge branch 'main' into main
domesticmouse 041bc04
Remove comment
pzierahn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter/cupertino.dart'; | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_markdown/flutter_markdown.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:markdown/markdown.dart' as md; | ||
|
|
||
| import 'utils.dart'; | ||
|
|
||
| void main() => defineTests(); | ||
|
|
||
| void defineTests() { | ||
| group('InlineWidget', () { | ||
| testWidgets( | ||
| 'Test inline widget', | ||
| (WidgetTester tester) async { | ||
| await tester.pumpWidget( | ||
| boilerplate( | ||
| MarkdownBody( | ||
| data: 'Hello, foo bar', | ||
| builders: <String, MarkdownElementBuilder>{ | ||
| 'sub': SubscriptBuilder(), | ||
| }, | ||
| extensionSet: md.ExtensionSet( | ||
| <md.BlockSyntax>[], | ||
| <md.InlineSyntax>[SubscriptSyntax()], | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
|
|
||
| final Text textWidget = tester.firstWidget(find.byType(Text)); | ||
| final TextSpan span = textWidget.textSpan! as TextSpan; | ||
|
|
||
| final TextSpan part1 = span.children![0] as TextSpan; | ||
| expect(part1.toPlainText(), 'Hello, '); | ||
|
|
||
| final WidgetSpan part2 = span.children![1] as WidgetSpan; | ||
| expect(part2.alignment, PlaceholderAlignment.middle); | ||
| expect(part2.child, isA<Text>()); | ||
| expect((part2.child as Text).data, 'foo'); | ||
|
|
||
| final TextSpan part3 = span.children![2] as TextSpan; | ||
| expect(part3.toPlainText(), ' bar'); | ||
| }, | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| class SubscriptBuilder extends MarkdownElementBuilder { | ||
| @override | ||
| Widget visitElementAfterWithContext( | ||
| BuildContext context, | ||
| md.Element element, | ||
| TextStyle? preferredStyle, | ||
| TextStyle? parentStyle, | ||
| ) { | ||
| // This pull request will add support for WidgetSpan in the FlutterMarkdown package | ||
| return Text.rich(WidgetSpan( | ||
| alignment: PlaceholderAlignment.middle, | ||
| child: Text(element.textContent), | ||
| )); | ||
| } | ||
| } | ||
|
|
||
| class SubscriptSyntax extends md.InlineSyntax { | ||
| SubscriptSyntax() : super(_pattern); | ||
|
|
||
| static const String _pattern = r'(foo)'; | ||
|
|
||
| @override | ||
| bool onMatch(md.InlineParser parser, Match match) { | ||
| parser.addNode(md.Element.text('sub', match[1]!)); | ||
| return true; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.