X-Git-Url: https://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Rakka%2FWiki%2FInterpreter%2FImage.hs;h=886fdf512732228f1f746b7481d81bf0987b4c07;hb=42f51754dea02201aececaacbf194d714cd58aaf;hp=12ea6d662de735ee33a5b1203599b8dd6feb2c40;hpb=ddf0b4d7ab2f1e141edbc7ef75d39853c0846f8c;p=Rakka.git
diff --git a/Rakka/Wiki/Interpreter/Image.hs b/Rakka/Wiki/Interpreter/Image.hs
index 12ea6d6..886fdf5 100644
--- a/Rakka/Wiki/Interpreter/Image.hs
+++ b/Rakka/Wiki/Interpreter/Image.hs
@@ -1,86 +1,110 @@
+{-# 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 Control.Monad
-import Data.Maybe
-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 inside) ->
- do BaseURI baseURI <- getSysConf (ctxSysConf ctx)
-
- let pageName = case lookup "src" attrs of
- Just x -> x
- Nothing -> error "\"src\" attribute is missing"
- hrefAttr = ("href", uriToString id (mkPageURI baseURI pageName) "")
+ = \(InterpreterContext {..}) (InlineCommand _ attrs _) â
+ do BaseURI baseURI â getSysConf ctxSysConf
+ let name = case lookup "src" attrs of
+ Just x â x
+ Nothing â error "\"src\" attribute is missing"
+ link = case lookup "link" attrs of
+ 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 -> ("class", "inlineImage")
- Just "left" -> ("class", "inlineImage leftFloat")
- Just "right" -> ("class", "inlineImage rightFloat")
- Just others -> error ("unknown \"float\" attribute: " ++ others)
- anchorAttrs = [hrefAttr, classAttr]
-
- return (Anchor anchorAttrs [Image pageName alt])
+ 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]
+ return result
}
--