Add MarkdownElementBuilder.wrapBlockWidget to wrap block widgets without replacing them (#124) - #147
Open
dkajiwara wants to merge 1 commit into
Open
Conversation
…s without replacing them Returning a widget from visitElementAfterWithContext replaces an element's default rendering entirely, which makes it impossible to attach a key (or any other wrapper) to a heading while keeping its inline formatting, style sheet styles and paddingBuilders padding. That is the building block needed for scrolling to `#fragment` links (foresightmobile#124). - Add `wrapBlockWidget(context, element, child)` to MarkdownElementBuilder. It is called for block elements with the fully built widget (including list bullets and blockquote / code block decoration) and returns `child` unchanged by default. - Fall back to the default text rendering when a block builder's `visitText` returns null, so a builder can override only `wrapBlockWidget` and still get the element's text rendered. - Add tests, an anchor link demo to the example app, and a README example.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #124
What
Adds
MarkdownElementBuilder.wrapBlockWidget(context, element, child).It is called with a block element's fully built widget and can wrap it while keeping the default rendering. Until now the only hook,
visitElementAfterWithContext, replaced the rendering entirely, so attaching a key to a heading meant losing its inline formatting and padding.With this hook, anchor links work like so (full version in the new Anchor Link Demo):
h1..h6that wraps each heading in a keyed widget.onTapLink, resolve the#fragmentto that key and callScrollable.ensureVisible.Behavior change
When a block builder's
visitTextreturnsnull, the default text rendering is now used instead of dropping the text.