diff options
Diffstat (limited to 'unhtml.lisp')
-rw-r--r-- | unhtml.lisp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/unhtml.lisp b/unhtml.lisp new file mode 100644 index 0000000..7ecea1b --- /dev/null +++ b/unhtml.lisp @@ -0,0 +1,20 @@ +(defpackage :phaser.unhtml + (:use :common-lisp) + (:export + #:text-excerpt)) + +(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 length) + (let ((text-nodes (text-children (plump:parse content)))) + (plump:text (first text-nodes)))) |