X-Git-Url: https://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Rakka%2FWiki%2FInterpreter%2FImage.hs;h=80cd6c318730a794f2f5403f307e78449884ca6c;hb=d72f26d01168e88e6afa1d00bcda8a0f81e9a91d;hp=f01c2de4f5fac8f8e7976d3cb8531128e7b58b3c;hpb=605a843e408a7ef475fbb5a26f408271ab315cc8;p=Rakka.git diff --git a/Rakka/Wiki/Interpreter/Image.hs b/Rakka/Wiki/Interpreter/Image.hs index f01c2de..80cd6c3 100644 --- a/Rakka/Wiki/Interpreter/Image.hs +++ b/Rakka/Wiki/Interpreter/Image.hs @@ -18,6 +18,12 @@ interpreters = [ imageInterp ] +-- [Alternative] -- 空文字列の場合はリンク無し + -- -- ... -- @@ -26,36 +32,38 @@ imageInterp = InlineCommandInterpreter { iciName = "img" , iciInterpret - = \ ctx (InlineCommand _ attrs inside) -> + = \ ctx (InlineCommand _ attrs _) -> do BaseURI baseURI <- getSysConf (ctxSysConf ctx) - let pageName = lookup "src" attrs - when (pageName == Nothing) - $ fail "\"src\" attribute is missing" - - let hrefAttr = ("href", uriToString id (mkPageURI baseURI (fromJust pageName)) "") - srcAttr = ("src" , uriToString id (mkObjectURI baseURI (fromJust pageName)) "") - altAttr = do alt <- lookup "alt" attrs - return ("alt", alt) + let name = case lookup "src" attrs of + Just x -> x + Nothing -> error "\"src\" attribute is missing" + link = case lookup "link" attrs of + Just "" -> Nothing + Just x -> if isURI x then + Just x + else + Just (uriToString id (mkPageURI baseURI x) "") + Nothing -> Just (uriToString id (mkPageURI baseURI name) "") + alt = lookup "alt" attrs classAttr = case lookup "float" attrs of - Nothing -> ("class", "inlineImage") - Just "left" -> ("class", "inlineImage leftFloat") - Just "right" -> ("class", "inlineImage rightFloat") + Nothing -> "inlineImage" + Just "left" -> "inlineImage leftFloat" + Just "right" -> "inlineImage rightFloat" Just others -> error ("unknown \"float\" attribute: " ++ others) - anchorAttrs = [hrefAttr, classAttr] - imgAttrs = catMaybes [Just srcAttr, altAttr] - - return (Anchor anchorAttrs [Image imgAttrs]) + 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 } --
--
---

--- --- --- ---

+-- +-- +-- --
--
-- ... @@ -69,24 +77,30 @@ imgFrameInterp = \ ctx (BlockCommand _ attrs inside) -> do BaseURI baseURI <- getSysConf (ctxSysConf ctx) - let pageName = lookup "src" attrs - when (pageName == Nothing) - $ fail "\"src\" attribute is missing" - - let hrefAttr = ("href", uriToString id (mkPageURI baseURI (fromJust pageName)) "") - srcAttr = ("src" , uriToString id (mkObjectURI baseURI (fromJust pageName)) "") + let name = case lookup "src" attrs of + Just x -> x + Nothing -> error "\"src\" attribute is missing" + link = case lookup "link" attrs of + Just "" -> Nothing + Just x -> if isURI x then + Just x + else + Just (uriToString id (mkPageURI baseURI x) "") + Nothing -> Just (uriToString id (mkPageURI baseURI name) "") classAttr = case lookup "float" attrs of Nothing -> ("class", "imageFrame") Just "left" -> ("class", "imageFrame leftFloat") Just "right" -> ("class", "imageFrame rightFloat") Just others -> error ("unknown \"float\" attribute: " ++ others) + image = case link of + Nothing -> Image (Right name) Nothing + Just x -> Anchor [("href" , x)] [Image (Right name) Nothing] return (Div [classAttr] - [ Div [("class", "imageData")] - [ Paragraph [ Anchor [hrefAttr] - [ Image [srcAttr] ] ] - ] - , Div [("class", "imageCaption")] inside + [ Block (Div [("class", "imageData")] + [ Inline image ]) + , Block (Div [("class", "imageCaption")] + [ Block x | x <- inside ]) ] ) }