Describe the bug
When a custom MarkdownElementBuilder is registered for an inline tag (e.g. a) and visitElementAfterWithContext returns a non-null widget, the builder only replaces current.children[0] instead of clearing all children. If the element has multiple children (e.g. link text containing delimiter characters like _ or *), the remaining children are still appended to the parent, causing duplicate text rendering.
To Reproduce
- Register a custom builder for the
a tag
- Send a message containing a link whose text includes a delimiter character, e.g.
[_hello world](https://example.com)
- The markdown parser splits the link text into multiple children:
[Text("_"), Text("hello world")]
- The builder widget replaces only
children[0], so Text("hello world") is also appended to the parent
- Result:
"hello world" appears twice
Expected behavior
When visitElementAfterWithContext returns a non-null widget, all existing children should be replaced by that widget — not just children[0].
Suggested fix
In builder.dart, change:
if (current.children.isEmpty) {
current.children.add(child);
} else {
current.children[0] = child;
}
to:
current.children
..clear()
..add(child);
Describe the bug
When a custom
MarkdownElementBuilderis registered for an inline tag (e.g.a) andvisitElementAfterWithContextreturns a non-null widget, the builder only replacescurrent.children[0]instead of clearing all children. If the element has multiple children (e.g. link text containing delimiter characters like_or*), the remaining children are still appended to the parent, causing duplicate text rendering.To Reproduce
atag[_hello world](https://example.com)[Text("_"), Text("hello world")]children[0], soText("hello world")is also appended to the parent"hello world"appears twiceExpected behavior
When
visitElementAfterWithContextreturns a non-null widget, all existing children should be replaced by that widget — not justchildren[0].Suggested fix
In
builder.dart, change:to: