module Rakka.Wiki.Interpreter.Image
( interpreters
)
where
import Control.Monad
import Data.Maybe
import Network.URI
import Rakka.Page
import Rakka.SystemConfig
import Rakka.Wiki.Interpreter
import Rakka.Wiki
interpreters :: [Interpreter]
interpreters = [ imageInterp
, imgFrameInterp
]
--
--
--
imageInterp :: Interpreter
imageInterp
= InlineCommandInterpreter {
iciName = "img"
, iciInterpret
= \ ctx (InlineCommand _ attrs inside) ->
do BaseURI baseURI <- getSysConf (ctxSysConf ctx) (BaseURI undefined)
let pageName = lookup "src" attrs
when (pageName == Nothing)
$ fail "\"src\" attribute is missing"
let hrefAttr = ("href", uriToString id (mkPageURI baseURI (fromJust pageName)) "")
srcAttr = ("src" , uriToString id (mkObjectURI baseURI (fromJust pageName)) "")
altAttr = do alt <- lookup "alt" attrs
return ("alt", alt)
classAttr = case lookup "float" attrs of
Nothing -> ("class", "inlineImage")
Just "left" -> ("class", "inlineImage leftFloat")
Just "right" -> ("class", "inlineImage rightFloat")
Just others -> error ("unknown \"float\" attribute: " ++ others)
anchorAttrs = [hrefAttr, classAttr]
imgAttrs = catMaybes [Just srcAttr, altAttr]
return (Anchor anchorAttrs [Image imgAttrs])
}
--
--
--
--
--