{-# LANGUAGE OverloadedStrings , RecordWildCards , UnicodeSyntax , ViewPatterns #-} module Rakka.Wiki.Interpreter.Image ( interpreters ) where import Data.Monoid.Unicode import Data.Text (Text) import qualified Data.Text as T import Network.URI import Prelude.Unicode 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 = \(InterpreterContext {..}) (InlineCommand _ attrs _) → do BaseURI baseURI ← getSysConf ctxSysConf let name = case lookup "src" attrs of Just x → x Nothing → error "\"src\" attribute is missing" link = case lookup "link" attrs of Just x | T.null x → Nothing | isURI' x → Just x | otherwise → Just ∘ T.pack $ uriToString id (mkPageURI baseURI x ) "" Nothing → Just ∘ T.pack $ 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: " ⊕ T.unpack 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 } --