(in-package :phaser.unhtml)

(defun node-has-text (node)
  (let ((tag (plump:tag-name node))
	(has-text (not (string= (plump:text node) ""))))
    (and (string= tag "p")
	 has-text)))

(defun text-children (dom)
  (loop for c across (plump:child-elements dom)
	if (node-has-text c) collect c ))

(defun text-excerpt (content excerpt-length)
  (let ((text-nodes (text-children (plump:parse content))))
    (if text-nodes
	(let ((text (plump:text (first text-nodes))))
	  (subseq text 0 (min excerpt-length (length text))))
	nil)))