Skip to content
Closed
Next Next commit
Pass parent TextStyle down to MarkdownElementBuilder.visitElementAfter
  • Loading branch information
IchordeDionysos committed Feb 23, 2023
commit f2e66c3ae0d51b401f1b4ca5419640b9b1fe408f
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ class SubscriptBuilder extends MarkdownElementBuilder {
];

@override
Widget visitElementAfter(md.Element element, TextStyle? preferredStyle) {
Widget visitElementAfter(
md.Element element,
TextStyle? preferredStyle,
TextStyle? parentStyle,
) {
// We don't currently have a way to control the vertical alignment of text spans.
// See https://github.com/flutter/flutter/issues/10906#issuecomment-385723664
final String textContent = element.textContent;
Expand Down
7 changes: 5 additions & 2 deletions packages/flutter_markdown/lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,11 @@ class MarkdownBuilder implements md.NodeVisitor {
}

if (builders.containsKey(tag)) {
final Widget? child =
builders[tag]!.visitElementAfter(element, styleSheet.styles[tag]);
final Widget? child = builders[tag]!.visitElementAfter(
element,
styleSheet.styles[tag],
parent.style,
);
if (child != null) {
current.children[0] = child;
}
Expand Down
9 changes: 8 additions & 1 deletion packages/flutter_markdown/lib/src/widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,15 @@ abstract class MarkdownElementBuilder {
/// If [MarkdownWidget.styleSheet] has a style of this tag, will passing
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't parse as a sentence. I'm assuming this should say something like "has a style for this tag, it will be passed as [preferredStyle]."?

/// to [preferredStyle].
///
/// If parent element has [TextStyle]'s set, it will be passed as
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"has a [TextStyle] set"

/// [parentStyle].
///
/// If you needn't build a widget, return null.
Widget? visitElementAfter(md.Element element, TextStyle? preferredStyle) =>
Widget? visitElementAfter(
md.Element element,
TextStyle? preferredStyle,
TextStyle? parentStyle,
) =>
null;
}

Expand Down
8 changes: 4 additions & 4 deletions packages/flutter_markdown/test/custom_syntax_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class SubscriptBuilder extends MarkdownElementBuilder {
];

@override
Widget visitElementAfter(md.Element element, _) {
Widget visitElementAfter(md.Element element, _, __) {
// We don't currently have a way to control the vertical alignment of text spans.
// See https://github.com/flutter/flutter/issues/10906#issuecomment-385723664
final String textContent = element.textContent;
Expand Down Expand Up @@ -172,7 +172,7 @@ class WikilinkSyntax extends md.InlineSyntax {

class WikilinkBuilder extends MarkdownElementBuilder {
@override
Widget visitElementAfter(md.Element element, _) {
Widget visitElementAfter(md.Element element, _, __) {
return RichText(
text: TextSpan(
text: element.textContent,
Expand All @@ -197,7 +197,7 @@ class ContainerSyntax extends md.InlineSyntax {

class ContainerBuilder extends MarkdownElementBuilder {
@override
Widget? visitElementAfter(md.Element element, _) {
Widget? visitElementAfter(md.Element element, _, __) {
return RichText(
text: TextSpan(
children: <InlineSpan>[
Expand All @@ -212,7 +212,7 @@ class ContainerBuilder extends MarkdownElementBuilder {

class ContainerBuilder2 extends MarkdownElementBuilder {
@override
Widget? visitElementAfter(md.Element element, _) {
Widget? visitElementAfter(md.Element element, _, __) {
return RichText(
text: TextSpan(
children: <InlineSpan>[
Expand Down