Skip to content

fix: fix to issue #132 (implementation of child(through) #133

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Markdown/Base/Markup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
15 changes: 15 additions & 0 deletions Tests/MarkdownTests/Base/MarkupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down