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:
parent
955db55b8a
commit
301d0fa579
1 changed files with 35 additions and 1 deletions
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Reference in a new issue