]> gitweb @ CieloNegro.org - Rakka.git/blobdiff - Rakka/Wiki/Formatter.hs
Resurrection from slight bitrot.
[Rakka.git] / Rakka / Wiki / Formatter.hs
index 969c228a756ad93d269ff8d69d219466ece5bd99..5f7c7d8c10b952a1c7d7df404da7bc1667e2113c 100644 (file)
@@ -4,11 +4,11 @@ module Rakka.Wiki.Formatter
     where
 
 import           Control.Arrow
+import           Control.Arrow.ArrowIf
 import           Control.Arrow.ArrowList
-import           Data.Char
-import           Data.List
+import           Control.Arrow.ArrowTree
 import           Data.Maybe
-import           Network.URI
+import           Network.URI hiding (fragment)
 import           Rakka.Page
 import           Rakka.Wiki
 import           Text.XML.HXT.Arrow.XmlArrow
@@ -20,13 +20,13 @@ formatWikiBlocks
     = proc (baseURI, blocks)
     -> do block   <- arrL id     -< blocks
           tree    <- formatBlock -< (baseURI, block)
-          returnA -< tree
+          attachXHtmlNS -< tree
 
 
 formatElement :: (ArrowXml a, ArrowChoice a) => a (URI, Element) XmlTree
 formatElement 
-    = proc (baseURI, elem)
-    -> case elem of
+    = proc (baseURI, e)
+    -> case e of
          Block  b -> formatBlock  -< (baseURI, b)
          Inline i -> formatInline -< (baseURI, i)
 
@@ -58,6 +58,8 @@ formatBlock
 
          EmptyBlock
              -> none -< ()
+
+         _   -> arr (error . ("formatBlock: unsupported BlockElement: " ++) . show) -< block
     where
       formatElem :: (ArrowXml a, ArrowChoice a) =>
                     String
@@ -192,6 +194,8 @@ formatInline
 
          EmptyInline
              -> none -< ()
+
+         _   -> arr (error . ("formatInline: unsupported InlineElement: " ++) . show) -< i
     where
       formatElem :: (ArrowXml a, ArrowChoice a) =>
                     String
@@ -232,6 +236,7 @@ formatPageLink
                       (Just  x, Just  y) -> mkPageFragmentURI baseURI x y
                       (Just  x, Nothing) -> mkPageURI baseURI x
                       (Nothing, Just  y) -> mkFragmentURI y
+                      _                  -> undefined
            href   = uriToString id uri ""
            dLabel = fromMaybe "" page ++ fromMaybe "" (fmap ('#':) fragment)
            label  = fromMaybe dLabel text
@@ -241,7 +246,9 @@ formatPageLink
 
 formatImage :: (ArrowXml a) => a (URI, InlineElement) XmlTree
 formatImage = proc (baseURI, Image src alt)
-            -> let uri  = mkObjectURI baseURI src
+            -> let uri  = case src of
+                            Left  u    -> u
+                            Right name -> mkObjectURI baseURI name
                    href = uriToString id uri ""
                in
                  ( eelem "img"
@@ -266,3 +273,11 @@ mkAnchor :: (ArrowXml a) => a (String, String) XmlTree
 mkAnchor = eelem "a"
            += attr "href" (arr fst >>> mkText)
            += (arr snd >>> mkText)
+
+
+attachXHtmlNS :: (ArrowXml a) => a XmlTree XmlTree
+attachXHtmlNS = processTopDown (changeQName attach `when` isElem)
+    where
+      attach :: QName -> QName
+      attach = setNamePrefix'   (newXName "xhtml") .
+               setNamespaceUri' (newXName "http://www.w3.org/1999/xhtml")