(defn
common-ancestor
"Returns the common ancestor of the given nodes."
[first-node second-node]
(let
[first-parent
(first (get-parents first-node "collection"))
second-parent
(first (get-parents second-node "collection"))]
(cond
(and first-parent second-parent (= first-parent second-parent))
first-parent
(and
(= first-node second-node)
(text-node? first-node)
(top-level? first-node))
first-node)))