1 module Rakka.Wiki.Interpreter.Image
10 import Rakka.SystemConfig
11 import Rakka.Wiki.Interpreter
15 interpreters :: [Interpreter]
16 interpreters = [ imageInterp
21 -- <a href="..." class="inlineImage ...">
22 -- <img src="..." alt="..." />
24 imageInterp :: Interpreter
26 = InlineCommandInterpreter {
29 = \ ctx (InlineCommand _ attrs inside) ->
30 do BaseURI baseURI <- getSysConf (ctxSysConf ctx)
32 let pageName = lookup "src" attrs
33 when (pageName == Nothing)
34 $ fail "\"src\" attribute is missing"
36 let hrefAttr = ("href", uriToString id (mkPageURI baseURI (fromJust pageName)) "")
37 srcAttr = ("src" , uriToString id (mkObjectURI baseURI (fromJust pageName)) "")
38 altAttr = do alt <- lookup "alt" attrs
40 classAttr = case lookup "float" attrs of
41 Nothing -> ("class", "inlineImage")
42 Just "left" -> ("class", "inlineImage leftFloat")
43 Just "right" -> ("class", "inlineImage rightFloat")
44 Just others -> error ("unknown \"float\" attribute: " ++ others)
45 anchorAttrs = [hrefAttr, classAttr]
46 imgAttrs = catMaybes [Just srcAttr, altAttr]
48 return (Anchor anchorAttrs [Image imgAttrs])
52 -- <div class="imageFrame ...">
53 -- <div class="imageData">
60 -- <div class="imageCaption">
64 imgFrameInterp :: Interpreter
66 = BlockCommandInterpreter {
69 = \ ctx (BlockCommand _ attrs inside) ->
70 do BaseURI baseURI <- getSysConf (ctxSysConf ctx)
72 let pageName = lookup "src" attrs
73 when (pageName == Nothing)
74 $ fail "\"src\" attribute is missing"
76 let hrefAttr = ("href", uriToString id (mkPageURI baseURI (fromJust pageName)) "")
77 srcAttr = ("src" , uriToString id (mkObjectURI baseURI (fromJust pageName)) "")
78 classAttr = case lookup "float" attrs of
79 Nothing -> ("class", "imageFrame")
80 Just "left" -> ("class", "imageFrame leftFloat")
81 Just "right" -> ("class", "imageFrame rightFloat")
82 Just others -> error ("unknown \"float\" attribute: " ++ others)
84 return (Div [classAttr]
85 [ Div [("class", "imageData")]
86 [ Paragraph [ Anchor [hrefAttr]
89 , Div [("class", "imageCaption")] inside