There are two different protocols for container elements currently:
ContainerOfBlocks
ContainerOfInlineElements
Both protocols have extensions which implement exactly the same logic, except that the return and input types differ (Block & Node vs. Inline & Node).
On top of that, both List and List.Item have the same extensions, again with different types. So there are basically four times the same implementations. Fixing bugs or adding functionality needs to be replicated four times.
We could simplify this to use one single container protocol instead. The unified protocol would look like:
public protocol Container: Node {
associatedtype ChildNode
}
The different container elements would declare conformance with an implementation like:
extension Document: Container {
public typealias ChildNode = Block & Node
}
The methods in an extension of the protocol would then look like this example for insert(child:before:):
public func insert(child: ChildNode, before sibling: ChildNode) -> Bool {
return add(child) { cmark_node_insert_before(sibling.cmark_node, child.cmark_node) }
}
What do you think? I can readily provide a pull request implementing the concept.