Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define-node-list-function wrap-all (working-nodes html-or-nodes)
- "Wrap an HTML structure around all elements inside their next (common) parent."
- (loop with wrapper-template = (first (nodes-or-build html-or-nodes))
- with parentmap = (make-hash-table)
- for node in working-nodes
- for parent = (dom:parent-node node)
- do (setf (gethash parent parentmap)
- (append (gethash parent parentmap) (list node)))
- finally (loop for parent being the hash-keys of parentmap
- for children being the hash-values of parentmap
- for wrapper = (dom:clone-node wrapper-template T)
- for index = (first (sort (nodefun-child-index children) #'<))
- do (buildnode:insert-nodes (nodefun-deepest wrapper) 0 children)
- (buildnode:insert-nodes parent index wrapper)))
- working-nodes)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement