-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create custom sequence to access child nodes (#228)
* Create sequence type for child nodes. * Directly convert DownRenderable to Document * Remove childSequence requirement from Node protocol. Add to the extension instead. * Remove toDocument requirement from the DownASTRenderable protocol. * Make documentation for DownASTRenderable.toDocument more clear Co-authored-by: Rob Phillips <rob@getkeepsafe.com>
- Loading branch information
1 parent
968ef0d
commit 6689a8f
Showing
9 changed files
with
64 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// ChildSequence.swift | ||
// Down | ||
// | ||
// Created by Sven Weidauer on 05.10.2020 | ||
// | ||
|
||
import libcmark | ||
|
||
/// Sequence of child nodes | ||
public struct ChildSequence: Sequence { | ||
let node: CMarkNode | ||
|
||
public struct Iterator: IteratorProtocol { | ||
var node: CMarkNode? | ||
|
||
public mutating func next() -> Node? { | ||
guard let node = node else { return nil } | ||
defer { self.node = cmark_node_next(node) } | ||
|
||
guard let result = node.wrap() else { | ||
assertionFailure("Couldn't wrap node of type: \(node.type)") | ||
return nil | ||
} | ||
|
||
return result | ||
} | ||
} | ||
|
||
public func makeIterator() -> Iterator { | ||
return Iterator(node: cmark_node_first_child(node)) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters