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 _) ->
30 do BaseURI baseURI <- getSysConf (ctxSysConf ctx)
32 let name = case lookup "src" attrs of
34 Nothing -> error "\"src\" attribute is missing"
35 hrefAttr = ("href", uriToString id (mkPageURI baseURI name) "")
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 (Right name) alt])
48 -- <div class="imageFrame ...">
49 -- <div class="imageData">
54 -- <div class="imageCaption">
58 imgFrameInterp :: Interpreter
60 = BlockCommandInterpreter {
63 = \ ctx (BlockCommand _ attrs inside) ->
64 do BaseURI baseURI <- getSysConf (ctxSysConf ctx)
66 let name = case lookup "src" attrs of
68 Nothing -> error "\"src\" attribute is missing"
69 hrefAttr = ("href", uriToString id (mkPageURI baseURI name) "")
70 classAttr = case lookup "float" attrs of
71 Nothing -> ("class", "imageFrame")
72 Just "left" -> ("class", "imageFrame leftFloat")
73 Just "right" -> ("class", "imageFrame rightFloat")
74 Just others -> error ("unknown \"float\" attribute: " ++ others)
76 return (Div [classAttr]
77 [ Block (Div [("class", "imageData")]
78 [ Inline (Anchor [hrefAttr]
79 [ Image (Right name) Nothing ]) ])
80 , Block (Div [("class", "imageCaption")]
81 [ Block x | x <- inside ])