X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Rakka.git;a=blobdiff_plain;f=Rakka%2FWiki%2FInterpreter%2FImage.hs;fp=Rakka%2FWiki%2FInterpreter%2FImage.hs;h=886fdf512732228f1f746b7481d81bf0987b4c07;hp=00a55de056191ae9fb53b6713907bd2b75bc1b23;hb=42f51754dea02201aececaacbf194d714cd58aaf;hpb=98fd1cb53a837a9bda7145544c34872acb13a634
diff --git a/Rakka/Wiki/Interpreter/Image.hs b/Rakka/Wiki/Interpreter/Image.hs
index 00a55de..886fdf5 100644
--- a/Rakka/Wiki/Interpreter/Image.hs
+++ b/Rakka/Wiki/Interpreter/Image.hs
@@ -1,21 +1,28 @@
+{-# LANGUAGE
+ OverloadedStrings
+ , RecordWildCards
+ , UnicodeSyntax
+ , ViewPatterns
+ #-}
module Rakka.Wiki.Interpreter.Image
( interpreters
)
where
+import Data.Monoid.Unicode
+import Data.Text (Text)
+import qualified Data.Text as T
+import Network.URI
+import Prelude.Unicode
+import Rakka.Page
+import Rakka.SystemConfig
+import Rakka.Wiki.Interpreter
+import Rakka.Wiki
-import Network.URI
-import Rakka.Page
-import Rakka.SystemConfig
-import Rakka.Wiki.Interpreter
-import Rakka.Wiki
-
-
-interpreters :: [Interpreter]
+interpreters â· [Interpreter]
interpreters = [ imageInterp
, imgFrameInterp
]
-
--
--
--
-imageInterp :: Interpreter
+imageInterp â· Interpreter
imageInterp
= InlineCommandInterpreter {
- iciName = "img"
+ iciName = "img"
, iciInterpret
- = \ ctx (InlineCommand _ attrs _) ->
- do BaseURI baseURI <- getSysConf (ctxSysConf ctx)
-
+ = \(InterpreterContext {..}) (InlineCommand _ attrs _) â
+ do BaseURI baseURI â getSysConf ctxSysConf
let name = case lookup "src" attrs of
- Just x -> x
- Nothing -> error "\"src\" attribute is missing"
+ 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) "")
+ Just x
+ | T.null x â Nothing
+ | isURI' x â Just x
+ | otherwise â Just â T.pack $ uriToString id (mkPageURI baseURI x ) ""
+ Nothing â Just â T.pack $ uriToString id (mkPageURI baseURI name) ""
alt = lookup "alt" attrs
classAttr = case lookup "float" attrs of
- Nothing -> "inlineImage"
- Just "left" -> "inlineImage leftFloat"
- Just "right" -> "inlineImage rightFloat"
- Just others -> error ("unknown \"float\" attribute: " ++ others)
+ Nothing â "inlineImage"
+ Just "left" â "inlineImage leftFloat"
+ Just "right" â "inlineImage rightFloat"
+ Just others â error ("unknown \"float\" attribute: " â T.unpack others)
result = case link of
- Nothing -> Span [("class", classAttr)] [Image (Right name) alt]
- Just x -> Anchor [ ("class", classAttr)
- , ("href" , x ) ] [Image (Right name) alt]
+ Nothing â Span [("class", classAttr)] [Image (Right name) alt]
+ Just x â Anchor [ ("class", classAttr)
+ , ("href" , x ) ] [Image (Right name) alt]
return result
}
@@ -67,38 +72,39 @@ imageInterp
-- ...
--
--
-imgFrameInterp :: Interpreter
+imgFrameInterp â· Interpreter
imgFrameInterp
= BlockCommandInterpreter {
- bciName = "imgframe"
+ bciName = "imgframe"
, bciInterpret
- = \ ctx (BlockCommand _ attrs inside) ->
- do BaseURI baseURI <- getSysConf (ctxSysConf ctx)
-
+ = \(InterpreterContext {..}) (BlockCommand _ attrs inside) â
+ do BaseURI baseURI â getSysConf ctxSysConf
let name = case lookup "src" attrs of
- Just x -> x
- Nothing -> error "\"src\" attribute is missing"
+ 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) "")
+ Just x
+ | T.null x â Nothing
+ | isURI' x â Just x
+ | otherwise â Just â T.pack $ uriToString id (mkPageURI baseURI x ) ""
+ Nothing â Just â T.pack $ 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)
+ Nothing â ("class", "imageFrame")
+ Just "left" â ("class", "imageFrame leftFloat")
+ Just "right" â ("class", "imageFrame rightFloat")
+ Just others â error ("unknown \"float\" attribute: " â T.unpack others)
image = case link of
- Nothing -> Image (Right name) Nothing
- Just x -> Anchor [("href" , x)] [Image (Right name) Nothing]
+ Nothing â Image (Right name) Nothing
+ Just x â Anchor [("href" , x)] [Image (Right name) Nothing]
return (Div [classAttr]
[ Block (Div [("class", "imageData")]
[ Inline image ])
, Block (Div [("class", "imageCaption")]
- [ Block x | x <- inside ])
+ [ Block x | x â inside ])
]
)
}
+
+isURI' â· Text â Bool
+isURI' = isURI â T.unpack
\ No newline at end of file