Skip to content

Commit

Permalink
Remove new API, update test
Browse files Browse the repository at this point in the history
  • Loading branch information
gspencergoog committed Oct 14, 2024
1 parent ff8ec0a commit 71b8cc2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 30 deletions.
38 changes: 17 additions & 21 deletions packages/flutter_markdown/lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ final List<String> _kBlockTags = <String>[

const List<String> _kListTags = <String>['ul', 'ol'];

bool _isBlockTag(String? tag) => _kBlockTags.contains(tag);

bool _isListTag(String tag) => _kListTags.contains(tag);

class _BlockElement {
Expand Down Expand Up @@ -109,7 +111,6 @@ class MarkdownBuilder implements md.NodeVisitor {
required this.builders,
required this.paddingBuilders,
required this.listItemCrossAxisAlignment,
required this.customBlockTags,
this.fitContent = false,
this.onSelectionChanged,
this.onTapText,
Expand Down Expand Up @@ -155,9 +156,6 @@ class MarkdownBuilder implements md.NodeVisitor {
/// does not allow for intrinsic height measurements.
final MarkdownListItemCrossAxisAlignment listItemCrossAxisAlignment;

/// Collection of custom block tags to be used building block widgets.
final List<String> customBlockTags;

/// Called when the user changes selection when [selectable] is set to true.
final MarkdownOnSelectionChangedCallback? onSelectionChanged;

Expand All @@ -180,10 +178,6 @@ class MarkdownBuilder implements md.NodeVisitor {
String? _lastVisitedTag;
bool _isInBlockquote = false;

bool _isBlockTag(String? tag) =>
_kBlockTags.contains(tag) ||
customBlockTags.contains(tag);

/// Returns widgets that display the given Markdown nodes.
///
/// The returned widgets are typically used as children in a [ListView].
Expand Down Expand Up @@ -391,16 +385,18 @@ class MarkdownBuilder implements md.NodeVisitor {
final _BlockElement current = _blocks.removeLast();
Widget child;

if (current.children.isNotEmpty) {
child = Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: fitContent
? CrossAxisAlignment.start
: CrossAxisAlignment.stretch,
children: current.children,
);
} else {
child = const SizedBox();
Widget defaultChild() {
if (current.children.isNotEmpty) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: fitContent
? CrossAxisAlignment.start
: CrossAxisAlignment.stretch,
children: current.children,
);
} else {
return const SizedBox();
}
}

if (builders.containsKey(tag)) {
Expand All @@ -411,9 +407,9 @@ class MarkdownBuilder implements md.NodeVisitor {
styleSheet.styles[tag],
_inlines.isNotEmpty ? _inlines.last.style : null,
);
if (builderChild != null) {
child = builderChild;
}
child = builderChild ?? defaultChild();
} else {
child = defaultChild();
}

if (_isListTag(tag)) {
Expand Down
7 changes: 0 additions & 7 deletions packages/flutter_markdown/lib/src/widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ abstract class MarkdownWidget extends StatefulWidget {
this.onTapLink,
this.onTapText,
this.imageDirectory,
this.customBlockTags,
this.blockSyntaxes,
this.inlineSyntaxes,
this.extensionSet,
Expand Down Expand Up @@ -270,9 +269,6 @@ abstract class MarkdownWidget extends StatefulWidget {
/// Collection of custom block syntax types to be used parsing the Markdown data.
final List<md.BlockSyntax>? blockSyntaxes;

/// Collection of custom block tags to be used building block widgets.
final List<String>? customBlockTags;

/// Collection of custom inline syntax types to be used parsing the Markdown data.
final List<md.InlineSyntax>? inlineSyntaxes;

Expand Down Expand Up @@ -397,7 +393,6 @@ class _MarkdownWidgetState extends State<MarkdownWidget>
imageBuilder: widget.imageBuilder,
checkboxBuilder: widget.checkboxBuilder,
bulletBuilder: widget.bulletBuilder,
customBlockTags: widget.customBlockTags,
builders: widget.builders,
paddingBuilders: widget.paddingBuilders,
fitContent: widget.fitContent,
Expand Down Expand Up @@ -469,7 +464,6 @@ class MarkdownBody extends MarkdownWidget {
super.onTapLink,
super.onTapText,
super.imageDirectory,
super.customBlockTags,
super.blockSyntaxes,
super.inlineSyntaxes,
super.extensionSet,
Expand Down Expand Up @@ -525,7 +519,6 @@ class Markdown extends MarkdownWidget {
super.onTapLink,
super.onTapText,
super.imageDirectory,
super.customBlockTags,
super.blockSyntaxes,
super.inlineSyntaxes,
super.extensionSet,
Expand Down
7 changes: 5 additions & 2 deletions packages/flutter_markdown/test/custom_syntax_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ void defineTests() {
builders: <String, MarkdownElementBuilder>{
'note': NoteBuilder(),
},
customBlockTags: const <String>['note'],
),
),
);
Expand Down Expand Up @@ -77,7 +76,6 @@ void defineTests() {
builders: <String, MarkdownElementBuilder>{
'custom': CustomTagBlockBuilder(),
},
customBlockTags: const <String>['custom'],
),
),
);
Expand Down Expand Up @@ -413,6 +411,11 @@ class NoteSyntax extends md.BlockSyntax {
}

class CustomTagBlockBuilder extends MarkdownElementBuilder {
@override
bool isBlockElement() {
return true;
}

@override
Widget visitElementAfterWithContext(
BuildContext context,
Expand Down

0 comments on commit 71b8cc2

Please sign in to comment.