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 _) -> do BaseURI baseURI <- getSysConf (ctxSysConf ctx) let name = case lookup "src" attrs of Just x -> x Nothing -> error "\"src\" attribute is missing" hrefAttr = ("href", uriToString id (mkPageURI baseURI name) "") alt = lookup "alt" attrs 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] return (Anchor anchorAttrs [Image (Right name) alt]) } --
--
-- -- -- --
--
-- ... --
--
imgFrameInterp :: Interpreter imgFrameInterp = BlockCommandInterpreter { bciName = "imgframe" , bciInterpret = \ ctx (BlockCommand _ attrs inside) -> do BaseURI baseURI <- getSysConf (ctxSysConf ctx) let name = case lookup "src" attrs of Just x -> x Nothing -> error "\"src\" attribute is missing" hrefAttr = ("href", uriToString id (mkPageURI baseURI name) "") classAttr = case lookup "float" attrs of Nothing -> ("class", "imageFrame") Just "left" -> ("class", "imageFrame leftFloat") Just "right" -> ("class", "imageFrame rightFloat") Just others -> error ("unknown \"float\" attribute: " ++ others) return (Div [classAttr] [ Block (Div [("class", "imageData")] [ Inline (Anchor [hrefAttr] [ Image (Right name) Nothing ]) ]) , Block (Div [("class", "imageCaption")] [ Block x | x <- inside ]) ] ) }