From ebb9b9094ae7cbf091d91540fee65cfe8522b869 Mon Sep 17 00:00:00 2001 From: Magnus Henoch Date: Wed, 15 Apr 2009 13:11:30 +0100 Subject: [PATCH] * org-feed.el (org-feed-parse-atom-feed) (org-feed-parse-atom-entry): New functions. --- lisp/org-feed.el | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 50 insertions(+), 0 deletions(-) diff --git a/lisp/org-feed.el b/lisp/org-feed.el index 9c64bff..72d1a7a 100644 --- a/lisp/org-feed.el +++ b/lisp/org-feed.el @@ -596,6 +596,56 @@ containing the properties `:guid' and `:item-full-text'." (setq entry (plist-put entry :guid-permalink t)))) entry) +(defun org-feed-parse-atom-feed (buffer) + "Parse BUFFER for Atom feed entries. +Returns a list of enttries, with each entry a property list, +containing the properties `:guid' and `:item-full-text'. + +The `:item-full-text' property actually contains the sexp +formatted as a string, not the original XML data." + (with-current-buffer buffer + (widen) + (goto-char (point-min)) + ;; Skip HTTP headers + (search-forward "\n\n") + (delete-region (point-min) (point)) + (let ((feed (car (xml-parse-region (point-min) (point-max))))) + (mapcar + (lambda (entry) + (list + :guid (car (xml-node-children (car (xml-get-children entry 'id)))) + :item-full-text (prin1-to-string entry))) + (xml-get-children feed 'entry))))) + +(defun org-feed-parse-atom-entry (entry) + "Parse the `:item-full-text' as a sexp and create new properties." + (let ((xml (car (read-from-string (plist-get entry :item-full-text))))) + ;; Get first . + (setq entry (plist-put entry :link + (xml-get-attribute + (car (xml-get-children xml 'link)) + 'href))) + ;; Add as :title. + (setq entry (plist-put entry :title + (car (xml-node-children + (car (xml-get-children xml 'title)))))) + (let* ((content (car (xml-get-children xml 'content))) + (type (xml-get-attribute-or-nil content 'type))) + (when content + (cond + ((string= type "text") + ;; We like plain text. + (setq entry (plist-put entry :description (car (xml-node-children content))))) + ((string= type "html") + ;; TODO: convert HTML to Org markup. + (setq entry (plist-put entry :description (car (xml-node-children content))))) + ((string= type "xhtml") + ;; TODO: convert XHTML to Org markup. + (setq entry (plist-put entry :description (prin1-to-string (xml-node-children content))))) + (t + (setq entry (plist-put entry :description (format "Unknown '%s' content." type))))))) + entry)) + (provide 'org-feed) ;; arch-tag: 0929b557-9bc4-47f4-9633-30a12dbb5ae2 -- 1.6.0.2