module Rakka.Wiki.Interpreter.Image ( interpreters ) where import Network.URI import Rakka.Page import Rakka.SystemConfig import Rakka.Wiki.Interpreter import Rakka.Wiki interpreters :: [Interpreter] interpreters = [ imageInterp , imgFrameInterp ] -- [Alternative] -- 空文字列の場合はリンク無し -- -- ... -- 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" link = case lookup "link" attrs of Just "" -> Nothing Just x -> if isURI x then Just x else Just (uriToString id (mkPageURI baseURI x) "") Nothing -> Just (uriToString id (mkPageURI baseURI name) "") alt = lookup "alt" attrs classAttr = case lookup "float" attrs of Nothing -> "inlineImage" Just "left" -> "inlineImage leftFloat" Just "right" -> "inlineImage rightFloat" Just others -> error ("unknown \"float\" attribute: " ++ others) result = case link of Nothing -> Span [("class", classAttr)] [Image (Right name) alt] Just x -> Anchor [ ("class", classAttr) , ("href" , x ) ] [Image (Right name) alt] return result } --
--
-- -- -- --
--
-- ... --
--
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" link = case lookup "link" attrs of Just "" -> Nothing Just x -> if isURI x then Just x else Just (uriToString id (mkPageURI baseURI x) "") Nothing -> Just (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) image = case link of Nothing -> Image (Right name) Nothing Just x -> Anchor [("href" , x)] [Image (Right name) Nothing] return (Div [classAttr] [ Block (Div [("class", "imageData")] [ Inline image ]) , Block (Div [("class", "imageCaption")] [ Block x | x <- inside ]) ] ) }