1 module Rakka.Wiki.Interpreter.Base.Image
11 import Rakka.SystemConfig
12 import Rakka.Wiki.Interpreter
16 -- <a href="..." class="inlineImage ...">
17 -- <img src="..." alt="..." />
19 imageInterp :: Interpreter
21 = InlineCommandInterpreter {
24 = \ (InlineCommand _ attrs inside) _ _ sysConf ->
25 do BaseURI baseURI <- getSysConf sysConf (BaseURI undefined)
27 let pageName = lookup "src" attrs
28 when (pageName == Nothing)
29 $ fail "\"src\" attribute is missing"
31 let hrefAttr = ("href", uriToString id (mkPageURI baseURI (fromJust pageName)) "")
32 srcAttr = ("src" , uriToString id (mkObjectURI baseURI (fromJust pageName)) "")
33 altAttr = do alt <- lookup "alt" attrs
35 classAttr = case lookup "float" attrs of
36 Nothing -> ("class", "inlineImage")
37 Just "left" -> ("class", "inlineImage leftFloat")
38 Just "right" -> ("class", "inlineImage rightFloat")
39 Just others -> error ("unknown \"float\" attribute: " ++ others)
40 anchorAttrs = [hrefAttr, classAttr]
41 imgAttrs = catMaybes [Just srcAttr, altAttr]
43 return (Anchor anchorAttrs [Image imgAttrs])
47 -- <div class="imageFrame ...">
48 -- <div class="imageData">
55 -- <div class="imageCaption">
59 imgFrameInterp :: Interpreter
61 = BlockCommandInterpreter {
64 = \ (BlockCommand _ attrs inside) _ _ sysConf ->
65 do BaseURI baseURI <- getSysConf sysConf (BaseURI undefined)
67 let pageName = lookup "src" attrs
68 when (pageName == Nothing)
69 $ fail "\"src\" attribute is missing"
71 let hrefAttr = ("href", uriToString id (mkPageURI baseURI (fromJust pageName)) "")
72 srcAttr = ("src" , uriToString id (mkObjectURI baseURI (fromJust pageName)) "")
73 classAttr = case lookup "float" attrs of
74 Nothing -> ("class", "imageFrame")
75 Just "left" -> ("class", "imageFrame leftFloat")
76 Just "right" -> ("class", "imageFrame rightFloat")
77 Just others -> error ("unknown \"float\" attribute: " ++ others)
79 return (Div [classAttr]
80 [ Div [("class", "imageData")]
81 [ Paragraph [ Anchor [hrefAttr]
84 , Div [("class", "imageCaption")] inside