SwiftDocOrg / CommonMark

Create, parse, and render Markdown text according to the CommonMark specification
MIT License
179 stars 10 forks source link

Direct children of Document don't have a parent node. #7

Closed Lukas-Stuehrk closed 4 years ago

Lukas-Stuehrk commented 4 years ago

Direct children of Documents don't have a parent node.

Minimal test case to reproduce the issue:

    func testChildrenShouldHaveParent() throws {
        let markdown = #######"""
        aaa

        bbb

        """#######

        let document = try Document(markdown)

        for child in document.children {
            XCTAssertNotNil(child.parent)
        }
    }

From my understanding, this is not the expected behavior. They should have the document as their parent node.

This is also the reason why most operations on a document are failing, e.g. insert(child:after:) or insert(child:before:), as those operations check for a parent node in cmark.

mattt commented 4 years ago

Thanks for filing this issue, @Lukas-Stuehrk. I have a fix for this with #8.