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 = case lookup "src" attrs of
34 Nothing -> error "\"src\" attribute is missing"
35 hrefAttr = ("href", uriToString id (mkPageURI baseURI pageName) "")
36 alt = lookup "alt" attrs
37 classAttr = case lookup "float" attrs of
38 Nothing -> ("class", "inlineImage")
39 Just "left" -> ("class", "inlineImage leftFloat")
40 Just "right" -> ("class", "inlineImage rightFloat")
41 Just others -> error ("unknown \"float\" attribute: " ++ others)
42 anchorAttrs = [hrefAttr, classAttr]
44 return (Anchor anchorAttrs [Image pageName alt])
48 -- <div class="imageFrame ...">
49 -- <div class="imageData">
56 -- <div class="imageCaption">
60 imgFrameInterp :: Interpreter
62 = BlockCommandInterpreter {
65 = \ ctx (BlockCommand _ attrs inside) ->
66 do BaseURI baseURI <- getSysConf (ctxSysConf ctx)
68 let pageName = case lookup "src" attrs of
70 Nothing -> error "\"src\" attribute is missing"
71 hrefAttr = ("href", uriToString id (mkPageURI baseURI pageName) "")
72 classAttr = case lookup "float" attrs of
73 Nothing -> ("class", "imageFrame")
74 Just "left" -> ("class", "imageFrame leftFloat")
75 Just "right" -> ("class", "imageFrame rightFloat")
76 Just others -> error ("unknown \"float\" attribute: " ++ others)
78 return (Div [classAttr]
79 [ Div [("class", "imageData")]
80 [ Paragraph [ Anchor [hrefAttr]
81 [ Image pageName Nothing ] ]
83 , Div [("class", "imageCaption")] inside