aboutsummaryrefslogtreecommitdiff
path: root/unhtml.lisp
blob: 7ecea1b5fdfac5d3534f689d3db86bf61e3b77d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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))))