Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
georgemp opened this issue Jun 20, 2023 · 0 comments · Fixed by #133
Closed

Comments

@georgemp
Copy link
Contributor

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.

georgemp added a commit to georgemp/swift-markdown that referenced this issue Jun 20, 2023
`func child(through path: TypedChildIndexPath) -> Markup?` uses the root document node's child count
for comparison against the passed in path for valid reference to a child. Changed it to use the
current iterated element.

fix apple#132
georgemp added a commit to georgemp/swift-markdown that referenced this issue Jun 20, 2023
QuietMisdreavus pushed a commit that referenced this issue Jun 20, 2023
`func child(through path: TypedChildIndexPath) -> Markup?` uses the root document node's child count
for comparison against the passed in path for valid reference to a child. Changed it to use the
current iterated element.

fix #132
QuietMisdreavus pushed a commit that referenced this issue Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant