-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[flutter_markdown] Pass parent TextStyle down to MarkdownElementBuilder.visitElementAfter #3281
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
Conversation
@domesticmouse, how do we deal with the breaking change of the PR? |
@stuartmorgan thoughts? |
I've also exposed now the Which is a very hacky workaround and has it's own drawbacks 🙈 @override
Widget visitElementAfter(md.Element element, TextStyle? preferredStyle) {
return RichText(
text: TextSpan(
children: [
WidgetSpan(
child: Builder(
builder: (context) {
return Text(
innerText,
style: preferredStyle
);
},
),
),
],
),
);
} Feels free to leave any suggestions/feedback/change requests! |
Does it have to be a breaking change? What about a new method with a default implementation that calls the existing method (discarding the extra parameters)? |
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
@stuartmorgan thanks for the hint, I've just implemented it, not sure yet about the name of the new function 🤔 /cc @domesticmouse |
@domesticmouse if you find the time to give this a review here that would be awesome :) It's no longer a breaking change so should be easier to merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI is failing the autoformat check, so the code will need to be autoformatted.
|
||
* Introduce a new `MarkdownElementBuilder.visitElementAfterWithContext()` method passing the widget `BuildContext` and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Introduces"
See the CHANGELOG style guide linked from the PR descirption.
|
||
* Introduce a new `MarkdownElementBuilder.visitElementAfterWithContext()` method passing the widget `BuildContext` and | ||
the parent texts' `TextStyle`. | ||
This should allow custom syntax implementations to get data from the current context, as well as properly style any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changelog should just describe the change (the first sentence); it doesn't need to provide the motivation for it.
|
||
* Introduce a new `MarkdownElementBuilder.visitElementAfterWithContext()` method passing the widget `BuildContext` and | ||
the parent texts' `TextStyle`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
text's
/// Called when an Element has been reached, after its children have been | ||
/// visited. | ||
/// | ||
/// If [MarkdownWidget.styleSheet] has a style of this tag, will passing |
There was a problem hiding this comment.
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]."?
/// If [MarkdownWidget.styleSheet] has a style of this tag, will passing | ||
/// to [preferredStyle]. | ||
/// | ||
/// If parent element has [TextStyle]'s set, it will be passed as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"has a [TextStyle] set"
@IchordeDionysos Are you still planning on updating this based on the last round of feedback? |
I'm making this a draft just to get it off of the review queue; please mark it as ready for review once you've had a chance to update. Thanks! |
@tarrinneal to adopt, per triage meeting. |
Closing and moving changes over to #4393 as I cannot make changes to this pr. |
…er.visitElementAfter (#4393) The parent `TextStyle` should be passed down to the `MarkdownElementBuilder.visitElementAfter` method to allow custom markdown tags to override only part of the text style, e.g. the color, but keep all the rest of the styles the same. This is especially useful when trying to color markdown headers in a certain color, as the parent font size, font family, etc. all are passed down and can be kept, while only the color is overridden. This will unfortunately lead to a breaking change, due to the nature of how the class is typically used. As all usages of the class are sub-classes any change to the method schema will result in a breaking change! Enables the following flutter/flutter#105571 replaces #3281
The parent
TextStyle
should be passed down to theMarkdownElementBuilder.visitElementAfter
method to allow custom markdown tags to override only part of the text style, e.g. the color, but keep all the rest of the styles the same.This is especially useful when trying to color markdown headers in a certain color, as the parent font size, font family, etc. all are passed down and can be kept, while only the color is overridden.
This will unfortunately lead to a breaking change, due to the nature of how the class is typically used. As all usages of the class are sub-classes any change to the method schema will result in a breaking change!
Enables the following flutter/flutter#105571
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.