diff --git a/Sources/Markdown/Base/Markup.swift b/Sources/Markdown/Base/Markup.swift index 4b271bff..23c72e78 100644 --- a/Sources/Markdown/Base/Markup.swift +++ b/Sources/Markdown/Base/Markup.swift @@ -265,7 +265,7 @@ extension Markup { public func child(through path: TypedChildIndexPath) -> Markup? { var element: Markup = self for pathElement in path { - guard pathElement.index <= raw.markup.childCount else { + guard pathElement.index <= element.childCount else { return nil } diff --git a/Tests/MarkdownTests/Base/MarkupTests.swift b/Tests/MarkdownTests/Base/MarkupTests.swift index 4258a921..15730437 100644 --- a/Tests/MarkdownTests/Base/MarkupTests.swift +++ b/Tests/MarkdownTests/Base/MarkupTests.swift @@ -283,6 +283,21 @@ final class MarkupTests: XCTestCase { )!.debugDescription() ) } + + func testChildThroughIndicesWithMultipleParagraphs() { + 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. +""" + + let document = Document(parsing: source) + XCTAssertNotNil(document.child(through: [2, 5]) as? Strong) + } func testChildAtPositionHasCorrectType() throws { let source = "This is a [*link*](github.com). And some **bold** and *italic* text."