Skip to content

Cannot reliably get child element using child(through:) when there are multiple paragraphs #132

Closed
@georgemp

Description

@georgemp

Consider the following markdown string

let source = """
This is a markup __*document*__ with *some* **more** attributes.

This is the *second* paragraph.
This is on a **new** line, but, continues on the same paragraph.

This is the *third* paragraph.
This is on a **new** line, but, continues on the same paragraph.
"""

This generates the following markdown tree (correctly)

Document
├─ Paragraph
│  ├─ Text "This is a markup "
│  ├─ Strong
│  │  └─ Emphasis
│  │     └─ Text "document"
│  ├─ Text " with "
│  ├─ Emphasis
│  │  └─ Text "some"
│  ├─ Text " "
│  ├─ Strong
│  │  └─ Text "extended"
│  └─ Text " attributes."
├─ Paragraph
│  ├─ Text "This is the "
│  ├─ Emphasis
│  │  └─ Text "second"
│  ├─ Text " paragraph."
│  ├─ SoftBreak
│  ├─ Text "This is on a "
│  ├─ Strong
│  │  └─ Text "new"
│  └─ Text " line, but, continues on the same paragraph."
└─ Paragraph
   ├─ Text "This is the "
   ├─ Emphasis
   │  └─ Text "third"
   ├─ Text " paragraph."
   ├─ SoftBreak
   ├─ Text "This is on a "
   ├─ Strong
   │  └─ Text "new"
   └─ Text " line, but, continues on the same paragraph."

If we try to access the strong element (reads as new) on the second paragraph with let secondStrong = document.child(through: [1, 5]) it will be nil. It is expected that this will be a strong node.

Trying to access any element whose second indexpath is greater than 3 (the number of paragraphs or children) on the root document returns nil.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions