-module Epublishable
-where
-
-import Text.Pandoc
-import qualified Data.ByteString.Lazy as B (ByteString, writeFile)
-import Data.Time (getCurrentTime)
-import Data.Tree.NTree.TypeDefs (NTree)
-import System.FilePath (normalise)
-import Text.XML.HXT.Core (IOSArrow, XNode, XmlTree)
-
-import XHTML
-
-
-class (XHTML a) => Epublishable a where
- parse :: IOSArrow XmlTree (NTree XNode) -> IO (Maybe a)
-
- title :: a -> String
-
- metadata :: a -> IO String
- metadata obj = do
- date <- getCurrentTime
- return $
- "<dc:creator>http://lwn.net/</dc:creator>\n" ++
- "<dc:date>" ++ (show date) ++ "</dc:date>\n" ++
- "<dc:language>en-US</dc:language>\n" ++
- "<dc:rights>Copyright Eklektix, Inc.</dc:rights>\n" ++
- "<dc:title>" ++ (title obj) ++ "</dc:title>\n"
-
- epublish :: a -> FilePath -> IO ()
- epublish obj path = do
- let xhtml = to_xhtml obj
- epmd <- metadata obj
- epub <- xhtml_to_epub epmd xhtml
- let normalized_path = normalise path
- B.writeFile normalized_path epub
-
-xhtml_to_epub :: String -> String -> IO B.ByteString
-xhtml_to_epub epmd =
- write_epub . read_html
- where
- my_writer_options = defaultWriterOptions { writerEPUBMetadata = epmd }
- write_epub = writeEPUB Nothing [] my_writer_options
- read_html = readHtml defaultParserState