fix: prevent documentToMarkdown from mutating source document (#1184)

* fix: prevent documentToMarkdown from mutating source document

convertNodes() was calling pageNode(children: nodes) which triggered
Node's constructor to unlink() each child from its original parent,
orphaning nested list items in the source document.

Fix by deep-copying nodes before passing them to pageNode().

Fixes https://github.com/AppFlowy-IO/AppFlowy/issues/8486

* chore: add regression test for issue #8486

Verifies that documentToMarkdown() does not orphan children of nested
list items in the source document after conversion.
This commit is contained in:
Lucas 2026-02-23 16:01:58 +08:00 • committed by GitHub
commit 301d0fa579
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -34,7 +34,9 @@ class DocumentMarkdownEncoder extends Converter<Document, String> {
List<Node> nodes, {
bool withIndent = false,
}) {
final result = convert(Document(root: pageNode(children: nodes)));
final result = convert(
Document(root: pageNode(children: nodes.map((n) => n.deepCopy()))),
);
if (result.isNotEmpty && withIndent) {
return result
.split('\n')