]> gitweb.michael.orlitzky.com - dead/lwn-epub.git/blobdiff - src/LWN/Article.hs
Go through a good bit of nonsense to get it successfully parsing our three test cases.
[dead/lwn-epub.git] / src / LWN / Article.hs
index 2da17354249edd936b4bc74648b1612ebf7ec2a1..70c68a5190d724fc2663531c57a63d02efb7c227 100644 (file)
@@ -3,12 +3,36 @@ where
 
 import XHTML
 
-data Article = Article { headline  :: String,
-                         byline    :: String,
-                         body_html :: String }
+newtype Title    = Title    { getTitle    :: String }
+newtype Byline   = Byline   { getByline   :: Maybe String }
+newtype BodyHtml = BodyHtml { getBodyHtml :: String }
+
+instance Show Title where
+  show = getTitle
+
+instance Show Byline where
+  show (Byline (Just bl)) = bl
+  show (Byline Nothing  ) = ""
+
+instance Show BodyHtml where
+  show = getBodyHtml
+
+instance XHTML Title where
+  to_xhtml (Title t) = "<h2>" ++ t ++ "</h2>"
+
+instance XHTML Byline where
+  to_xhtml (Byline (Just bl)) = "<p><em>" ++ bl ++ "</em></p>"
+  to_xhtml (Byline Nothing)   = ""
+
+instance XHTML BodyHtml where
+  to_xhtml = getBodyHtml
+
+data Article = Article { title     :: Title,
+                         byline    :: Byline,
+                         body_html :: BodyHtml }
 
 instance XHTML Article where
-  to_xhtml (Article hl bl b) =
-    "<h1>" ++ hl ++ "</h1>\n\n" ++
-    "<h2>" ++ bl ++ "</h2>\n\n" ++
-    b
+  to_xhtml (Article t bl b) =
+    (to_xhtml t)  ++
+    (to_xhtml bl) ++
+    (to_xhtml b)