1
0
Fork 0

- prevented adding a quote prefix to each element inside a blockquote tag, when converting html to text.

This commit is contained in:
cage 2023-11-17 16:08:30 +01:00
parent a2c7c1d581
commit d01b6c798f
1 changed files with 22 additions and 12 deletions

View File

@ -102,6 +102,8 @@
(defparameter *prefix-text-line* "") (defparameter *prefix-text-line* "")
(defparameter *block-tag* nil)
(defun html->text (html &key (defun html->text (html &key
(add-link-footnotes t) (body-footnotes-separator "") (add-link-footnotes t) (body-footnotes-separator "")
(quote-prefix "> ") (list-item-prefix "* ")) (quote-prefix "> ") (list-item-prefix "* "))
@ -130,11 +132,14 @@ Some convenience functions are provided to works with these structures.
(when node (when node
(cond (cond
((stringp node) ((stringp node)
(princ (strcat *prefix-text-line* node) body-stream)) (if *block-tag*
(princ (strcat *prefix-text-line* node) body-stream)
(princ node body-stream)))
((consp (car node)) ((consp (car node))
(descend (car node))) (descend (car node)))
((tag= +tag-link+ node) ((tag= +tag-link+ node)
(let ((link (find-attribute +attribute-url+ node))) (let ((*block-tag* nil)
(link (find-attribute +attribute-url+ node)))
(incf link-count) (incf link-count)
(if link (if link
(format footnotes-stream (format footnotes-stream
@ -149,20 +154,25 @@ Some convenience functions are provided to works with these structures.
(when add-link-footnotes (when add-link-footnotes
(format body-stream " [~a] " link-count)))) (format body-stream " [~a] " link-count))))
((tag= +tag-break+ node) ((tag= +tag-break+ node)
(let ((*block-tag* nil))
(format body-stream "~%") (format body-stream "~%")
(descend-children node)) (descend-children node)))
((or (tag= +tag-paragraph+ node) ((or (tag= +tag-paragraph+ node)
(tag= +tag-div+ node)) (tag= +tag-div+ node))
(let ((*block-tag* t))
(format body-stream "~%") (format body-stream "~%")
(descend-children node) (descend-children node)
(format body-stream "~%")) (format body-stream "~%")))
((tag= +tag-list-item+ node) ((tag= +tag-list-item+ node)
(let ((*block-tag* nil))
(format body-stream list-item-prefix) (format body-stream list-item-prefix)
(descend-children node) (descend-children node)
(format body-stream "~%")) (format body-stream "~%")))
((tag= +tag-blockquote+ node) ((tag= +tag-blockquote+ node)
(let ((*prefix-text-line* quote-prefix)) (let ((*prefix-text-line* quote-prefix)
(descend-children node))) (*block-tag* t))
(descend-children node)
(format body-stream "~%")))
(t (t
(descend-children node)))))) (descend-children node))))))
(descend root) (descend root)