diff atom.js @ 7:7ab6b48122af

Add support for content in Atom and improve published display.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 02 Nov 2011 09:35:46 -0700
parents 4d7a67349089
children 461a24a5a788
line wrap: on
line diff
--- a/atom.js
+++ b/atom.js
@@ -84,6 +84,45 @@ parsers[ns.atom] = function(id, xml) {
 			article.appendChild(p);
 		}
 
+		var atomContent = atom.getChild('content');
+		if (atomContent) {
+			var contentType = atomContent.getAttribute('type');
+			if (/^text$/.test(contentType)) {
+				var p = document.createElementNS(ns.xhtml, 'p');
+				p.appendChild(document.createTextNode(atomContent.getText()));
+				article.appendChild(p);
+			} else if (/^html$/.test(contentType)) {
+				article.insertAdjacentHTML('beforeend', atomContent.getText()); // FIXME: could be not-well-formed.
+			} else if (/^xhtml$/.test(contentType)) {
+				// TODO: use a better xml2json lib that allow to json2xml
+				/*var div = atomContent.getChild();
+				article.appendChild(div.innerXml());*/
+			} else {
+				var contentSrc = atomContent.getAttribute('src');
+				if (contentSrc) {
+					if (/^image\//.test(contentType)) {
+						var img = document.createElementNS(ns.xhtml, 'img');
+						img.setAttributeNS(null, 'src', contentSrc);
+						article.appendChild(img);
+					} else if (/^audio\//.test(contentType)) {
+						var audio = document.createElementNS(ns.xhtml, 'audio');
+						audio.setAttributeNS(null, 'src', contentSrc);
+						audio.setAttributeNS(null, 'controls', '');
+						article.appendChild(audio);
+					} else if (/^video\//.test(contentType)) {
+						var video = document.createElementNS(ns.xhtml, 'video');
+						video.setAttributeNS(null, 'src', contentSrc);
+						video.setAttributeNS(null, 'controls', '');
+						article.appendChild(video);
+					} else {
+						var a = document.createElementNS(ns.xhtml, 'a');
+						a.setAttributeNS(null, 'href', contentSrc);
+						article.appendChild(a);
+					}
+				}
+			}
+		}
+
 		var atomLinks = atom.getChildren('link');
 		for (var i in atomLinks) {
 			var atomLink = atomLinks[i];