X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Rakka%2FWiki%2FFormatter.hs;h=90687f4e8479a1c11593e770b6cf899fd67f71ee;hb=706ee842873fdceb9465cdf6a583176ab855fae2;hp=4b483db37dba260310b2263ea644db9085684b3c;hpb=65c7f9f0643c7e8884e4a02567b77c169167c093;p=Rakka.git diff --git a/Rakka/Wiki/Formatter.hs b/Rakka/Wiki/Formatter.hs index 4b483db..90687f4 100644 --- a/Rakka/Wiki/Formatter.hs +++ b/Rakka/Wiki/Formatter.hs @@ -4,11 +4,13 @@ module Rakka.Wiki.Formatter where import Control.Arrow +import Control.Arrow.ArrowIf import Control.Arrow.ArrowList +import Control.Arrow.ArrowTree import Data.Char import Data.List 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 +22,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 +60,8 @@ formatBlock EmptyBlock -> none -< () + + _ -> arr (error . ("formatBlock: unsupported BlockElement: " ++) . show) -< block where formatElem :: (ArrowXml a, ArrowChoice a) => String @@ -192,6 +196,8 @@ formatInline EmptyInline -> none -< () + + _ -> arr (error . ("formatInline: unsupported InlineElement: " ++) . show) -< i where formatElem :: (ArrowXml a, ArrowChoice a) => String @@ -232,6 +238,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 @@ -242,7 +249,7 @@ formatPageLink formatImage :: (ArrowXml a) => a (URI, InlineElement) XmlTree formatImage = proc (baseURI, Image src alt) -> let uri = case src of - Left uri -> uri + Left u -> u Right name -> mkObjectURI baseURI name href = uriToString id uri "" in @@ -268,3 +275,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")